<< Chapter < Page Chapter >> Page >

To assist you in this quest, I will present and explain modifications that were made to update the game-math library that you learned about in the previoustwo modules. In addition, I will present and explain three sample programs that illustrate the new features of the game-math 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

Much of the code in the library remains unchanged. I explained that code in previous modules and I won't repeat that explanation in this module.Rather, in this module, I will concentrate on explaining the modifications that I made to the library.

The game-math library named GM2D03

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

This update added the following new capabilities:

  • Compare two ColMatrix objects for equality by implementing Kjell's rules for equality given in his Chapter 1, topic "Column Matrix Equality." The equality test does not test for absolute equality. Rather, It compares the values stored in two matrices and returns true ifthe values are equal or almost equal and returns false otherwise.
  • Get a reference to the ColMatrix object that defines a Point object.
  • Compare two Point objects for equality based on a comparison of the ColMatrix objects that define them.
  • Get a reference to the ColMatrix object that defines a Vector object.
  • Compare two Vector objects for equality based on a comparison of the ColMatrix objects that define them.
  • Add one ColMatrix object to a second ColMatrix object, returning a ColMatrix object.
  • Subtract one ColMatrix object from a second ColMatrix object, returning a ColMatrix object.
  • Get a displacement vector from one Point object to a second Point object. The vector points from the object on which the getDisplacementVector method is called to the object passed as a parameter to the method.

I will explain these updates in conjunction with the discussions of the programs that follow.

The sample program named ColMatrixEquals01

A complete listing of this program is provided in Listing 12 near the end of the module. I will explain the program in fragments. In selectingthe portions of the program that I will explain, I will skip over material that is very similar to code that I have previously explained.

The purpose of this program is to confirm the behavior of the equals methods of the GM2D03.ColMatrix , Point , and Vector classes.

Overridden equals method of the GM2D03.ColMatrix class

I will begin by explaining some of the equals methods in the updated GM2D03 game-math library.

The first fragment in Listing 1 shows the new equals method of the ColMatrix class.

Listing 1 . Overridden equals method of the GM2D03.ColMatrix class.
public boolean equals(Object obj){ if(obj instanceof GM2D03.ColMatrix&&Math.abs(((GM2D03.ColMatrix)obj).getData(0) - getData(0))<= 0.00001&&Math.abs(((GM2D03.ColMatrix)obj).getData(1) - getData(1))<= 0.00001){ return true;}else{ return false;}//end else}//end overridden equals method

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