btWheelInfo.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/
  3. *
  4. * Permission to use, copy, modify, distribute and sell this software
  5. * and its documentation for any purpose is hereby granted without fee,
  6. * provided that the above copyright notice appear in all copies.
  7. * Erwin Coumans makes no representations about the suitability
  8. * of this software for any purpose.
  9. * It is provided "as is" without express or implied warranty.
  10. */
  11. #include "btWheelInfo.h"
  12. #include "BulletDynamics/Dynamics/btRigidBody.h" // for pointvelocity
  13. btScalar btWheelInfo::getSuspensionRestLength() const
  14. {
  15. return m_suspensionRestLength1;
  16. }
  17. void btWheelInfo::updateWheel(const btRigidBody& chassis, RaycastInfo& raycastInfo)
  18. {
  19. (void)raycastInfo;
  20. if (m_raycastInfo.m_isInContact)
  21. {
  22. btScalar project = m_raycastInfo.m_contactNormalWS.dot(m_raycastInfo.m_wheelDirectionWS);
  23. btVector3 chassis_velocity_at_contactPoint;
  24. btVector3 relpos = m_raycastInfo.m_contactPointWS - chassis.getCenterOfMassPosition();
  25. chassis_velocity_at_contactPoint = chassis.getVelocityInLocalPoint(relpos);
  26. btScalar projVel = m_raycastInfo.m_contactNormalWS.dot(chassis_velocity_at_contactPoint);
  27. if (project >= btScalar(-0.1))
  28. {
  29. m_suspensionRelativeVelocity = btScalar(0.0);
  30. m_clippedInvContactDotSuspension = btScalar(1.0) / btScalar(0.1);
  31. }
  32. else
  33. {
  34. btScalar inv = btScalar(-1.) / project;
  35. m_suspensionRelativeVelocity = projVel * inv;
  36. m_clippedInvContactDotSuspension = inv;
  37. }
  38. }
  39. else // Not in contact : position wheel in a nice (rest length) position
  40. {
  41. m_raycastInfo.m_suspensionLength = this->getSuspensionRestLength();
  42. m_suspensionRelativeVelocity = btScalar(0.0);
  43. m_raycastInfo.m_contactNormalWS = -m_raycastInfo.m_wheelDirectionWS;
  44. m_clippedInvContactDotSuspension = btScalar(1.0);
  45. }
  46. }