<< Chapter < Page Chapter >> Page >

At this point, you should not find any code in Listing 12 that you don't understand. I have explained the code in Listing 12 earlier in this module or in an earlier module, so I won't repeat that explanation here.

End of discussion .

That concludes the discussion of the program named GM01test05 . You will find a complete listing of this program in Listing 29 .

The program named GM01test06

Scaling, translation, and rotation of a point

Three of the most common and important operations that you will encounter in game programming will be to scale, translate, and/or rotate a geometric object.

Since all geometric objects are composed of points that define the vertices, possibly embellished with lines, shading, lighting, etc., if you know how toscale, translate, and/or rotate a point, you also know how to scale, translate, and/or rotate the entire geometric object. You simply apply the requiredoperation to all of the points that comprise the object and you will have applied the operation to the object as a whole.

However, there are some complex issues associated with hiding the back faces of a rotated object, which will be addressed in a future module under thegeneral topic of backface culling . Backface culling is a process by which you prevent 3D objects from appearing to be transparent.

Homogeneous Coordinates:

In a future module, we will learn about a mathematical trick commonly known as homogeneous coordinates that can simplify the scaling, translation, and rotation of a point. However, that will have to wait until we have a better grasp of matrix arithmetic.

In a previous module, you learned how to translate a geometric object. In this program, you willlearn how to scale a geometric object. In the next two programs, you will learn how to rotate geometric objects.

The new scaling methods

The additions to the game-math library included the following two methods:

  • GM01.Point2D.scale
  • GM01.Point3D.scale

As the names imply, these two methods can be used to scale a point in either 2D or 3D.

The game-math library method named GM01.Point3D.scale

This method is shown in Listing 13 .

Listing 13 . The game-math library method named GM01.Point3D.scale.
public GM01.Point3D scale(GM01.ColMatrix3D scale){ return new GM01.Point3D(new ColMatrix3D(getData(0) * scale.getData(0), getData(1) * scale.getData(1),getData(2) * scale.getData(2))); }//end scale

This method multiplies each coordinate value of the Point3D object on which the method is called by the corresponding values in an incoming ColMatrix3D object to produce and return a new Point3D object. This makes it possible to scale each coordinate value that defines thelocation in space by a different scale factor.

If a scale factor for a particular coordinate is less than 1.0 but greater than 0.0, the location of the new point will be closer to the origin along thataxis than was the location of the original point. If a scale factor is greater than 1.0, the new point will be further from the origin along that axis.If the scale factor is negative, the location of the new point will be on the other side of the origin along the same axis.

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