<< Chapter < Page Chapter >> Page >

A complete listing of the program named PointLine02 is provided in Listing 15 near the end of the module and a complete listing of the game-math library named GM2D01 is provided in Listing 16 .

Screen output from the program named PointLine02

Figure 5 shows the screen output produced by running this program. I will refer back to the material in Figure 5 in subsequent paragraphs.

Figure 5 . Screen output from the program named PointLine02.
Instantiate and display the contents of a new ColMatrix object2.5,6.8 2.56.8 Bad indexInstantiate and display the contents of a new Point object3.4,9.7 3.49.7 Bad indexInstantiate and display the contents of a new Vector object-1.9,7.5 -1.97.5 Bad indexInstantiate and display the contents of a new Line objectTail = 1.1,2.2 Head = 3.3,4.41.1,2.2 3.3,4.4Press any key to continue...

The game-math library named GM2D01

As mentioned earlier, the name GM2D01 is an abbreviation for GameMath2D01. (I elected to use the abbreviated name to keep the code from being so long.) This is a game-math class, which will be expanded over time as I publish sample programs and additional modules in this collection.

For educational purposes only

The game-math class is provided solely for educational purposes. Although some things were done to optimize the code and make it more efficient, the class wasmainly designed and implemented for maximum clarity. Hopefully the use of this library will help youto better understand the programming details of various mathematical operations commonly used in graphics, game, andsimulation programming.

Each time the library is expanded or modified, it will be given a new name by incrementing the two digits at the end of the class name to make one versiondistinguishable from the next. No attempt will be made to maintain backward compatibility from one version of the library to the next.

Static top-level methods

The GM2D01 class contains several static top-level classes (See Java 2D Graphics, Nested Top-Level Classes and Interfaces if you are unfamiliar with static top-level classes.) . This organizational approach was chosen primarily for the purpose of gathering the individual classes together under a common naming umbrellawhile avoiding name conflicts within a single package.

For example, as time passes and this library is expanded, my default package may contain class fileswith the following names, each representing a compiled version of the Point class in a different version of the overall library.

  • GM2D01$Point.class
  • GM2D02$Point.class
  • GM2D03$Point.class

Real numbers represented as type double

All real-number values used in the library are maintained as type double because double is the default representation for literal real numbers in Java.

Will explain in fragments

I will explain the code in Listing 15 and Listing 16 in fragments, switching back and forth between the code from the program named PointLine02 and the library class named GM2D01 to show how they work together.

Beginning of the class named PointLine02

Listing 8 shows the beginning of the class named PointLine02 including the beginning of the main method.

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