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

Questions & Answers

what are components of cells
ofosola Reply
twugzfisfjxxkvdsifgfuy7 it
Sami
58214993
Sami
what is a salt
John
the difference between male and female reproduction
John
what is computed
IBRAHIM Reply
what is biology
IBRAHIM
what is the full meaning of biology
IBRAHIM
what is biology
Jeneba
what is cell
Kuot
425844168
Sami
what is biology
Inenevwo
what is cytoplasm
Emmanuel Reply
structure of an animal cell
Arrey Reply
what happens when the eustachian tube is blocked
Puseletso Reply
what's atoms
Achol Reply
discuss how the following factors such as predation risk, competition and habitat structure influence animal's foraging behavior in essay form
Burnet Reply
cell?
Kuot
location of cervical vertebra
KENNEDY Reply
What are acid
Sheriff Reply
define biology infour way
Happiness Reply
What are types of cell
Nansoh Reply
how can I get this book
Gatyin Reply
what is lump
Chineye Reply
what is cell
Maluak Reply
what is biology
Maluak
what is vertibrate
Jeneba
what's cornea?
Majak Reply
what are cell
Achol
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

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