<< 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 defense mechanism
Chinaza Reply
what is defense mechanisms
Chinaza
I'm interested in biological psychology and cognitive psychology
Tanya Reply
what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
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