<< Chapter < Page Chapter >> Page >

Nothing new here

There is nothing in Listing 6 that is new relative to what you learned in the previous module. Listing 6 starts by defining four GM2D02.Point objects that will be used to define the ends of the line segments. References to these Point objects are passed to the constructor for the GM2D02.Line class to instantiate the four Line objects.

Note that the locations of the points, and hence the positions of the lines were one pixel away from the edges of the canvas towards the center of thecanvas. These locations were chosen to ensure that the resulting visual manifestations of the lines would be visible on the canvas.

It is also extremely important to understand that the GM2D02.Point and GM2D02.Line objects instantiated in Listing 6 are not graphical objects. Rather, they are underlying data objects, which are suitable for use inmathematical operations.

Draw a visual manifestation of each line

Listing 7 calls the draw method of the GM2D02.Line class four times in succession for each off-screen image. Note that a reference tothe off-screen image is passed as a parameter to the draw method each time the method is called on one of the GM2D02.Line objects.

Listing 7 . Draw a visual manifestation of each line.
//Now draw a visual manifestation of each line // on g2Da.top.draw(g2Da); rightSide.draw(g2Da);bottom.draw(g2Da); leftSide.draw(g2Da);//Now draw a visual manifestation of each of the same// four lines on g2Db top.draw(g2Db);rightSide.draw(g2Db); bottom.draw(g2Db);leftSide.draw(g2Db);

As you will see shortly, each of these calls to the draw method causes an object of the standard Java Line2D.Double class to be rendered onto the specified off-screen image. When the off-screen image is ultimatelycopied to the canvas object by the overridden paint method, this produces a visual manifestation of the GM2D02.Line object.

Once again, however, it is very important to understand that the Line2D.Double object is a graphical object and the GM2D02.Line is an underlying data object. They are completely independent objects.

Also, it is important to understand that the Line2D.Double class is a member of the standard Java library,whereas the GM2D02.Line class is a member of my special game math library named GM2D02 .

The draw method of the GM2D02.Line class

Now it's time to explain one of the methods that was added to the original game-math library named GM2D01 to produce the new library named GM2D02 . At this point, I will start switching back and forth between code in the GM2D02 library and code in the program named PointLine03 .

Listing 8 shows the draw method that was called repeatedly on the GM2D02.Line objects in Listing 7 . This code belongs to the GM2D02 library.

Listing 8 . The draw method of the GM2D02.Line class.
public void draw(Graphics2D g2D){ Line2D.Double line = new Line2D.Double(getTail().getData(0), getTail().getData(1),getHead().getData(0), getHead().getData(1));g2D.draw(line); }//end draw

Construct and render a Line2D.Double object on the graphics context

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
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