<< 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.

Missing image.

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.

  1. Each GM01Point3D object that defines a corner of the box was scaled by a ColMatrix3D object containing the values 0.25, 0.5, and 0.75. Thus, the overall size of the box was reduced in comparison with thebox in shown Figure 1 .
  2. Each of the red, green, and blue points on the axes was scaled by 0.25, 0.5, or 0.75 respectively to cause the locations of those points to continueto be where the axes intersect the surface of the box.
  3. The magenta vector shown in Figure 1 was removed from the program because it didn't contribute to the objective of illustrating the scaling ofa geometric object.

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 .

The program named StringArt02

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.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask