<< Chapter < Page Chapter >> Page >

Draw the two lines on the screen

Finally, Listing 7 calls the draw method of the Graphics2D class twice in succession to draw the two lines on the screen as shown in Figure 1 .

Listing 7 . Draw the two lines on the screen.
g2.draw(horizLine); g2.draw(vertLine);}//end overridden paint() }//end inner class MyCanvas}//end class GUI

Listing 7 also signals the end of the overridden paint method, the end of the inner class named MyCanvas , and the end of the top-level class named GUI .

But wait, there's something wrong here

Kjell describes his points and lines in a very general way that is suitable for use in mathematical operations later on. However, in the above program, Ifell into the trap of defining my points and lines using Java classes that are intended primarily for rendering graphics on the screen. That approach isprobably not conducive to mathematical operations. We need to step back and take another look at what we are doing here.

Points, points, and more points

There will be many occasions when you, as a game programmer, will need to define the coordinate values for a point (or a set of points) that you have no intention of displaying on the screen. Instead, you will use thosepoints for various mathematical operations to produce something else that may or may not bedisplayed on the screen.

The Alice ice skater

For example, Figure 2 , Figure 3 , and Figure 4 show three views in the construction of the Ice skater object in the Alice programming language .

Figure 2 First of three views in the construction of a 3D human figure.

Missing image.

Figure 3 Second of three views in the construction of a 3D human figure.

Missing image.

Figure 4 Third of three views in the construction of a 3D human figure.

Missing image.

Points as the vertices of triangles

The image in Figure 2 shows a graphical representation of a set of points. These points wereused to define the vertices of the set of polygons shown i n Figure 3 . The polygons, in turn, were used in the construction of the ice skater object shownin Figure 4 .

As you can see, neither the points in Figure 2 , nor the lines that comprise the sides of the polygons in i n Figure 3 appear in the final rendering of the object in Figure 4 .

However, both the points and the polygons were required to support the mathematical operations that ultimatelyresulted in the ice skater object.

(Only the image in Figure 4 is typically displayed on the computer screen. I had to do some extra work to cause the points and thelines to be displayed.)

Another look at points and lines

We'll take another look at points and lines, and will introduce column matrices and vectors in the next sample program.

What is a vector?

According to Kjell, "A vector is a geometrical object that has two properties: length and direction." He also tells us, "A vector does not have a position."

In addition, Kjell tells us that we can represent a vector with two real numbers in a 2D system and with three real numbers in a 3D system.

Use a column matrix to represent a vector

A column matrix provides a good way to store two real numbers in a computer program. Therefore, in addition to representing a point, a column matrix canalso be used to represent a vector.

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