Set contact point and max suspension when 1 wheel off ground

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3908 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
davemk 2009-08-23 14:38:46 +00:00
parent 0549c9c965
commit 96e2c28799

View File

@ -424,19 +424,34 @@ void btKart::updateVehicle( btScalar step )
// are on ground, or none of them. This avoids the problem of
// the kart suddenly getting additional angular velocity because
// e.g. only one rear wheel is on the ground.
for(i=0; i<4; i+=2)
for(i=0; i<m_wheelInfo.size(); i+=2)
{
if(m_wheelInfo[i].m_raycastInfo.m_isInContact &&
!(m_wheelInfo[i+1].m_raycastInfo.m_isInContact))
if(m_wheelInfo[i].m_raycastInfo.m_isInContact != m_wheelInfo[i+1].m_raycastInfo.m_isInContact)
{
m_wheelInfo[i+1].m_raycastInfo = m_wheelInfo[i].m_raycastInfo;
int wheel_air_index = i;
if (m_wheelInfo[i].m_raycastInfo.m_isInContact)
wheel_air_index = i+1;
btWheelInfo& wheel_air = m_wheelInfo[wheel_air_index];
wheel_air.m_raycastInfo.m_isInContact = true;
wheel_air.m_raycastInfo.m_groundObject = &s_fixedObject;//todo for driving on dynamic/movable objects!;
btScalar maxSuspensionLength =wheel_air.getSuspensionRestLength()+ wheel_air.m_maxSuspensionTravelCm*btScalar(0.01);
wheel_air.m_raycastInfo.m_suspensionLength = maxSuspensionLength;
//extra fix to suspension
btVector3 chassis_velocity_at_contactPoint;
btVector3 relpos = wheel_air.m_raycastInfo.m_contactPointWS-getRigidBody()->getCenterOfMassPosition();
chassis_velocity_at_contactPoint = getRigidBody()->getVelocityInLocalPoint(relpos);
btScalar projVel = wheel_air.m_raycastInfo.m_contactNormalWS.dot( chassis_velocity_at_contactPoint );
wheel_air.m_suspensionRelativeVelocity = projVel;
}
if(!(m_wheelInfo[i].m_raycastInfo.m_isInContact) &&
m_wheelInfo[i+1].m_raycastInfo.m_isInContact)
{
m_wheelInfo[i].m_raycastInfo = m_wheelInfo[i+1].m_raycastInfo;
}
} // for i=0; i<4; i+=2
} // for i=0; i<m_wheelInfo.size(); i+=2
updateSuspension(step);