<< Chapter < Page | Chapter >> Page > |
Graphic output from the program named GM01test06
The graphic output from the program named GM01test06 is shown in Figure 5 . Compare this with the graphic output from the program named GM01test01 shown in Figure 1 .
Figure 5 Graphic output from the program named GM01test06.
Modifications to the original program
The program named GM01test06 , shown in Listing 30 , modifies the earlier program named GM01test01 in three different ways to demonstrate the effects of scaling points in 3D.
These modifications are so straightforward that no explanation of the actual code is justified. You can view the modifications in Listing 30 .
End of discussion .
That concludes the discussion of the program named GM01test06 . You will find a complete listing of this program in Listing 30 .
Things are about to get a lot more interesting. This program and the one following it both deal with the rotation of geometric objects, which is a relatively complex topic.
In this program, I will teach you how to use the new GM01.Point2D.rotate method to rotate objects in 2D space. In the next program, I will teachyou how to use the new GM01.Point3D.rotate method to rotate objects in 3D space.
Rotation is 3D space is much more complicated than rotation in 2D space, so I will begin my explanation of this topic with the simpler of the two programs.
Equations for rotating an object in 2D space
Once again, we have some equations to deal with, and once we understand the equations, the required code is tedious, but not terribly difficult to write.The new game-math library method named GM01.Point2D.rotate , which begins in Listing 14 , implements the required equations for rotating an object in 2D space.
Listing 14 . Beginning of the game-math library method named GM01.Point2D.rotate. |
---|
public GM01.Point2D rotate(GM01.Point2D anchorPoint,
double angle){GM01.Point2D newPoint = this.clone();double tempX ;
double tempY; |
The purpose of the GM01.Point2D.rotate method is to rotate a point around a specified anchor point in the x-y plane. The location of the anchor point is passed in as a reference to an object of the class GM01.Point2D . The rotation angle is passed in as a double value in degrees with the positive angle of rotation beingcounter-clockwise.
Does not modify the original Point 2D object
This method does not modify the contents of the original Point2D object on which the method is called. Rather, it uses the contents of thatobject to instantiate, rotate, and return a new Point2D object, leaving the original object intact.
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?