<< Chapter < Page | Chapter >> Page > |
The behavior described above for the method named GM01.Point3D.draw is somewhat indicative of the manner in which 3D geometric objects are projectedonto a 2D plane and the manner in which the issue regarding the positive direction of the y-axis is resolved by the code in the updated game-mathlibrary.
The behavior of the three draw methods
Each of the three draw methods listed earlier needs the ability to project a Point3D object, a Vector3D object, or a Line3D object onto a 2D pane. In each case, the object to be drawn is built up using one ormore ColMatrix3D objects as fundamental building blocks.
For the case of the GM01.Point3D.draw method discussed above, the draw method calls the convert3Dto2D method directly to convert the 3D coordinate values of the point to the 2D coordinate values required for thedisplay.
A similar approach for the GM01.Vector3D.draw method
A similar approach is used for the GM01.Vector3D.draw method, which is shown in Listing 5 .
Listing 5 . The method named GM01.Vector3D.draw. |
---|
public void draw(Graphics2D g2D,GM01.Point3D tail){//Get a 2D projection of the tail
GM01.ColMatrix2D tail2D = convert3Dto2D(tail.point);//Get the 3D location of the headGM01.ColMatrix3D head =
tail.point.add(this.getColMatrix());//Get a 2D projection of the headGM01.ColMatrix2D head2D = convert3Dto2D(head);
drawLine(g2D,tail2D.getData(0),tail2D.getData(1),
head2D.getData(0),head2D.getData(1));
//Draw a small filled circle to identify the head.fillOval(g2D,head2D.getData(0)-3,
head2D.getData(1)+3,6,
6);}//end draw |
This method draws the 2D visual manifestation of a GM01.Vector3D object on the specified 2D graphics context. Recall that a vector hasno location property. Therefore, it can be correctly drawn anywhere. The GM01.Vector3D.draw method requires the drawing location of the tail to be specified by a reference to a GM01.Point3D object received as an incoming parameter.
A small filled circle is drawn at the head of the vector as shown by the magenta filled circle at the origin in Figure 1 . (Note that the other circles in Figure 1 are not filled.)
Two calls to the convert3Dto2D method
Two calls are made to the convert3Dto2D method in Listing 5 . The first call gets a 2D projection of the 3D location of the tail of the vector.The second call gets a 2D projection of the 3D location of the head of the vector. In both cases, the projected location in 2D space is returned as areference to an object of the GM01.ColMatrix2D class.
Draw the vector on the specified drawing context
The reference returned by the first call to the convert3Dto2D method is used to call the static GM01.drawLine wrapper method to
The reference returned by the second call to the convert3Dto2D method is used to call the static GM01.fillOval wrapper method to
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?