Game Development Reference
In-Depth Information
// I = mr^2 = approximate with hoop inertia with r = 1 so that I = mass;
float Torque = r * Force;
float aangular = 0;
float I = m_Mass;
if (I != 0)
{
aangular = Torque/I;
}
m_AngularAcceleration += aangular;
}
The function UpdateValueWithinLimit updates the input value by increment, according to the limit
parameter. That is, the function returns the incremented value within the range -limit and limit.
(See Listing 5-7.)
Listing 5-7. UpdateValueWithinLimit Function
float UpdateValueWithinLimit(float value, float increment, float limit)
{
float retvalue = 0;
// Increments the value by the increment if the result
// is within +- limit value
float tempv = value + increment;
if (tempv > limit)
{
retvalue = limit;
}
else if (tempv < -limit)
{
retvalue = -limit;
}
else
{
retvalue += increment;
}
return retvalue;
}
The TestSetLimitValue() function clamps the value of the input parameter value to -limit to limit.
(See Listing 5-8.)
Listing 5-8. TestSetLimitValue Function
float TestSetLimitValue(float value, float limit)
{
float retvalue = value;
// If value is greater than limit then set value = limit
// If value is less than -limit then set value = -limit
if (value > limit)
 
Search WWH ::




Custom Search