<< Chapter < Page Chapter >> Page >

The name of the library

The name GM01 is an abbreviation for GameMath01 . See the file named GM2D01 from an earlier module for a general description of the game-math library. The library has been updated severaltimes. This version updates the file named GM2D04 .

Improving efficiency

In addition to the updates mentioned above, this update cleaned up some lingering areas of code inefficiency by using the simplest available method todraw on an off-screen image.

New static methods

Also, the following new static methods were added to the class named GM01 . The first method in the following list deals with the problem of displaying a 3Dimage on a 2D screen. The last five methods in the list wrap around the standard graphics methods for the purpose of eliminating the issue of thedirection of the positive Y-axis.

  • GM01.convert3Dto2D
  • GM01.translate
  • GM01.drawLine
  • GM01.fillOval
  • GM01.drawOval
  • GM01.fillRect

It will probably be necessary for me to add more wrapper methods to the library in future modules. With the exception of the first method in theabove list, the coding of these methods was straightforward and explanations of that code are not warranted. Note, however, that it is the wrapper methods that resolve the issue regarding the direction of the positivey-axis. You will see comments in this regard if you examine the source code for the wrapper methods in Listing 27 . I will explain the code for the method named GM01.convert3Dto2D shortly.

Other new methods

In addition to the new static methods listed above, a number of new methods were added to the existing static top-level 2D classes and also included in thenew static top-level 3D classes. A list of those new methods follows:

  • GM01.Vector2D.scale
  • GM01.Vector2D.negate
  • GM01.Point2D.clone
  • GM01.Vector2D.normalize
  • GM01.Point2D.rotate
  • GM01.Point2D.scale
  • GM01.Vector3D.scale
  • GM01.Vector3D.negate
  • GM01.Point3D.clone
  • GM01.Vector3D.normalize
  • GM01.Point3D.rotate
  • GM01.Point3D.scale

With the exception of the two rotate methods, the coding of the methods in the above list was also straightforward and an explanation of thatcode is not warranted. You can view all of the new code in Listing 26 .

The two rotate methods are not straightforward at all. They are quite complicated (particularly the 3D method) and require quite a lot of background information to understand. I will dedicate a large portion of afuture module to the task of rotating geometric objects in 2D and 3D worlds and will defer an explanation of the two rotate methods until that module.

The static method named GM01convert3Dto2D

Note first that this is a static method of the class named GM01 . Among other things, this means that the method can be called simply by joiningthe name of the method to the name of the class. In other words, an object of the class named GM01 is not necessary to make the method accessible.

A complete listing of the method is provided in Listing 1 .

Listing 1 . The static method named convert3Dto2D.
public static GM01.ColMatrix2D convert3Dto2D( GM01.ColMatrix3D data){return new GM01.ColMatrix2D( data.getData(0) - 0.866*data.getData(2),data.getData(1) - 0.50*data.getData(2)); }//end convert3Dto2D

As you can see, the method is quite short, and once you know how it is required to behave , coding the method is not difficult. The complexity comes in understanding the required behavior.

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