Back to index

supertuxkart  0.5+dfsg1
Classes | Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions | Private Attributes
btRaycastVehicle Class Reference

rayCast vehicle, very special constraint that turn a rigidbody into a vehicle. More...

#include <btRaycastVehicle.h>

Inheritance diagram for btRaycastVehicle:
Inheritance graph
[legend]
Collaboration diagram for btRaycastVehicle:
Collaboration graph
[legend]

List of all members.

Classes

class  btVehicleTuning

Public Member Functions

 btRaycastVehicle (const btVehicleTuning &tuning, btRigidBody *chassis, btVehicleRaycaster *raycaster)
virtual ~btRaycastVehicle ()
const btTransformgetChassisWorldTransform () const
btScalar rayCast (btWheelInfo &wheel)
virtual void updateVehicle (btScalar step)
void resetSuspension ()
btScalar getSteeringValue (int wheel) const
void setSteeringValue (btScalar steering, int wheel)
void applyEngineForce (btScalar force, int wheel)
const btTransformgetWheelTransformWS (int wheelIndex) const
void updateWheelTransform (int wheelIndex, bool interpolatedTransform=true)
void setRaycastWheelInfo (int wheelIndex, bool isInContact, const btVector3 &hitPoint, const btVector3 &hitNormal, btScalar depth)
btWheelInfoaddWheel (const btVector3 &connectionPointCS0, const btVector3 &wheelDirectionCS0, const btVector3 &wheelAxleCS, btScalar suspensionRestLength, btScalar wheelRadius, const btVehicleTuning &tuning, bool isFrontWheel)
int getNumWheels () const
const btWheelInfogetWheelInfo (int index) const
btWheelInfogetWheelInfo (int index)
void updateWheelTransformsWS (btWheelInfo &wheel, bool interpolatedTransform=true)
void setBrake (btScalar brake, int wheelIndex)
void setPitchControl (btScalar pitch)
void updateSuspension (btScalar deltaTime)
virtual void updateFriction (btScalar timeStep)
btRigidBodygetRigidBody ()
const btRigidBodygetRigidBody () const
int getRightAxis () const
int getUpAxis () const
int getForwardAxis () const
btVector3 getForwardVector () const
 Worldspace forward vector.
btScalar getCurrentSpeedKmHour () const
 Velocity of vehicle (positive if velocity vector has same direction as foward vector)
virtual void setCoordinateSystem (int rightIndex, int upIndex, int forwardIndex)
virtual void buildJacobian ()
virtual void solveConstraint (btScalar timeStep)
const btRigidBodygetRigidBodyA () const
btRigidBodygetRigidBodyA ()
const btRigidBodygetRigidBodyB () const
btRigidBodygetRigidBodyB ()
int getUserConstraintType () const
void setUserConstraintType (int userConstraintType)
void setUserConstraintId (int uid)
int getUserConstraintId () const
int getUid () const
btScalar getAppliedImpulse () const
btTypedConstraintType getConstraintType () const

Public Attributes

btAlignedObjectArray< btWheelInfom_wheelInfo

Protected Attributes

btRigidBodym_rbA
btRigidBodym_rbB
btScalar m_appliedImpulse

Private Member Functions

void defaultInit (const btVehicleTuning &tuning)

Private Attributes

btAlignedObjectArray< btVector3m_forwardWS
btAlignedObjectArray< btVector3m_axle
btAlignedObjectArray< btScalarm_forwardImpulse
btAlignedObjectArray< btScalarm_sideImpulse
btScalar m_tau
btScalar m_damping
btVehicleRaycasterm_vehicleRaycaster
btScalar m_pitchControl
btScalar m_steeringValue
btScalar m_currentVehicleSpeedKmHour
btRigidBodym_chassisBody
int m_indexRightAxis
int m_indexUpAxis
int m_indexForwardAxis

Detailed Description

rayCast vehicle, very special constraint that turn a rigidbody into a vehicle.

Definition at line 24 of file btRaycastVehicle.h.


Constructor & Destructor Documentation

btRaycastVehicle::btRaycastVehicle ( const btVehicleTuning tuning,
btRigidBody chassis,
btVehicleRaycaster raycaster 
)

