Graphics Reference
In-Depth Information
- (
CALayer
*)cubeWithTransform:(
CATransform3D
)transform
{
//create cube layer
CATransformLayer
*cube = [
CATransformLayer
layer
];
//add cube face 1
CATransform3D
ct =
CATransform3DMakeTranslation
(
0
,
0
,
50
);
[cube
addSublayer
:[
self
faceWithTransform
:ct]];
//add cube face 2
ct =
CATransform3DMakeTranslation
(
50
,
0
,
0
);
ct =
CATransform3DRotate
(ct,
M_PI_2
,
0
,
1
,
0
);
[cube
addSublayer
:[
self
faceWithTransform
:ct]];
//add cube face 3
ct =
CATransform3DMakeTranslation
(
0
, -
50
,
0
);
ct =
CATransform3DRotate
(ct,
M_PI_2
,
1
,
0
,
0
);
[cube
addSublayer
:[
self
faceWithTransform
:ct]];
//add cube face 4
ct =
CATransform3DMakeTranslation
(
0
,
50
,
0
);
ct =
CATransform3DRotate
(ct, -
M_PI_2
,
1
,
0
,
0
);
[cube
addSublayer
:[
self
faceWithTransform
:ct]];
//add cube face 5
ct =
CATransform3DMakeTranslation
(-
50
,
0
,
0
);
ct =
CATransform3DRotate
(ct, -
M_PI_2
,
0
,
1
,
0
);
[cube
addSublayer
:[
self
faceWithTransform
:ct]];
//add cube face 6
ct =
CATransform3DMakeTranslation
(
0
,
0
, -
50
);
ct =
CATransform3DRotate
(ct,
M_PI
,
0
,
1
,
0
);
[cube
addSublayer
:[
self
faceWithTransform
:ct]];
//center the cube layer within the container
CGSize
containerSize =
self
.containerView.
bounds
.
size
;
cube.
position
=
CGPointMake
(containerSize.
width
/
2.0
,
containerSize.
height
/
2.0
);
//apply the transform and return
cube.
transform
= transform;
return
cube;
}
- (
void
)viewDidLoad
{