<< Chapter < Page Chapter >> Page >

Project eight points onto the 2D plane and draw them

Listing 8 calls the GM01.Point3D.draw method eight times in succession to cause the locations of the eight points in 3D space to be projected onto the2D off-screen image and to draw the points as small circles on that image. This is the first draw method from the earlier list that I explained above.

Listing 8 . Project eight points onto the 2D plane and draw them.
//Draw seven of the points in BLACK g2D.setColor(Color.BLACK);for(int cnt = 1;cnt<points.length;cnt++){ points[cnt].draw(g2D); }//end for loop//Draw the right top front point in RED to identify// it. g2D.setColor(Color.RED);points[0].draw(g2D);g2D.setColor(Color.BLACK);

Seven of the points are drawn in BLACK and one is drawn in RED. The eight small circles appear at the corners of the box in Figure 1 .

As indicated in the comments, the RED point is drawn at the right top front corner of the box to help you get the orientation of the box correct in yourmind's eye.

Draw twelve lines that connect the corners of the box

Listing 9 calls the GM01.Line3D.draw method twelve times in succession to project the lines that connect the corners of the 3D box onto the 2Doff-screen image and to draw those lines on that image. This is the second draw method from the earlier list that I explained above.

Listing 9 . Draw twelve lines that connect the corners of the box.
//Draw lines that connect the points to define the // twelve edges of the box.//Right side new GM01.Line3D(points[0],points[1]).draw(g2D);new GM01.Line3D(points[1],points[2]).draw(g2D); new GM01.Line3D(points[2],points[3]).draw(g2D);new GM01.Line3D(points[3],points[0]).draw(g2D);//Left side new GM01.Line3D(points[4],points[5]).draw(g2D);new GM01.Line3D(points[5],points[6]).draw(g2D); new GM01.Line3D(points[6],points[7]).draw(g2D);new GM01.Line3D(points[7],points[4]).draw(g2D);//Front new GM01.Line3D(points[0],points[4]).draw(g2D);new GM01.Line3D(points[3],points[7]).draw(g2D);//Back new GM01.Line3D(points[1],points[5]).draw(g2D);new GM01.Line3D(points[2],points[6]).draw(g2D);

Instantiate and draw a GM01.Vector3D object onto the 2D off-screen image

Listing 10 instantiates an object of the GM01.Vector3D class and calls the draw method of that class to draw the magenta vector shown in Figure 1 .

Listing 10 . Instantiate and draw a GM01.Vector3D object onto the 2D off-screen image.
//Instantiate a vector. GM01.Vector3D vecA = new GM01.Vector3D(new GM01.ColMatrix3D(75,-75,-75));//Draw the vector with its tail at the upper-left // corner of the box. The length and direction of the// vector will cause its head to be at the origin. g2D.setColor(Color.MAGENTA);vecA.draw(g2D,points[4]);}//end drawOffScreen

This is the third and final draw method from the earlier list that I explained above. The vector was drawn with its tail at the upper left corner ofthe box. The length and direction of the vector were such as to cause the head of the vector to be at the origin in 3D space.

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