<< Chapter < Page Chapter >> Page >

Preview

In this module, I will present and explain several updates to the game-math library. In addition, I will present and explain five sampleprograms that illustrate the use of the new features of the library.

I will also provide exercises for you to complete on your own at the end of the module. The exercises will concentrate on the material that you have learnedin this module and previous modules.

Discussion and sample code

The game-math library was updated and the name was changed to GM2D04 in preparation for this module. Much of the code in the updated library remains unchanged. I explained that code in the previousmodules and I won't repeat that explanation in this module. I will concentrate on explaining the modifications that I made to the library inthis module.

The game-math library named GM2D04

A complete listing of the library program is provided in Listing 19 near the end of the module.

This update added the following new capabilities to the library:

  • GM2D04.Vector.add - Adds this Vector object to a Vector object received as an incoming parameter and returns the sum as a new Vector object.
  • GM2D04.Vector.getLength - Returns the length of a Vector as type double .
  • GM2D04.Point.addVectorToPoint - Adds a Vector object to a Point object returning a new Point object.

These three new methods are presented in Listing 1 , Listing 2 , and Listing 3 below. These methods are so simple that no explanation should be required foryou to understand them.

Listing 1 . The add method of the GM2D04.Vector class.
//Adds this vector to a vector received as an incoming // parameter and returns the sum as a vector.public GM2D04.Vector add(GM2D04.Vector vec){ return new GM2D04.Vector(new ColMatrix(vec.getData(0)+vector.getData(0), vec.getData(1)+vector.getData(1)));}//end add
Listing 2 . The getLength method of the GM2D04.Vector class.
//Returns the length of a Vector object. public double getLength(){return Math.sqrt( getData(0)*getData(0) + getData(1)*getData(1));}//end getLength
Listing 3 . The addVectorToPoint method of the GM2D04 class.
//Adds a Vector to a Point producing a new Point. public GM2D04.Point addVectorToPoint(GM2D04.Vector vec){ return new GM2D04.Point(new GM2D04.ColMatrix(getData(0) + vec.getData(0), getData(1) + vec.getData(1)));}//end addVectorToPoint

Simple but powerful

Although these new methods are individually very simple, when combined with the other methods in the library, they significantly increase the power of thelibrary. For example, in the next module I will show you that the library in its current form supports translation and animation.

I will illustrate the use of these new methods in the sample programs that follow.

The program named VectorAdd01

This program illustrates the addition of two and then three vectors. It also illustrates the head-to-tail rule described by Kjell. A complete listing of the program is provided in Listing 20 near the end of the module.

Screen output from the program named VectorAdd01

Questions & Answers

Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
hi
Loga
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





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