Game Development Reference
In-Depth Information
//5. Update Object Angular Position
////////////////////////////////////////////////////////////////////////////////
// Add Rotation to Rotation Matrix
orientation.AddRotation(m_AngularVelocity);
}
Hands-on Example: Linear Motion and Angular Motion
Using Forces
Here I guide you through a hands-on example demonstrating the use of forces to create linear and
angular movement in 3D objects. To follow along with this exercise, the best thing to do is to create a
new work space on your development system, download the code for this chapter from apress.com ,
and then import the project into your new work space.
Creating a Four-Sided Textured Cube
In our previous examples, we used a cube with a texture on two sides. Because we are
demonstrating angular rotation here, it would be easier to see the effect if the cube had a texture
on all four sides facing the viewer. The code in Listing 5-11 has been added to the Cube class to
produce a cube with a texture mapped on four sides.
Listing 5-11. Cube with Four-Sided Texture in Cube Class
static float CubeData4Sided[] =
{
// x, y, z, u, v nx, ny, nz
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, -1, 1, 1, // front top left 0
-0.5f, -0.5f, 0.5f, 0.0f, 1.0f, -1, -1, 1, // front bottom left 1
0.5f, -0.5f, 0.5f, 1.0f, 1.0f, 1, -1, 1, // front bottom right 2
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1, 1, 1, // front top right 3
-0.5f, 0.5f, -0.5f, 1.0f, 0.0f, -1, 1, -1, // back top left 4
-0.5f, -0.5f, -0.5f, 1.0f, 1.0f, -1, -1, -1, // back bottom left 5
0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 1, -1, -1, // back bottom right 6
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 1, 1, -1 // back top right 7
};
Modifying the Object3d Class
The Object3d class has to be modified to add functionality from our Physics class. First, we have to
add two new variables. The m_Physics variable is our interface to the object's physics properties.
private Physics m_Physics;
Another variable we must add is the m_Visible variable that is true if we want that object to be
visible and thus drawn to the screen.
 
Search WWH ::




Custom Search