Definition at line 28 of file btRaycastVehicle.cpp.

Here is the call graph for this function:

Definition at line 51 of file btRaycastVehicle.cpp.

{
}

Member Function Documentation

btWheelInfo & btRaycastVehicle::addWheel ( const btVector3 connectionPointCS0,
const btVector3 wheelDirectionCS0,
const btVector3 wheelAxleCS,
btScalar  suspensionRestLength,
btScalar  wheelRadius,
const btVehicleTuning tuning,
bool  isFrontWheel 
)

Definition at line 59 of file btRaycastVehicle.cpp.

{

       btWheelInfoConstructionInfo ci;

       ci.m_chassisConnectionCS = connectionPointCS;
       ci.m_wheelDirectionCS = wheelDirectionCS0;
       ci.m_wheelAxleCS = wheelAxleCS;
       ci.m_suspensionRestLength = suspensionRestLength;
       ci.m_wheelRadius = wheelRadius;
       ci.m_suspensionStiffness = tuning.m_suspensionStiffness;
       ci.m_wheelsDampingCompression = tuning.m_suspensionCompression;
       ci.m_wheelsDampingRelaxation = tuning.m_suspensionDamping;
       ci.m_frictionSlip = tuning.m_frictionSlip;
       ci.m_bIsFrontWheel = isFrontWheel;
       ci.m_maxSuspensionTravelCm = tuning.m_maxSuspensionTravelCm;

       m_wheelInfo.push_back( btWheelInfo(ci));
       
       btWheelInfo& wheel = m_wheelInfo[getNumWheels()-1];
       
       updateWheelTransformsWS( wheel , false );
       updateWheelTransform(getNumWheels()-1,false);
       return wheel;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void btRaycastVehicle::applyEngineForce ( btScalar  force,
int  wheel 
)

Definition at line 376 of file btRaycastVehicle.cpp.

{
       assert(wheel>=0 && wheel < getNumWheels());
       btWheelInfo& wheelInfo = getWheelInfo(wheel);
       wheelInfo.m_engineForce = force;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void btRaycastVehicle::buildJacobian ( ) [inline, virtual]

Implements btTypedConstraint.

Definition at line 178 of file btRaycastVehicle.h.

       {
              //not yet
       }
void btRaycastVehicle::defaultInit ( const btVehicleTuning tuning) [private]

Definition at line 41 of file btRaycastVehicle.cpp.

Here is the caller graph for this function:

btScalar btTypedConstraint::getAppliedImpulse ( ) const [inline, inherited]

Definition at line 108 of file btTypedConstraint.h.

       {
              return m_appliedImpulse;
       }

Definition at line 246 of file btRaycastVehicle.cpp.

{
       /*if (getRigidBody()->getMotionState())
       {
              btTransform chassisWorldTrans;
              getRigidBody()->getMotionState()->getWorldTransform(chassisWorldTrans);
              return chassisWorldTrans;
       }
       */

       
       return getRigidBody()->getCenterOfMassTransform();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 113 of file btTypedConstraint.h.

       {
              return m_constraintType;
       }

Here is the caller graph for this function:

Velocity of vehicle (positive if velocity vector has same direction as foward vector)

Definition at line 166 of file btRaycastVehicle.h.

int btRaycastVehicle::getForwardAxis ( ) const [inline]

Definition at line 146 of file btRaycastVehicle.h.

       {
              return m_indexForwardAxis;
       }

Worldspace forward vector.

Definition at line 153 of file btRaycastVehicle.h.

       {
              const btTransform& chassisTrans = getChassisWorldTransform(); 

              btVector3 forwardW ( 
                       chassisTrans.getBasis()[0][m_indexForwardAxis], 
                       chassisTrans.getBasis()[1][m_indexForwardAxis], 
                       chassisTrans.getBasis()[2][m_indexForwardAxis]); 

              return forwardW;
       }

Here is the call graph for this function:

int btRaycastVehicle::getNumWheels ( ) const [inline]

Definition at line 100 of file btRaycastVehicle.h.

                                                 {
              return int (m_wheelInfo.size());
       }

Here is the call graph for this function:

Here is the caller graph for this function:

int btRaycastVehicle::getRightAxis ( ) const [inline]

Definition at line 137 of file btRaycastVehicle.h.

       {
              return m_indexRightAxis;
       }

Definition at line 127 of file btRaycastVehicle.h.

       {
              return m_chassisBody;
       }

Here is the caller graph for this function:

const btRigidBody* btRaycastVehicle::getRigidBody ( ) const [inline]

Definition at line 132 of file btRaycastVehicle.h.

       {
              return m_chassisBody;
       }
const btRigidBody& btTypedConstraint::getRigidBodyA ( ) const [inline, inherited]

Reimplemented in btGeneric6DofConstraint, btSliderConstraint, btConeTwistConstraint, and btHingeConstraint.

Definition at line 65 of file btTypedConstraint.h.

       {
              return m_rbA;
       }

Here is the caller graph for this function:

Definition at line 74 of file btTypedConstraint.h.

       {
              return m_rbA;
       }
const btRigidBody& btTypedConstraint::getRigidBodyB ( ) const [inline, inherited]

Reimplemented in btGeneric6DofConstraint, btSliderConstraint, btConeTwistConstraint, and btHingeConstraint.

Definition at line 69 of file btTypedConstraint.h.

       {
              return m_rbB;
       }

Here is the caller graph for this function:

Definition at line 78 of file btTypedConstraint.h.

       {
              return m_rbB;
       }

Definition at line 370 of file btRaycastVehicle.cpp.

{
       return getWheelInfo(wheel).m_steering;
}

Here is the call graph for this function:

int btTypedConstraint::getUid ( ) const [inline, inherited]

Definition at line 103 of file btTypedConstraint.h.

       {
              return m_userConstraintId;   
       } 
int btRaycastVehicle::getUpAxis ( ) const [inline]

Definition at line 141 of file btRaycastVehicle.h.

       {
              return m_indexUpAxis;
       }
int btTypedConstraint::getUserConstraintId ( ) const [inline, inherited]

Definition at line 98 of file btTypedConstraint.h.

       {
              return m_userConstraintId;
       }
int btTypedConstraint::getUserConstraintType ( ) const [inline, inherited]

Definition at line 83 of file btTypedConstraint.h.

       {
              return m_userConstraintType ;
       }
const btWheelInfo & btRaycastVehicle::getWheelInfo ( int  index) const

Definition at line 384 of file btRaycastVehicle.cpp.

{
       btAssert((index >= 0) && (index <  getNumWheels()));
       
       return m_wheelInfo[index];
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 391 of file btRaycastVehicle.cpp.

{
       btAssert((index >= 0) && (index <  getNumWheels()));
       
       return m_wheelInfo[index];
}

Here is the call graph for this function:

const btTransform & btRaycastVehicle::getWheelTransformWS ( int  wheelIndex) const

Definition at line 88 of file btRaycastVehicle.cpp.

{
       assert(wheelIndex < getNumWheels());
       const btWheelInfo& wheel = m_wheelInfo[wheelIndex];
       return wheel.m_worldTransform;

}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 160 of file btRaycastVehicle.cpp.

{
       updateWheelTransformsWS( wheel,false);

       
       btScalar depth = -1;
       
       btScalar raylen = wheel.getSuspensionRestLength()+wheel.m_wheelsRadius;

       btVector3 rayvector = wheel.m_raycastInfo.m_wheelDirectionWS * (raylen);
       const btVector3& source = wheel.m_raycastInfo.m_hardPointWS;
       wheel.m_raycastInfo.m_contactPointWS = source + rayvector;
       const btVector3& target = wheel.m_raycastInfo.m_contactPointWS;

       btScalar param = btScalar(0.);
       
       btVehicleRaycaster::btVehicleRaycasterResult     rayResults;

       assert(m_vehicleRaycaster);

       void* object = m_vehicleRaycaster->castRay(source,target,rayResults);

       wheel.m_raycastInfo.m_groundObject = 0;

       if (object)
       {
              param = rayResults.m_distFraction;
              depth = raylen * rayResults.m_distFraction;
              wheel.m_raycastInfo.m_contactNormalWS  = rayResults.m_hitNormalInWorld;
              wheel.m_raycastInfo.m_isInContact = true;
              
              wheel.m_raycastInfo.m_groundObject = &s_fixedObject;//todo for driving on dynamic/movable objects!;
              //wheel.m_raycastInfo.m_groundObject = object;


              btScalar hitDistance = param*raylen;
              wheel.m_raycastInfo.m_suspensionLength = hitDistance - wheel.m_wheelsRadius;
              //clamp on max suspension travel

              btScalar  minSuspensionLength = wheel.getSuspensionRestLength() - wheel.m_maxSuspensionTravelCm*btScalar(0.01);
              btScalar maxSuspensionLength = wheel.getSuspensionRestLength()+ wheel.m_maxSuspensionTravelCm*btScalar(0.01);
              if (wheel.m_raycastInfo.m_suspensionLength < minSuspensionLength)
              {
                     wheel.m_raycastInfo.m_suspensionLength = minSuspensionLength;
              }
              if (wheel.m_raycastInfo.m_suspensionLength > maxSuspensionLength)
              {
                     wheel.m_raycastInfo.m_suspensionLength = maxSuspensionLength;
              }

              wheel.m_raycastInfo.m_contactPointWS = rayResults.m_hitPointInWorld;

              btScalar denominator= wheel.m_raycastInfo.m_contactNormalWS.dot( wheel.m_raycastInfo.m_wheelDirectionWS );

              btVector3 chassis_velocity_at_contactPoint;
              btVector3 relpos = wheel.m_raycastInfo.m_contactPointWS-getRigidBody()->getCenterOfMassPosition();

              chassis_velocity_at_contactPoint = getRigidBody()->getVelocityInLocalPoint(relpos);

              btScalar projVel = wheel.m_raycastInfo.m_contactNormalWS.dot( chassis_velocity_at_contactPoint );

              if ( denominator >= btScalar(-0.1))
              {
                     wheel.m_suspensionRelativeVelocity = btScalar(0.0);
                     wheel.m_clippedInvContactDotSuspension = btScalar(1.0) / btScalar(0.1);
              }
              else
              {
                     btScalar inv = btScalar(-1.) / denominator;
                     wheel.m_suspensionRelativeVelocity = projVel * inv;
                     wheel.m_clippedInvContactDotSuspension = inv;
              }
                     
       } else
       {
              //put wheel info as in rest position
              wheel.m_raycastInfo.m_suspensionLength = wheel.getSuspensionRestLength();
              wheel.m_suspensionRelativeVelocity = btScalar(0.0);
              wheel.m_raycastInfo.m_contactNormalWS = - wheel.m_raycastInfo.m_wheelDirectionWS;
              wheel.m_clippedInvContactDotSuspension = btScalar(1.0);
       }

       return depth;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 129 of file btRaycastVehicle.cpp.

{

       int i;
       for (i=0;i<m_wheelInfo.size();     i++)
       {
                     btWheelInfo& wheel = m_wheelInfo[i];
                     wheel.m_raycastInfo.m_suspensionLength = wheel.getSuspensionRestLength();
                     wheel.m_suspensionRelativeVelocity = btScalar(0.0);
                     
                     wheel.m_raycastInfo.m_contactNormalWS = - wheel.m_raycastInfo.m_wheelDirectionWS;
                     //wheel_info.setContactFriction(btScalar(0.0));
                     wheel.m_clippedInvContactDotSuspension = btScalar(1.0);
       }
}

Here is the call graph for this function:

void btRaycastVehicle::setBrake ( btScalar  brake,
int  wheelIndex 
)

Definition at line 398 of file btRaycastVehicle.cpp.

{
       btAssert((wheelIndex >= 0) && (wheelIndex <      getNumWheels()));
       getWheelInfo(wheelIndex).m_brake = brake;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void btRaycastVehicle::setCoordinateSystem ( int  rightIndex,
int  upIndex,
int  forwardIndex 
) [inline, virtual]

Definition at line 171 of file btRaycastVehicle.h.

       {
              m_indexRightAxis = rightIndex;
              m_indexUpAxis = upIndex;
              m_indexForwardAxis = forwardIndex;
       }

Here is the caller graph for this function:

void btRaycastVehicle::setPitchControl ( btScalar  pitch) [inline]

Definition at line 116 of file btRaycastVehicle.h.

       {
              m_pitchControl = pitch;
       }
void btRaycastVehicle::setRaycastWheelInfo ( int  wheelIndex,
bool  isInContact,
const btVector3 hitPoint,
const btVector3 hitNormal,
btScalar  depth 
)
void btRaycastVehicle::setSteeringValue ( btScalar  steering,
int  wheel 
)

Definition at line 360 of file btRaycastVehicle.cpp.

{
       assert(wheel>=0 && wheel < getNumWheels());

       btWheelInfo& wheelInfo = getWheelInfo(wheel);
       wheelInfo.m_steering = steering;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void btTypedConstraint::setUserConstraintId ( int  uid) [inline, inherited]

Definition at line 93 of file btTypedConstraint.h.

       {
              m_userConstraintId = uid;
       }
void btTypedConstraint::setUserConstraintType ( int  userConstraintType) [inline, inherited]

Definition at line 88 of file btTypedConstraint.h.

       {
              m_userConstraintType = userConstraintType;
       };
virtual void btRaycastVehicle::solveConstraint ( btScalar  timeStep) [inline, virtual]

Implements btTypedConstraint.

Definition at line 183 of file btRaycastVehicle.h.

       {
              (void)timeStep;
              //not yet
       }
void btRaycastVehicle::updateFriction ( btScalar  timeStep) [virtual]

Definition at line 519 of file btRaycastVehicle.cpp.

{

              //calculate the impulse, so that the wheels don't move sidewards
              int numWheel = getNumWheels();
              if (!numWheel)
                     return;

              m_forwardWS.resize(numWheel);
              m_axle.resize(numWheel);
              m_forwardImpulse.resize(numWheel);
              m_sideImpulse.resize(numWheel);
              
              int numWheelsOnGround = 0;
       

              //collapse all those loops into one!
              for (int i=0;i<getNumWheels();i++)
              {
                     btWheelInfo& wheelInfo = m_wheelInfo[i];
                     class btRigidBody* groundObject = (class btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject;
                     if (groundObject)
                            numWheelsOnGround++;
                     m_sideImpulse[i] = btScalar(0.);
                     m_forwardImpulse[i] = btScalar(0.);

              }
       
              {
       
                     for (int i=0;i<getNumWheels();i++)
                     {

                            btWheelInfo& wheelInfo = m_wheelInfo[i];
                                   
                            class btRigidBody* groundObject = (class btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject;

                            if (groundObject)
                            {

                                   const btTransform& wheelTrans = getWheelTransformWS( i );

                                   btMatrix3x3 wheelBasis0 = wheelTrans.getBasis();
                                   m_axle[i] = btVector3(      
                                          wheelBasis0[0][m_indexRightAxis],
                                          wheelBasis0[1][m_indexRightAxis],
                                          wheelBasis0[2][m_indexRightAxis]);
                                   
                                   const btVector3& surfNormalWS = wheelInfo.m_raycastInfo.m_contactNormalWS;
                                   btScalar proj = m_axle[i].dot(surfNormalWS);
                                   m_axle[i] -= surfNormalWS * proj;
                                   m_axle[i] = m_axle[i].normalize();
                                   
                                   m_forwardWS[i] = surfNormalWS.cross(m_axle[i]);
                                   m_forwardWS[i].normalize();

                            
                                   resolveSingleBilateral(*m_chassisBody, wheelInfo.m_raycastInfo.m_contactPointWS,
                                                   *groundObject, wheelInfo.m_raycastInfo.m_contactPointWS,
                                                   btScalar(0.), m_axle[i],m_sideImpulse[i],timeStep);

                                   m_sideImpulse[i] *= sideFrictionStiffness2;
                                          
                            }
                            

                     }
              }

       btScalar sideFactor = btScalar(1.);
       btScalar fwdFactor = 0.5;

       bool sliding = false;
       {
              for (int wheel =0;wheel <getNumWheels();wheel++)
              {
                     btWheelInfo& wheelInfo = m_wheelInfo[wheel];
                     class btRigidBody* groundObject = (class btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject;

                     btScalar      rollingFriction = 0.f;

                     if (groundObject)
                     {
                            if (wheelInfo.m_engineForce != 0.f)
                            {
                                   rollingFriction = wheelInfo.m_engineForce* timeStep;
                            } else
                            {
                                   btScalar defaultRollingFrictionImpulse = 0.f;
                                   btScalar maxImpulse = wheelInfo.m_brake ? wheelInfo.m_brake : defaultRollingFrictionImpulse;
                                   btWheelContactPoint contactPt(m_chassisBody,groundObject,wheelInfo.m_raycastInfo.m_contactPointWS,m_forwardWS[wheel],maxImpulse);
                                   rollingFriction = calcRollingFriction(contactPt);
                            }
                     }

                     //switch between active rolling (throttle), braking and non-active rolling friction (no throttle/break)
                     



                     m_forwardImpulse[wheel] = btScalar(0.);
                     m_wheelInfo[wheel].m_skidInfo= btScalar(1.);

                     if (groundObject)
                     {
                            m_wheelInfo[wheel].m_skidInfo= btScalar(1.);
                            
                            btScalar maximp = wheelInfo.m_wheelsSuspensionForce * timeStep * wheelInfo.m_frictionSlip;
                            btScalar maximpSide = maximp;

                            btScalar maximpSquared = maximp * maximpSide;
                     

                            m_forwardImpulse[wheel] = rollingFriction;//wheelInfo.m_engineForce* timeStep;

                            btScalar x = (m_forwardImpulse[wheel] ) * fwdFactor;
                            btScalar y = (m_sideImpulse[wheel] ) * sideFactor;
                            
                            btScalar impulseSquared = (x*x + y*y);

                            if (impulseSquared > maximpSquared)
                            {
                                   sliding = true;
                                   
                                   btScalar factor = maximp / btSqrt(impulseSquared);
                                   
                                   m_wheelInfo[wheel].m_skidInfo *= factor;
                            }
                     } 

              }
       }

       


              if (sliding)
              {
                     for (int wheel = 0;wheel < getNumWheels(); wheel++)
                     {
                            if (m_sideImpulse[wheel] != btScalar(0.))
                            {
                                   if (m_wheelInfo[wheel].m_skidInfo< btScalar(1.))
                                   {
                                          m_forwardImpulse[wheel] *=  m_wheelInfo[wheel].m_skidInfo;
                                          m_sideImpulse[wheel] *= m_wheelInfo[wheel].m_skidInfo;
                                   }
                            }
                     }
              }

              // apply the impulses
              {
                     for (int wheel = 0;wheel<getNumWheels() ; wheel++)
                     {
                            btWheelInfo& wheelInfo = m_wheelInfo[wheel];

                            btVector3 rel_pos = wheelInfo.m_raycastInfo.m_contactPointWS - 
                                          m_chassisBody->getCenterOfMassPosition();

                            if (m_forwardImpulse[wheel] != btScalar(0.))
                            {
                                   m_chassisBody->applyImpulse(m_forwardWS[wheel]*(m_forwardImpulse[wheel]),rel_pos);
                            }
                            if (m_sideImpulse[wheel] != btScalar(0.))
                            {
                                   class btRigidBody* groundObject = (class btRigidBody*) m_wheelInfo[wheel].m_raycastInfo.m_groundObject;

                                   btVector3 rel_pos2 = wheelInfo.m_raycastInfo.m_contactPointWS - 
                                          groundObject->getCenterOfMassPosition();

                                   
                                   btVector3 sideImp = m_axle[wheel] * m_sideImpulse[wheel];

                                   rel_pos[2] *= wheelInfo.m_rollInfluence;
                                   m_chassisBody->applyImpulse(sideImp,rel_pos);

                                   //apply friction impulse on the ground
                                   groundObject->applyImpulse(-sideImp,rel_pos2);
                            }
                     }
              }

       
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 405 of file btRaycastVehicle.cpp.

{
       (void)deltaTime;

       btScalar chassisMass = btScalar(1.) / m_chassisBody->getInvMass();
       
       for (int w_it=0; w_it<getNumWheels(); w_it++)
       {
              btWheelInfo &wheel_info = m_wheelInfo[w_it];
              
              if ( wheel_info.m_raycastInfo.m_isInContact )
              {
                     btScalar force;
                     //     Spring
                     {
                            btScalar      susp_length                 = wheel_info.getSuspensionRestLength();
                            btScalar      current_length = wheel_info.m_raycastInfo.m_suspensionLength;

                            btScalar length_diff = (susp_length - current_length);

                            force = wheel_info.m_suspensionStiffness
                                   * length_diff * wheel_info.m_clippedInvContactDotSuspension;
                     }
              
                     // Damper
                     {
                            btScalar projected_rel_vel = wheel_info.m_suspensionRelativeVelocity;
                            {
                                   btScalar      susp_damping;
                                   if ( projected_rel_vel < btScalar(0.0) )
                                   {
                                          susp_damping = wheel_info.m_wheelsDampingCompression;
                                   }
                                   else
                                   {
                                          susp_damping = wheel_info.m_wheelsDampingRelaxation;
                                   }
                                   force -= susp_damping * projected_rel_vel;
                            }
                     }

                     // RESULT
                     wheel_info.m_wheelsSuspensionForce = force * chassisMass;
                     if (wheel_info.m_wheelsSuspensionForce < btScalar(0.))
                     {
                            wheel_info.m_wheelsSuspensionForce = btScalar(0.);
                     }
              }
              else
              {
                     wheel_info.m_wheelsSuspensionForce = btScalar(0.0);
              }
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

void btRaycastVehicle::updateVehicle ( btScalar  step) [virtual]

Definition at line 261 of file btRaycastVehicle.cpp.

{
       {
              for (int i=0;i<getNumWheels();i++)
              {
                     updateWheelTransform(i,false);
              }
       }


       m_currentVehicleSpeedKmHour = btScalar(3.6) * getRigidBody()->getLinearVelocity().length();
       
       const btTransform& chassisTrans = getChassisWorldTransform();

       btVector3 forwardW (
              chassisTrans.getBasis()[0][m_indexForwardAxis],
              chassisTrans.getBasis()[1][m_indexForwardAxis],
              chassisTrans.getBasis()[2][m_indexForwardAxis]);

       if (forwardW.dot(getRigidBody()->getLinearVelocity()) < btScalar(0.))
       {
              m_currentVehicleSpeedKmHour *= btScalar(-1.);
       }

       //
       // simulate suspension
       //
       
       int i=0;
       for (i=0;i<m_wheelInfo.size();i++)
       {
              btScalar depth; 
              depth = rayCast( m_wheelInfo[i]);
       }

       updateSuspension(step);

       
       for (i=0;i<m_wheelInfo.size();i++)
       {
              //apply suspension force
              btWheelInfo& wheel = m_wheelInfo[i];
              
              btScalar suspensionForce = wheel.m_wheelsSuspensionForce;
              
              btScalar gMaxSuspensionForce = btScalar(6000.);
              if (suspensionForce > gMaxSuspensionForce)
              {
                     suspensionForce = gMaxSuspensionForce;
              }
              btVector3 impulse = wheel.m_raycastInfo.m_contactNormalWS * suspensionForce * step;
              btVector3 relpos = wheel.m_raycastInfo.m_contactPointWS - getRigidBody()->getCenterOfMassPosition();
              
              getRigidBody()->applyImpulse(impulse, relpos);
       
       }
       

       
       updateFriction( step);

       
       for (i=0;i<m_wheelInfo.size();i++)
       {
              btWheelInfo& wheel = m_wheelInfo[i];
              btVector3 relpos = wheel.m_raycastInfo.m_hardPointWS - getRigidBody()->getCenterOfMassPosition();
              btVector3 vel = getRigidBody()->getVelocityInLocalPoint( relpos );

              if (wheel.m_raycastInfo.m_isInContact)
              {
                     const btTransform&   chassisWorldTransform = getChassisWorldTransform();

                     btVector3 fwd (
                            chassisWorldTransform.getBasis()[0][m_indexForwardAxis],
                            chassisWorldTransform.getBasis()[1][m_indexForwardAxis],
                            chassisWorldTransform.getBasis()[2][m_indexForwardAxis]);

                     btScalar proj = fwd.dot(wheel.m_raycastInfo.m_contactNormalWS);
                     fwd -= wheel.m_raycastInfo.m_contactNormalWS * proj;

                     btScalar proj2 = fwd.dot(vel);
                     
                     wheel.m_deltaRotation = (proj2 * step) / (wheel.m_wheelsRadius);
                     wheel.m_rotation += wheel.m_deltaRotation;

              } else
              {
                     wheel.m_rotation += wheel.m_deltaRotation;
              }
              
              wheel.m_deltaRotation *= btScalar(0.99);//damping of rotation when not in contact

       }



}

Here is the call graph for this function:

Here is the caller graph for this function:

void btRaycastVehicle::updateWheelTransform ( int  wheelIndex,
bool  interpolatedTransform = true 
)

Definition at line 96 of file btRaycastVehicle.cpp.

{
       
       btWheelInfo& wheel = m_wheelInfo[ wheelIndex ];
       updateWheelTransformsWS(wheel,interpolatedTransform);
       btVector3 up = -wheel.m_raycastInfo.m_wheelDirectionWS;
       const btVector3& right = wheel.m_raycastInfo.m_wheelAxleWS;
       btVector3 fwd = up.cross(right);
       fwd = fwd.normalize();
//     up = right.cross(fwd);
//     up.normalize();

       //rotate around steering over de wheelAxleWS
       btScalar steering = wheel.m_steering;
       
       btQuaternion steeringOrn(up,steering);//wheel.m_steering);
       btMatrix3x3 steeringMat(steeringOrn);

       btQuaternion rotatingOrn(right,-wheel.m_rotation);
       btMatrix3x3 rotatingMat(rotatingOrn);

       btMatrix3x3 basis2(
              right[0],fwd[0],up[0],
              right[1],fwd[1],up[1],
              right[2],fwd[2],up[2]
       );
       
       wheel.m_worldTransform.setBasis(steeringMat * rotatingMat * basis2);
       wheel.m_worldTransform.setOrigin(
              wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength
       );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void btRaycastVehicle::updateWheelTransformsWS ( btWheelInfo wheel,
bool  interpolatedTransform = true 
)

Definition at line 145 of file btRaycastVehicle.cpp.

{
       wheel.m_raycastInfo.m_isInContact = false;

       btTransform chassisTrans = getChassisWorldTransform();
       if (interpolatedTransform && (getRigidBody()->getMotionState()))
       {
              getRigidBody()->getMotionState()->getWorldTransform(chassisTrans);
       }

       wheel.m_raycastInfo.m_hardPointWS = chassisTrans( wheel.m_chassisConnectionPointCS );
       wheel.m_raycastInfo.m_wheelDirectionWS = chassisTrans.getBasis() *  wheel.m_wheelDirectionCS ;
       wheel.m_raycastInfo.m_wheelAxleWS = chassisTrans.getBasis() * wheel.m_wheelAxleCS;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 50 of file btTypedConstraint.h.

Definition at line 28 of file btRaycastVehicle.h.

Definition at line 61 of file btRaycastVehicle.h.

Definition at line 59 of file btRaycastVehicle.h.

Definition at line 55 of file btRaycastVehicle.h.

Definition at line 29 of file btRaycastVehicle.h.

Definition at line 27 of file btRaycastVehicle.h.

Definition at line 65 of file btRaycastVehicle.h.

Definition at line 63 of file btRaycastVehicle.h.

Definition at line 64 of file btRaycastVehicle.h.

Definition at line 57 of file btRaycastVehicle.h.

btRigidBody& btTypedConstraint::m_rbA [protected, inherited]

Definition at line 48 of file btTypedConstraint.h.

btRigidBody& btTypedConstraint::m_rbB [protected, inherited]

Definition at line 49 of file btTypedConstraint.h.

Definition at line 30 of file btRaycastVehicle.h.

Definition at line 58 of file btRaycastVehicle.h.

Definition at line 54 of file btRaycastVehicle.h.

Definition at line 56 of file btRaycastVehicle.h.

Definition at line 104 of file btRaycastVehicle.h.


The documentation for this class was generated from the following files: