Bullet Collision Detection & Physics Library: btWheelInfo.cpp Source File

Bullet Collision Detection & Physics Library

btWheelInfo.cpp
Go to the documentation of this file.
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
14 btScalar btWheelInfo::getSuspensionRestLength() const
15 {
16 return m_suspensionRestLength1;
17 }
18
19 void btWheelInfo::updateWheel(const btRigidBody& chassis, RaycastInfo& raycastInfo)
20 {
21 (void)raycastInfo;
22
23 if (m_raycastInfo.m_isInContact)
24
25 {
26 btScalar project = m_raycastInfo.m_contactNormalWS.dot(m_raycastInfo.m_wheelDirectionWS);
27 btVector3 chassis_velocity_at_contactPoint;
28 btVector3 relpos = m_raycastInfo.m_contactPointWS - chassis.getCenterOfMassPosition();
29 chassis_velocity_at_contactPoint = chassis.getVelocityInLocalPoint(relpos);
30 btScalar projVel = m_raycastInfo.m_contactNormalWS.dot(chassis_velocity_at_contactPoint);
31 if (project >= btScalar(-0.1))
32 {
33 m_suspensionRelativeVelocity = btScalar(0.0);
34 m_clippedInvContactDotSuspension = btScalar(1.0) / btScalar(0.1);
35 }
36 else
37 {
38 btScalar inv = btScalar(-1.) / project;
39 m_suspensionRelativeVelocity = projVel * inv;
40 m_clippedInvContactDotSuspension = inv;
41 }
42 }
43
44 else // Not in contact : position wheel in a nice (rest length) position
45 {
46 m_raycastInfo.m_suspensionLength = this->getSuspensionRestLength();
47 m_suspensionRelativeVelocity = btScalar(0.0);
48 m_raycastInfo.m_contactNormalWS = -m_raycastInfo.m_wheelDirectionWS;
49 m_clippedInvContactDotSuspension = btScalar(1.0);
50 }
51 }
btWheelInfo.h
btWheelInfo::RaycastInfo::m_suspensionLength
btScalar m_suspensionLength
Definition: btWheelInfo.h:44
btRigidBody
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:60
btWheelInfo::m_suspensionRelativeVelocity
btScalar m_suspensionRelativeVelocity
Definition: btWheelInfo.h:110
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btVector3::dot
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition: btVector3.h:229
btRigidBody.h
btWheelInfo::updateWheel
void updateWheel(const btRigidBody &chassis, RaycastInfo &raycastInfo)
Definition: btWheelInfo.cpp:19
btWheelInfo::RaycastInfo::m_contactNormalWS
btVector3 m_contactNormalWS
Definition: btWheelInfo.h:42
btWheelInfo::getSuspensionRestLength
btScalar getSuspensionRestLength() const
Definition: btWheelInfo.cpp:14
btWheelInfo::RaycastInfo
Definition: btWheelInfo.h:40
btWheelInfo::m_suspensionRestLength1
btScalar m_suspensionRestLength1
Definition: btWheelInfo.h:59
btWheelInfo::RaycastInfo::m_wheelDirectionWS
btVector3 m_wheelDirectionWS
Definition: btWheelInfo.h:46
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btRigidBody::getVelocityInLocalPoint
btVector3 getVelocityInLocalPoint(const btVector3 &rel_pos) const
Definition: btRigidBody.h:460
btWheelInfo::RaycastInfo::m_contactPointWS
btVector3 m_contactPointWS
Definition: btWheelInfo.h:43
btRigidBody::getCenterOfMassPosition
const btVector3 & getCenterOfMassPosition() const
Definition: btRigidBody.h:423
btWheelInfo::m_clippedInvContactDotSuspension
btScalar m_clippedInvContactDotSuspension
Definition: btWheelInfo.h:109
btWheelInfo::m_raycastInfo
RaycastInfo m_raycastInfo
Definition: btWheelInfo.h:52
btWheelInfo::RaycastInfo::m_isInContact
bool m_isInContact
Definition: btWheelInfo.h:48