Graphics Reference
In-Depth Information
//add cube face 5
transform =
CATransform3DMakeTranslation
(-
100
,
0
,
0
);
transform =
CATransform3DRotate
(transform, -
M_PI_2
,
0
,
1
,
0
);
[
self
addFace
:
4
withTransform
:transform];
//add cube face 6
transform =
CATransform3DMakeTranslation
(
0
,
0
, -
100
);
transform =
CATransform3DRotate
(transform,
M_PI
,
0
,
1
,
0
);
[
self
addFace
:
5
withTransform
:transform];
}
@end
Figure 5.20
The cube, displayed face-on
Our cube isn't really that impressive from this angle; it just looks like a square. To
appreciate it properly, we need to look at it from a
different point of view.
Rotating the cube itself would be cumbersome because we'd have to rotate each face
individually. A simpler option is to rotate the
camera
, which we can do by adjusting the
sublayerTransform
of our container view.
Add the following lines to rotate the
perspective
transform matrix before applying it to
the
containerView
layer:
perspective =
CATransform3DRotate
(perspective, -
M_PI_4
,
1
,
0
,
0
);
perspective =
CATransform3DRotate
(perspective, -
M_PI_4
,
0
,
1
,
0
);