Java Reference
In-Depth Information
M3G is actually rotating a 3-dimensional triangle around the z-axis. The z-axis in M3G
points out towards you from the screen. In Figure 15-4, the vertices of the triangle actually
point three dimensionally and have x, y, and z coordinates. However, all of their z coordinates
have zero value. The 2D rotation that is observed is actually a 3D rotation in disguise.
If this is indeed the case, all that is required is to tell M3G to rotate the triangle around
some axis other than the z-axis, and you should immediately see some 3D activity.
You can convince yourself of this by looking for the following line in the TriangleCanvas
source code:
mTransform.postRotate(mAngle, 0, 0, 1.0f );
The last three numbers in this method invocation specify the vector around which the
triangle will rotate—in this case (0, 0, 1) , or a vector parallel to the z-axis. Now, change the
vector to (1,0,0) —a vector parallel to the x-axis:
mTransform.postRotate(mAngle, 1.0f, 0, 0 );
Build the MIDlet and run it again, and watch M3G rotate the triangle now in visible 3D,
around the x-axis! Figure 15-5 shows the MIDlet in the midst of this 3D rotation.
Figure 15-5. TriangleMIDlet rotating the triangle around the x-axis
The Effect of Culling
While the triangle shown in Figure 15-5 rotates around the x-axis, you will see the triangle
disappear as it rotates away from you. After a while, it will start to rotate towards you again as
it completes its clockwise rotation around the x-axis. The triangle seems to disappear for a
moment because the back of the triangle is not rendered by M3G. This is due to an optimization
technique known as culling . Culling avoids rendering surfaces that are never shown, and there-
fore saves on the computation required during rendering. Typically, the backside of triangles and
polygons you define do not need to be rendered. Later, you will see how to disable culling, to
make the triangle visible throughout its rotation.
 
Search WWH ::




Custom Search