<< Chapter < Page Chapter >> Page >

The terms in the equations

In Listing 2 , the terms x2d and y2d refer to drawing coordinates on the 2D screen, while x3d , y3d , and z3d refer to the coordinates of a point in 3D space. Obviously, sin , cos , and tan refer to the sine, cosine, and tangent of angles named alpha and theta .

Output in two dimensions

These equations and the assumptions that I made in using them produce displays such as the one shown in Figure 1 . In that image, the red horizontal line is the x-axis with the positive direction to the right.The green vertical line is the y-axis with the positive direction pointing up. The blue sloping line is the z-axis with the positive direction protruding fromthe screen towards and to the left of the viewer. The three axes intersect at the origin in 3D space.

(The sloping magenta line going from the corner of the box to the origin is a 3D vector. I will have more to say about the projectionsof 3D vectors later.)

No perspective in this projection

The sloping black lines in Figure 1 represent the edges of a rectangular box projected onto the 2D screen. Note in particular that there is noperspective in this type of projection. In other words, lines that are parallel in the 3D space remain parallel in the projection of those lines ontothe 2D screen. (Hence the word parallel in the name oblique parallel projection.) Objects don't appear to be smaller simply because they are further away from the viewer.

(The application of perspective would add another layer of complexity to the game math library. I will leave that as an exercise for the student toaccomplish.)

Options involving the angles

I could have produced a somewhat different display by assuming different values for the angles named alpha and theta . However, the values chosen are commonly used values that produce reasonably good results, so I decided to use them. You may find it interesting to experiment withother values for one or both angles to see the results produced by those other values.

The proper algebraic signs

Note in particular that the proper signs for the equations in Listing 2 depend on the assumed positive directions of the angles as well as the assumedpositive directions of the axes. The signs used in the method make the assumptions shown in Listing 2 . (These assumptions will be particularly important in future modules where we will be rotating objects in 3D space.)

The viewing position

Also as indicated in Listing 2 and shown in Figure 1 , the viewing position is above the x-axis and to the right of the z-y plane.

Typically, a game math library would provide the capability to modify the viewing position. That capability is not supported directly by this library.However, that capability can be approximated by the rotation capability discussed later. (Another exercise for the student to accomplish.)

The code in the method is straightforward

As I mentioned earlier, once you understand the requirements, the code for the method named convert3Dto2D (see Listing 1 ) is relatively straightforward. If you have studied the code in the previous modules inthis series, the code in Listing 1 shouldn't require further explanation.

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