<< Chapter < Page Chapter >> Page >
  • handle the issue of the positive direction of the y-axis, and
  • draw a small filled circle on the 2D off-screen image representing the head of the vector as shown by the magenta filled circle at the origin in Figure 1 .

The method named GM01.Line3D.draw

The GM01.Line3D.draw method is shown in Listing 6 .

Listing 6 . The GM01.Line3D.draw method.
public void draw(Graphics2D g2D){//Get 2D projection coordinates. GM01.ColMatrix2D tail =convert3Dto2D(getTail().point); GM01.ColMatrix2D head =convert3Dto2D(getHead().point); drawLine(g2D,tail.getData(0),tail.getData(1), head.getData(0),head.getData(1)); }//end draw

The code in Listing 6 is so similar to the code in Listing 5 that no further explanation should be required.

Now back to the program named GM01test01

A complete listing of the program named GM01test01 is provided in Listing 28 near the end of the module.

Because all of the 3D classes in the game-math library are new to this update, I felt the need to write a program that would step through and test thebehavior of most of the 3D methods in the library. That was the purpose of the program named GM01test01 .

Like the program named GM01test02 discussed earlier, this program produces both a graphic screen output and lots of text on thecommand-line screen. The graphic output is shown in Figure 1 . I won't waste space printing the command-line output in this tutorial. Ifyou want to see it, you can copy, compile, and run the program from Listing 28 and produce that output yourself.

The graphic output

The graphic output shown in Figure 1 is produced by the method named drawOffScreen , which begins in Listing 7 . I will briefly walk you through this method because everything in it is new. However, much of thecode is very similar to 2D code that I have explained before.

Listing 7 . Beginning of the drawOffScreen method in GM01test01.
void drawOffScreen(Graphics2D g2D){//Translate the origin on the off-screen // image and draw a pair of orthogonal axes on it.setCoordinateFrame(g2D); //Define eight points that define the corners of// a box in 3D that is centered on the origin.GM01.Point3D[] points = new GM01.Point3D[8]; //Right sidepoints[0] =new GM01.Point3D(new GM01.ColMatrix3D(75,75,75)); points[1]= new GM01.Point3D(new GM01.ColMatrix3D(75,75,-75));points[2] =new GM01.Point3D(new GM01.ColMatrix3D(75,-75,-75)); points[3]= new GM01.Point3D(new GM01.ColMatrix3D(75,-75,75));//Left side points[4]= new GM01.Point3D(new GM01.ColMatrix3D(-75,75,75));points[5] =new GM01.Point3D(new GM01.ColMatrix3D(-75,75,-75)); points[6]= new GM01.Point3D(new GM01.ColMatrix3D(-75,-75,-75));points[7] =new GM01.Point3D(new GM01.ColMatrix3D(-75,-75,75));

After translating the origin to the center of the off-screen image, Listing 7 instantiates eight GM01Point3D objects that define the corners of the 3D box shown in Figure 1 . References to the eight objects are stored in the elements of an array object referred to by thevariable named points . Although this code uses three coordinate values instead of two coordinate values to instantiate the objects, thesyntax should be very familiar to you by now.

Questions & Answers

how did the oxygen help a human being
Achol Reply
how did the nutrition help the plants
Achol Reply
Biology is a branch of Natural science which deals/About living Organism.
Ahmedin Reply
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
cell is the smallest unit of the humanity biologically
Abraham
what is biology
Victoria Reply
what is biology
Abraham
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
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