Game Development Reference
In-Depth Information
m_Velocity.Add(m_Acceleration);
m_Velocity.x = TestSetLimitValue(m_Velocity.x, m_MaxVelocity.x);
m_Velocity.y = TestSetLimitValue(m_Velocity.y, m_MaxVelocity.y);
m_Velocity.z = TestSetLimitValue(m_Velocity.z, m_MaxVelocity.z);
// 2. Update Angular Velocity
/////////////////////////////////////////////////////////////////////////////////
m_AngularAcceleration = TestSetLimitValue(m_AngularAcceleration, m_MaxAngularAcceleration);
m_AngularVelocity += m_AngularAcceleration;
m_AngularVelocity = TestSetLimitValue(m_AngularVelocity,m_MaxAngularVelocity);
// 3. Reset Forces acting on Object
// Rebuild forces acting on object for each update
////////////////////////////////////////////////////////////////////////////////
m_Acceleration.Clear();
m_AngularAcceleration = 0;
//4. Update Object Linear Position
////////////////////////////////////////////////////////////////////////////////
Vector3 pos = orientation.GetPosition();
pos.Add(m_Velocity);
// 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;
}
}
//5. Update Object Angular Position
////////////////////////////////////////////////////////////////////////////////
// Add Rotation to Rotation Matrix
//orientation.AddRotation(m_AngularVelocity);
// Call Native Method
AddRotationToObject(orientation, m_AngularVelocity);
}
Modifying the MyGLRenderer Class
Finally, the MyGLRenderer class has to be modified.
The CreateArenaObjectsSet() function must be modified to apply rotational forces to the arena
objects, in order to demonstrate the use of native functions in rotating objects. The value of the
rotational force to apply to the arena objects is held in the RotationalForce variable and is set to 5000.
 
Search WWH ::




Custom Search