<< Chapter < Page | Chapter >> Page > |
Figure 17 Rotation around the y-axis only.
I will let you interpret what you see there.
Rotation around all three axes with the anchor point at the origin
When more than one rotation angle has a non-zero value, the rotational effects are cumulative. The object is first rotated around the anchor point in adirection consistent with rotation around the z-axis (rotation in the x-y plane) . Then that rotated object is rotated in a direction consistent with rotation around the x-axis (rotation in the y-z plane) . Finally, the previously rotated object is rotated in a direction consistent with rotationaround the y-axis (rotation in the x-z plane) . It is important to note, however, that the actual rotation is around the anchor point and not around theorigin unless the anchor point is at the origin.
Figure 18 shows the result of applying all three of the rotations described above with the anchor point at the origin.
Figure 18 Rotation around all three axes with the anchor point at the origin.
Once again, I will let you interpret what you see there.
Perform all three rotations with the anchor point away from the origin
Figure 19 performs the same three rotations as were performed in Figure 18 . However, in Figure 19 , the anchor point was at a location defined by the coordinate values (50,50,50).
Figure 19 Perform all three rotations with the anchor point away from the origin.
At the risk of being boring, I will state once again that I will let you interpret what you see there.
Will animate the process later
For me, at least, it isn't easy to visualize the process of rotating around an arbitrary anchor point in 3D. In a future module, I will animate the rotationprocess and run it in slow motion so that you can see the progress of each individual rotation from the beginning until the point where all three rotationsare complete. Hopefully, that will make it easier to visualize rotation around an arbitrary anchor point in 3D. As a bonus, it will also give you someexperience in using the game-math library for a non-trivial animation project.
Let's see some code
As was the case with the previous program, given what you have already learned, the only interesting new code in this program is in the drawOffScreen method. Furthermore, only a small portion of the code in that method is new and interesting. Listing 25 contains some code that was extracted from the drawOffScreen method.
A complete listing of the program named StringArt03 is provided in Listing 32 .
Listing 25 . Interesting code from the drawOffScreen method. |
---|
for(int cnt = 0;cnt<numberPoints;cnt++){
points[cnt]= new GM01.Point3D(
new GM01.ColMatrix3D(50*Math.cos((cnt*360/numberPoints)*Math.PI/180),
50*Math.sin((cnt*360/numberPoints)*Math.PI/180),0.0));
//Populate a ColMatrix3D object with rotation valuesGM01.ColMatrix3D angles = new GM01.ColMatrix3D(
zRotation,xRotation,yRotation);//Populate a Point3D object with anchor point// coordinates.
GM01.Point3D anchorPoint = new GM01.Point3D(new GM01.ColMatrix3D(
xAnchorPoint,yAnchorPoint,zAnchorPoint));//Draw the anchorPoint in BLACK.
g2D.setColor(Color.BLACK);anchorPoint.draw(g2D);//The following statement causes the rotation to be
//performed.points[cnt] =points[cnt].rotate(anchorPoint,angles);}//end for loop |
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?