-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Description
I am at page 48 and actually using this code, but there is something wrong , and the sphere simply don't appear
what am i doing wrong ? i am sure i have follwed exactly the code in the book
` void Update(const float dt_sec)
{
m_position += m_linearVelocity * dt_sec;
// okay, we have an angular velocity around the center of mass, this needs to be
// converted somehow to relative to model position. This way we can properly update
// the orientation of the model.
Vec3 positionCM = GetCenterOfMassWorldSpace();
Vec3 cmToPos = m_position - positionCM;
// Total Torque is equal to external applied torques + internal torque (precession)
// T = T_external + omega x I * omega
// T_external = 0 because it was applied in the collision response function
// T = Ia = w x I * w
// a = I^-1 ( w x I * w )
Mat3 orientation = m_orientation.ToMat3();
Mat3 inertiaTensor = orientation * m_shape->InertiaTensor() * orientation.Transpose ();
Vec3 alpha = inertiaTensor.Inverse() * (m_angularVelocity.Cross (inertiaTensor * m_angularVelocity));
m_angularVelocity += alpha * dt_sec;
// Update orientation
Vec3 dAngle = m_angularVelocity * dt_sec;
Quat dq = Quat (dAngle, dAngle. GetMagnitude ());
m_orientation = dq * m_orientation;
m_orientation.Normalize ();
// Now ge t the new model position
m_position = positionCM + dq.RotatePoint(cmToPos);
}
`
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels