<< Chapter < Page Chapter >> Page >

Preview

This module will build on what you learned about the vector dot product in the earlier module titled GAME 2302-0145: Getting Started with the Vector Dot Product . In that module, you learned some of the theory behind the dot product. In this module, you will learn how to use the dot-productmethods of the game-math library to write several applications. I will present and explain the following four programs:

  • DotProd3D05 - Demonstrates how the dot product can be used to compute nine different angles of interest that a vector makes with variouselements in 3D space.
  • DotProd3D06 - Demonstrates the use of the dot product to find six somewhat unique vectors of the infinite set of vectors that are perpendicular to a given vector. (See Figure 4 .)
  • DotProd3D04 - Draws the same 3D object as the one drawn in DotProd3D03 but without the benefit of back-face culling. (See Figure 1 .)
  • DotProd3D03 - Demonstrates use of the vector dot product for back-face culling. (See Figure 2 .)

I will also provide exercises for you to complete on your own at the end of the module. The exercises will concentrate on the material that you have learnedin this module and previous modules.

Discussion and sample code

The game-math library named GM02

The game-math library has not been modified since the previous module. Therefore, there is nothing new to discuss and explain insofar as the library isconcerned. For your convenience, a complete listing of the source code for the library is provided in Listing 9 near the end of the module.

A link to a zip file containing documentation for the library is provided in the earlier module titled GAME 2302-0145: Getting Started with the Vector Dot Product .

The program named DotProd3D05

In order to understand this and the following programs, you need to understand the material in the Kjell tutorial through Chapter 10, Angle between 3D Vectors .

Game programming frequently requires the determination of angles of various types. The purpose of this program is to demonstrate how the dot product can beused to compute nine different angles of interest that a vector makes with various elements in 3Dspace.

Figure 3 shows a screen shot of the graphical user interface provided by this program.

Figure 3 - Screen shot of the output from the program named DotProd3D05.

Missing image.

Angles relative to the axes

First, the program computes and displays the angle between a user-specified vector (drawn in black in Figure 3 ) and each of the X, Y, and Z axes. These values are displayed with the labels Angle X , Angle Y , and Angle Z in Figure 3 .

Angles relative to the XY, YZ, and ZX planes

Then the program computes and displays the angle between the vector and each of the XY , YZ , and ZX planes. In this case, the program computes the smallest possible angle by projecting the vector onto the plane andthen computing the angle between the vector and its projection. These values are displayed with the labels Angle XY , Angle YZ , and Angle ZX .

Angles of projections relatives to the axes

Finally, the program computes and displays the angle between the projection of the vector on each of the three planes and one of the axes that defines eachplane. The angle between the projection and the other axis that defines the plane is 90 degrees minus the computed angle. Specifically the values that arecomputed and displayed are:

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