Bullet Collision Detection & Physics Library
btRigidBody.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef BT_RIGIDBODY_H
17#define BT_RIGIDBODY_H
18
23
25class btMotionState;
27
29extern bool gDisableDeactivation;
30
31#ifdef BT_USE_DOUBLE_PRECISION
32#define btRigidBodyData btRigidBodyDoubleData
33#define btRigidBodyDataName "btRigidBodyDoubleData"
34#else
35#define btRigidBodyData btRigidBodyFloatData
36#define btRigidBodyDataName "btRigidBodyFloatData"
37#endif //BT_USE_DOUBLE_PRECISION
38
40{
49};
50
60{
66
72
75
81
84
85 //m_optionalMotionState allows to automatic synchronize the world transform for active objects
87
88 //keep track of typed constraints referencing this rigid body, to disable collision between linked bodies
90
92
94
95protected:
102
103public:
110 {
112
117
122
128 btScalar m_spinningFriction; //torsional friction around contact normal
129
132
135
136 //Additional damping can help avoiding lowpass jitter motion, help stability for ragdolls etc.
137 //Such damping is undesirable, so once the overall simulation quality of the rigid body dynamics system has improved, this should become obsolete
143
150 m_friction(btScalar(0.5)),
161 {
163 }
164 };
165
167 btRigidBody(const btRigidBodyConstructionInfo& constructionInfo);
168
172
173 virtual ~btRigidBody()
174 {
175 //No constraints should point to this rigidbody
176 //Remove constraints from the dynamics world before you delete the related rigidbodies.
178 }
179
180protected:
182 void setupRigidBody(const btRigidBodyConstructionInfo& constructionInfo);
183
184public:
186
190 {
191 if (colObj->getInternalType() & btCollisionObject::CO_RIGID_BODY)
192 return (const btRigidBody*)colObj;
193 return 0;
194 }
196 {
197 if (colObj->getInternalType() & btCollisionObject::CO_RIGID_BODY)
198 return (btRigidBody*)colObj;
199 return 0;
200 }
201
204
206
207 void applyGravity();
208
209 void clearGravity();
210
211 void setGravity(const btVector3& acceleration);
212
213 const btVector3& getGravity() const
214 {
216 }
217
219
221 {
222 return m_linearDamping;
223 }
224
226 {
227 return m_angularDamping;
228 }
229
231 {
233 }
234
236 {
238 }
239
240 void applyDamping(btScalar timeStep);
241
243 {
244 return m_collisionShape;
245 }
246
248 {
249 return m_collisionShape;
250 }
251
253
255 {
256 return m_linearFactor;
257 }
259 {
262 }
264 btScalar getMass() const { return m_inverseMass == btScalar(0.) ? btScalar(0.) : btScalar(1.0) / m_inverseMass; }
266 {
268 }
269
271
272 void setCenterOfMassTransform(const btTransform& xform);
273
275 {
277 }
278
280 {
281 return m_totalForce;
282 };
283
285 {
286 return m_totalTorque;
287 };
288
290 {
291 return m_invInertiaLocal;
292 };
293
295 {
297 }
298
300 {
303 }
304
306 {
308 #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
310 #endif
311 }
312
314 {
317 }
318
320 {
322 #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
324 #endif
325 }
326
328 {
330 #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
332 #endif
333 }
334
336 {
337 if (m_inverseMass != btScalar(0.))
338 {
340 if (m_angularFactor)
341 {
343 }
344 }
345 }
346
348 {
349 if (m_inverseMass != btScalar(0.))
350 {
352 if (m_angularFactor)
353 {
355 }
356 }
357 }
358
360 {
361 return m_pushVelocity;
362 }
363
365 {
366 return m_turnVelocity;
367 }
368
370 {
371 m_pushVelocity = v;
372 }
373
374 #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
375 void clampVelocity(btVector3& v) const {
376 v.setX(
379 );
380 v.setY(
383 );
384 v.setZ(
387 );
388 }
389 #endif
390
392 {
393 m_turnVelocity = v;
394 #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
396 #endif
397 }
398
400 {
402 #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
404 #endif
405 }
406
408 {
410 #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
412 #endif
413 }
414
416 {
419 }
420
421 void updateInertiaTensor();
422
424 {
426 }
428
430 {
431 return m_worldTransform;
432 }
434 {
435 return m_linearVelocity;
436 }
438 {
439 return m_angularVelocity;
440 }
441
443 {
446 #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
448 #endif
449 }
450
452 {
455 #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
457 #endif
458 }
459
461 {
462 //we also calculate lin/ang velocity for kinematic objects
464
465 //for kinematic objects, we could also use use:
466 // return (m_worldTransform(rel_pos) - m_interpolationWorldTransform(rel_pos)) / m_kinematicTimeStep;
467 }
468
470 {
471 //we also calculate lin/ang velocity for kinematic objects
473 }
474
475 void translate(const btVector3& v)
476 {
478 }
479
481
483 {
485
486 btVector3 c0 = (r0).cross(normal);
487
489
490 return m_inverseMass + normal.dot(vec);
491 }
492
494 {
496 return axis.dot(vec);
497 }
498
500 {
502 return;
503
506 {
507 m_deactivationTime += timeStep;
508 }
509 else
510 {
513 }
514 }
515
517 {
519 return false;
520
521 //disable deactivation
523 return false;
524
526 return true;
527
529 {
530 return true;
531 }
532 return false;
533 }
534
536 {
537 return m_broadphaseHandle;
538 }
540 {
541 return m_broadphaseHandle;
542 }
544 {
546 }
547
548 //btMotionState allows to automatic synchronize the world transform for active objects
550 {
552 }
554 {
556 }
558 {
562 }
563
564 //for experimental overriding of friction/contact solver func
567
569 {
572 }
573
575 {
578 }
580 {
581 return m_angularFactor;
582 }
583
584 //is this rigidbody added to a btCollisionWorld/btDynamicsWorld/btBroadphase?
585 bool isInWorld() const
586 {
587 return (getBroadphaseProxy() != 0);
588 }
589
592
594 {
595 return m_constraintRefs[index];
596 }
597
599 {
600 return m_constraintRefs.size();
601 }
602
603 void setFlags(int flags)
604 {
606 }
607
608 int getFlags() const
609 {
610 return m_rigidbodyFlags;
611 }
612
615
618
622
624
625 virtual int calculateSerializeBufferSize() const;
626
628 virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
629
630 virtual void serializeSingleObject(class btSerializer* serializer) const;
631};
632
633//@todo add m_optionalMotionState and m_constraintRefs to btRigidBodyData
636{
658};
659
662{
684 char m_padding[4];
685};
686
687#endif //BT_RIGIDBODY_H
#define DISABLE_DEACTIVATION
#define WANTS_DEACTIVATION
#define ISLAND_SLEEPING
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:27
bool gDisableDeactivation
btScalar gDeactivationTime
btRigidBodyFlags
Definition btRigidBody.h:40
@ BT_ENABLE_GYROPSCOPIC_FORCE
Definition btRigidBody.h:48
@ BT_DISABLE_WORLD_GRAVITY
Definition btRigidBody.h:41
@ BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_BODY
Definition btRigidBody.h:47
@ BT_ENABLE_GYROSCOPIC_FORCE_EXPLICIT
BT_ENABLE_GYROPSCOPIC_FORCE flags is enabled by default in Bullet 2.83 and onwards.
Definition btRigidBody.h:45
@ BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_WORLD
Definition btRigidBody.h:46
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define ATTRIBUTE_ALIGNED16(a)
Definition btScalar.h:99
#define SIMD_FORCE_INLINE
Definition btScalar.h:98
#define btAssert(x)
Definition btScalar.h:153
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
int size() const
return the number of elements in the array
btCollisionObject can be used to manage collision detection objects.
int m_updateRevision
internal update revision number. It will be increased when the object changes. This allows some subsy...
btTransform m_worldTransform
btCollisionShape * m_collisionShape
void setActivationState(int newState) const
btBroadphaseProxy * m_broadphaseHandle
int getActivationState() const
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition btMatrix3x3.h:50
The btMotionState interface class allows the dynamics world to synchronize and interpolate the update...
virtual void getWorldTransform(btTransform &worldTrans) const =0
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
The btRigidBody is the main class for rigid body objects.
Definition btRigidBody.h:60
void applyTorqueImpulse(const btVector3 &torque)
void setLinearFactor(const btVector3 &linearFactor)
void getAabb(btVector3 &aabbMin, btVector3 &aabbMax) const
btScalar computeAngularImpulseDenominator(const btVector3 &axis) const
btScalar m_additionalAngularDampingFactor
Definition btRigidBody.h:80
void applyGravity()
bool wantsSleeping()
void integrateVelocities(btScalar step)
btVector3 getVelocityInLocalPoint(const btVector3 &rel_pos) const
void addConstraintRef(btTypedConstraint *c)
virtual void serializeSingleObject(class btSerializer *serializer) const
void clearForces()
void setNewBroadphaseProxy(btBroadphaseProxy *broadphaseProxy)
btScalar m_linearDamping
Definition btRigidBody.h:73
const btVector3 & getTotalTorque() const
void setFlags(int flags)
int getFlags() const
const btVector3 & getGravity() const
btMatrix3x3 m_invInertiaTensorWorld
Definition btRigidBody.h:61
int m_frictionSolverType
btVector3 m_invInertiaLocal
Definition btRigidBody.h:69
btCollisionShape * getCollisionShape()
btScalar getLinearSleepingThreshold() const
void applyDamping(btScalar timeStep)
applyDamping damps the velocity, using the given m_linearDamping and m_angularDamping
btMotionState * m_optionalMotionState
Definition btRigidBody.h:86
btVector3 m_gravity
Definition btRigidBody.h:67
int m_contactSolverType
void applyCentralForce(const btVector3 &force)
btScalar getInvMass() const
btScalar getAngularDamping() const
virtual const char * serialize(void *dataBuffer, class btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
btVector3 m_turnVelocity
void updateDeactivation(btScalar timeStep)
btScalar m_additionalDampingFactor
Definition btRigidBody.h:77
virtual int calculateSerializeBufferSize() const
int m_rigidbodyFlags
Definition btRigidBody.h:91
btScalar m_additionalAngularDampingThresholdSqr
Definition btRigidBody.h:79
void setGravity(const btVector3 &acceleration)
const btVector3 & getLinearFactor() const
btScalar getMass() const
const btVector3 & getInvInertiaDiagLocal() const
btScalar m_linearSleepingThreshold
Definition btRigidBody.h:82
btQuaternion getOrientation() const
void proceedToTransform(const btTransform &newTrans)
const btTransform & getCenterOfMassTransform() const
const btCollisionShape * getCollisionShape() const
btVector3 m_linearFactor
Definition btRigidBody.h:65
void saveKinematicState(btScalar step)
btVector3 getLocalInertia() const
btVector3 computeGyroscopicImpulseImplicit_World(btScalar dt) const
perform implicit force computation in world space
btVector3 m_angularFactor
Definition btRigidBody.h:98
btVector3 m_totalForce
Definition btRigidBody.h:70
btScalar m_inverseMass
Definition btRigidBody.h:64
btVector3 computeGyroscopicImpulseImplicit_Body(btScalar step) const
perform implicit force computation in body space (inertial frame)
void applyImpulse(const btVector3 &impulse, const btVector3 &rel_pos)
void applyCentralImpulse(const btVector3 &impulse)
btVector3 m_totalTorque
Definition btRigidBody.h:71
const btVector3 & getAngularVelocity() const
const btMotionState * getMotionState() const
btMotionState * getMotionState()
void setTurnVelocity(const btVector3 &v)
btScalar m_angularDamping
Definition btRigidBody.h:74
int getNumConstraintRefs() const
static btRigidBody * upcast(btCollisionObject *colObj)
void removeConstraintRef(btTypedConstraint *c)
btVector3 getPushVelocityInLocalPoint(const btVector3 &rel_pos) const
void setSleepingThresholds(btScalar linear, btScalar angular)
void setMassProps(btScalar mass, const btVector3 &inertia)
const btVector3 & getCenterOfMassPosition() const
btVector3 m_deltaAngularVelocity
Definition btRigidBody.h:97
btVector3 m_pushVelocity
btScalar getAngularSleepingThreshold() const
bool m_additionalDamping
Definition btRigidBody.h:76
int m_debugBodyId
Definition btRigidBody.h:93
void setAngularFactor(const btVector3 &angFac)
void applyTorqueTurnImpulse(const btVector3 &torque)
btBroadphaseProxy * getBroadphaseProxy()
bool isInWorld() const
btScalar m_angularSleepingThreshold
Definition btRigidBody.h:83
const btVector3 & getTotalForce() const
virtual ~btRigidBody()
btScalar getLinearDamping() const
void clearGravity()
const btVector3 & getAngularFactor() const
btScalar m_additionalLinearDampingThresholdSqr
Definition btRigidBody.h:78
btVector3 m_linearVelocity
Definition btRigidBody.h:62
btTypedConstraint * getConstraintRef(int index)
void setInvInertiaDiagLocal(const btVector3 &diagInvInertia)
void setAngularVelocity(const btVector3 &ang_vel)
void setMotionState(btMotionState *motionState)
void translate(const btVector3 &v)
void setPushVelocity(const btVector3 &v)
void applyCentralPushImpulse(const btVector3 &impulse)
void setDamping(btScalar lin_damping, btScalar ang_damping)
btVector3 m_deltaLinearVelocity
Definition btRigidBody.h:96
void setAngularFactor(btScalar angFac)
btVector3 m_angularVelocity
Definition btRigidBody.h:63
void setLinearVelocity(const btVector3 &lin_vel)
void applyPushImpulse(const btVector3 &impulse, const btVector3 &rel_pos)
void setupRigidBody(const btRigidBodyConstructionInfo &constructionInfo)
setupRigidBody is only used internally by the constructor
const btBroadphaseProxy * getBroadphaseProxy() const
void setCenterOfMassTransform(const btTransform &xform)
btScalar computeImpulseDenominator(const btVector3 &pos, const btVector3 &normal) const
static const btRigidBody * upcast(const btCollisionObject *colObj)
to keep collision detection and dynamics separate we don't store a rigidbody pointer but a rigidbody ...
btAlignedObjectArray< btTypedConstraint * > m_constraintRefs
Definition btRigidBody.h:89
void updateInertiaTensor()
void applyTorque(const btVector3 &torque)
void applyForce(const btVector3 &force, const btVector3 &rel_pos)
btVector3 getPushVelocity() const
btVector3 getTurnVelocity() const
const btMatrix3x3 & getInvInertiaTensorWorld() const
void predictIntegratedTransform(btScalar step, btTransform &predictedTransform)
continuous collision detection needs prediction
btVector3 computeGyroscopicForceExplicit(btScalar maxGyroscopicForce) const
explicit version is best avoided, it gains energy
btVector3 m_invMass
Definition btRigidBody.h:99
const btVector3 & getLinearVelocity() const
btVector3 m_gravity_acceleration
Definition btRigidBody.h:68
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:30
void setIdentity()
Set this transformation to the identity.
btVector3 & getOrigin()
Return the origin vector translation.
TypedConstraint is the baseclass for Bullet constraints and vehicles.
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
const btScalar & getZ() const
Return the z value.
Definition btVector3.h:565
void setZ(btScalar _z)
Set the z value.
Definition btVector3.h:571
btVector3 cross(const btVector3 &v) const
Return the cross product between this and another vector.
Definition btVector3.h:380
btScalar dot(const btVector3 &v) const
Return the dot product.
Definition btVector3.h:229
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition btVector3.h:640
void setY(btScalar _y)
Set the y value.
Definition btVector3.h:569
void setX(btScalar _x)
Set the x value.
Definition btVector3.h:567
const btScalar & getY() const
Return the y value.
Definition btVector3.h:563
const btScalar & getX() const
Return the x value.
Definition btVector3.h:561
The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
for serialization
for serialization
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btVector3DoubleData m_angularVelocity
btCollisionObjectDoubleData m_collisionObjectData
btVector3DoubleData m_totalForce
btVector3DoubleData m_linearFactor
btVector3DoubleData m_invInertiaLocal
btVector3DoubleData m_totalTorque
double m_additionalLinearDampingThresholdSqr
btVector3DoubleData m_angularFactor
btMatrix3x3DoubleData m_invInertiaTensorWorld
double m_angularSleepingThreshold
btVector3DoubleData m_linearVelocity
double m_additionalAngularDampingThresholdSqr
btVector3DoubleData m_gravity
double m_additionalAngularDampingFactor
btVector3DoubleData m_gravity_acceleration
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btVector3FloatData m_totalTorque
btVector3FloatData m_linearFactor
btVector3FloatData m_totalForce
btVector3FloatData m_angularVelocity
btVector3FloatData m_angularFactor
btVector3FloatData m_invInertiaLocal
btMatrix3x3FloatData m_invInertiaTensorWorld
float m_additionalLinearDampingThresholdSqr
float m_additionalAngularDampingFactor
btCollisionObjectFloatData m_collisionObjectData
btVector3FloatData m_linearVelocity
btVector3FloatData m_gravity
btVector3FloatData m_gravity_acceleration
float m_additionalAngularDampingThresholdSqr
The btRigidBodyConstructionInfo structure provides information to create a rigid body.
btScalar m_friction
best simulation results when friction is non-zero
btRigidBodyConstructionInfo(btScalar mass, btMotionState *motionState, btCollisionShape *collisionShape, const btVector3 &localInertia=btVector3(0, 0, 0))
btScalar m_restitution
best simulation results using zero restitution.
btMotionState * m_motionState
When a motionState is provided, the rigid body will initialize its world transform from the motion st...
btScalar m_rollingFriction
the m_rollingFriction prevents rounded shapes, such as spheres, cylinders and capsules from rolling f...