Game Development Reference
In-Depth Information
else
{
m_Velocity.Set(NewVelocity.x, NewVelocity.y, NewVelocity.z);
}
//5. Update Object Linear Position
////////////////////////////////////////////////////////////////////////////////
Vector3 pos = orientation.GetPosition();
pos.Add(m_Velocity);
orientation.SetPosition(pos);
// Check for object hitting ground if gravity is on.
if (m_ApplyGravity)
{
if ((pos.y < m_GroundLevel)&& (m_Velocity.y < 0))
{
if (Math.abs(m_Velocity.y) > Math.abs(m_Gravity))
{
m_JustHitGround = true;
}
pos.y = m_GroundLevel;
m_Velocity.y = 0;
}
}
//6. Update Object Angular Position
////////////////////////////////////////////////////////////////////////////////
// Add Rotation to Rotation Matrix
orientation.AddRotation(m_AngularVelocity);
}
Modifying the Object3d Class
The UpdateObject3dToHeading() function is added to the Object3d class. The UpdateObject3dToHeading()
function updates an Object3d object with the physics model, where the object moves in the direction of
the Heading vector. This physics model is for the movement of the tank. (See Listing 8-50.)
Listing 8-50. Updating the Object Along a Heading
void UpdateObject3dToHeading(Vector3 Heading)
{
if (m_Visible)
{
// Update Object3d Physics
m_Physics.UpdatePhysicsObjectHeading(Heading, m_Orientation);
}
// Update Explosions associated with this object
UpdateExplosions();
}
 
Search WWH ::




Custom Search