<< Chapter < Page Chapter >> Page >

You should make certain that you understand this syntax.

No overloaded operators:

It is at times like this when I wish that Java supported overloaded operators in a manner similar to C++. Overloading the + operator would make the syntax much more intuitive than that shown by the code in Listing 11 .

Back to the drawing

Now turn your attention back to the drawing in Figure 1 . The red, green, and blue vectors are drawn in a head-to-tail manner as described earlier. The sumOf3 (black) vector is drawn with its tail coinciding with the tail of the first (red) vector. Note that the head of the black vector coincides with the head of the last (blue) vector in the sum. Although not a definitive proof, this is at least a strong indication that thehead-to-tail rule works for adding any number of vectors.

An overridden paint method

The MyCanvas class also includes an overridden paint method. However, the code in that method is very similar to code that I explained in theearlier module titled GAME 2302-0110: Updating the Math Library for Graphics . Therefore, I won't explain that code again in this module. You can view theoverridden paint method in Listing 20 .

That concludes the discussion of the program named VectorAdd01 .

The program named CoordinateFrame01

A complete listing of this program is provided in Listing 21 near the end of the module. This program illustrates the relationship between the coordinateframe and a geometric object described in that coordinate frame.

A GUI allows the user to move the origin of the coordinate frame. Proper mathematical corrections are made such that a geometric object described in thatcoordinate frame maintains its position relative to world coordinates even when the coordinate frame is changed. This causes its position relative to thecoordinate frame to change.

Screen output at startup

Figure 2 shows the screen output of the program at startup.

Figure 2 Screen output from CoordinateFrame01 at startup.

Missing image.

The axes are difficult to see

At this point, the origin is at the upper-left corner of the canvas. Although orthogonal axes are drawn intersecting at the origin, they are at the very edgeof the canvas and are only barely visible. I will later refer to this coordinate frame with the origin in the upper-left corner as world coordinates .

A point has been defined (but not drawn) at a location specified by X equal to 196 and Y equal to 165. Even though the point is not drawn, a redvector has been drawn with its tail located at that point. A green vector has been drawn with its tail at the head of the red vector. A blue vector has beencomputed as the sum of the red and green vectors and it has been drawn with its tail at the tail of the red vector. As you learned in the previous program, thisresults in a closed polygon that is drawn at the point defined above.

Modify the coordinate frame

Figure 3 shows the result of modifying the coordinate frame and then causing everything to be re-drawn. The coordinate frame is modified by entering valuesinto the two user input fields and clicking the Replot button at the bottom of the GUI.

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