btWheelInfo.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/
00003  *
00004  * Permission to use, copy, modify, distribute and sell this software
00005  * and its documentation for any purpose is hereby granted without fee,
00006  * provided that the above copyright notice appear in all copies.
00007  * Erwin Coumans makes no representations about the suitability 
00008  * of this software for any purpose.  
00009  * It is provided "as is" without express or implied warranty.
00010 */
00011 #include "btWheelInfo.h"
00012 #include "BulletDynamics/Dynamics/btRigidBody.h" // for pointvelocity
00013 
00014 
00015 btScalar btWheelInfo::getSuspensionRestLength() const
00016 {
00017 
00018         return m_suspensionRestLength1;
00019 
00020 }
00021 
00022 void    btWheelInfo::updateWheel(const btRigidBody& chassis,RaycastInfo& raycastInfo)
00023 {
00024         (void)raycastInfo;
00025 
00026         
00027         if (m_raycastInfo.m_isInContact)
00028 
00029         {
00030                 btScalar        project= m_raycastInfo.m_contactNormalWS.dot( m_raycastInfo.m_wheelDirectionWS );
00031                 btVector3        chassis_velocity_at_contactPoint;
00032                 btVector3 relpos = m_raycastInfo.m_contactPointWS - chassis.getCenterOfMassPosition();
00033                 chassis_velocity_at_contactPoint = chassis.getVelocityInLocalPoint( relpos );
00034                 btScalar projVel = m_raycastInfo.m_contactNormalWS.dot( chassis_velocity_at_contactPoint );
00035                 if ( project >= btScalar(-0.1))
00036                 {
00037                         m_suspensionRelativeVelocity = btScalar(0.0);
00038                         m_clippedInvContactDotSuspension = btScalar(1.0) / btScalar(0.1);
00039                 }
00040                 else
00041                 {
00042                         btScalar inv = btScalar(-1.) / project;
00043                         m_suspensionRelativeVelocity = projVel * inv;
00044                         m_clippedInvContactDotSuspension = inv;
00045                 }
00046                 
00047         }
00048 
00049         else    // Not in contact : position wheel in a nice (rest length) position
00050         {
00051                 m_raycastInfo.m_suspensionLength = this->getSuspensionRestLength();
00052                 m_suspensionRelativeVelocity = btScalar(0.0);
00053                 m_raycastInfo.m_contactNormalWS = -m_raycastInfo.m_wheelDirectionWS;
00054                 m_clippedInvContactDotSuspension = btScalar(1.0);
00055         }
00056 }