<< Chapter < Page Chapter >> Page >
  • GM01.Point3D.draw
  • GM01.Vector3D.draw
  • GM01.Line3D.draw

The method named GM01.Point3D.draw

Recall that a point simply represents a location in space and has no width, height, or depth. Therefore a point is not visible to the human eye.However, it is sometimes useful to draw a small circle around a point to mark its location for human consumption. That is the purpose of the draw method of the GM01.Point3D class, which is shown in its entirety in Listing 4 .

Listing 4 . The method named GM01.Point3D.draw.
public void draw(Graphics2D g2D){//Get 2D projection coordinate values. ColMatrix2D temp = convert3Dto2D(point);drawOval(g2D,temp.getData(0)-3, temp.getData(1)+3,6, 6);}//end draw

Purpose of the method

This method draws a small circle around the location of a point in 3D space. The 3D location of the circle is projected onto the 2D plane of the specifiedgraphics context for display later on a 2D screen. The code in Listing 4 projects that location in 3D space onto the 2D plane by calling the staticmethod named convert3Dto2D .

Behavior of the GM01.Point3D.draw method

The location of a point in 3D space, as represented by an object of the GM01.Point3D class, is actually stored in an object of the GM01.ColMatrix3D class. A reference to that ColMatrix3D object is stored in the instance variable named point belonging to the Point3D object. This reference is passed as a parameter to the convert3Dto2D method in Listing 4 .

Recall from Listing 1 that the convert3Dto2D method receives an incoming reference to an object of the class GM01.ColMatrix3D and returns a reference to an object of the class GM01.ColMatrix2D , which contains the horizontal and vertical components of the projection of the 3D point onto a2D plane.

Using the returned GM01.ColMatrix2D object

Listing 4 uses the horizontal and vertical components stored in the returned ColMatrix2D object to construct the proper parameters and call the wrapper method named GM01.drawOval . This wrapper method doesn't know that it is receiving parameters that were originally derived from an objectin 3D space. The world of the wrapper method is confined to 2D space. The wrapper method named GM01.drawOval performs the following actions:

  • casts the four incoming numeric parameters to type int ,
  • flips the sign on the vertical component to resolve the issue regarding the positive value for the y-axis, and
  • passes the parameters to the drawOval method of the standard Graphics class to cause a small circle to be drawn at the correct location on the 2D off-screen image.

The small circle is not converted to an ellipse

Note that even though the location of the point in 3D space is projected onto the 2D plane, the shape of the small circle is not converted to an ellipse toreflect the 3D to 2D conversion nature of the operation. Thus, if the circle were large, it wouldn't necessarily look right. However, in thiscase, the only purpose of the circle is to mark the location of a point in 3D space. Therefore, I didn't consider the actual shape of the marker to betoo important. Figure 1 shows examples of circles marking points in 3D space at the corners of the box and at the ends of the axes.

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