btRigidBody.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. 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.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef BT_RIGIDBODY_H
  14. #define BT_RIGIDBODY_H
  15. #include "LinearMath/btAlignedObjectArray.h"
  16. #include "LinearMath/btTransform.h"
  17. #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
  18. #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
  19. class btCollisionShape;
  20. class btMotionState;
  21. class btTypedConstraint;
  22. extern btScalar gDeactivationTime;
  23. extern bool gDisableDeactivation;
  24. #ifdef BT_USE_DOUBLE_PRECISION
  25. #define btRigidBodyData btRigidBodyDoubleData
  26. #define btRigidBodyDataName "btRigidBodyDoubleData"
  27. #else
  28. #define btRigidBodyData btRigidBodyFloatData
  29. #define btRigidBodyDataName "btRigidBodyFloatData"
  30. #endif //BT_USE_DOUBLE_PRECISION
  31. enum btRigidBodyFlags
  32. {
  33. BT_DISABLE_WORLD_GRAVITY = 1,
  34. ///BT_ENABLE_GYROPSCOPIC_FORCE flags is enabled by default in Bullet 2.83 and onwards.
  35. ///and it BT_ENABLE_GYROPSCOPIC_FORCE becomes equivalent to BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_BODY
  36. ///See Demos/GyroscopicDemo and computeGyroscopicImpulseImplicit
  37. BT_ENABLE_GYROSCOPIC_FORCE_EXPLICIT = 2,
  38. BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_WORLD = 4,
  39. BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_BODY = 8,
  40. BT_ENABLE_GYROPSCOPIC_FORCE = BT_ENABLE_GYROSCOPIC_FORCE_IMPLICIT_BODY,
  41. };
  42. ///The btRigidBody is the main class for rigid body objects. It is derived from btCollisionObject, so it keeps a pointer to a btCollisionShape.
  43. ///It is recommended for performance and memory use to share btCollisionShape objects whenever possible.
  44. ///There are 3 types of rigid bodies:
  45. ///- A) Dynamic rigid bodies, with positive mass. Motion is controlled by rigid body dynamics.
  46. ///- B) Fixed objects with zero mass. They are not moving (basically collision objects)
  47. ///- C) Kinematic objects, which are objects without mass, but the user can move them. There is one-way interaction, and Bullet calculates a velocity based on the timestep and previous and current world transform.
  48. ///Bullet automatically deactivates dynamic rigid bodies, when the velocity is below a threshold for a given time.
  49. ///Deactivated (sleeping) rigid bodies don't take any processing time, except a minor broadphase collision detection impact (to allow active objects to activate/wake up sleeping objects)
  50. class btRigidBody : public btCollisionObject
  51. {
  52. btMatrix3x3 m_invInertiaTensorWorld;
  53. btVector3 m_linearVelocity;
  54. btVector3 m_angularVelocity;
  55. btScalar m_inverseMass;
  56. btVector3 m_linearFactor;
  57. btVector3 m_gravity;
  58. btVector3 m_gravity_acceleration;
  59. btVector3 m_invInertiaLocal;
  60. btVector3 m_totalForce;
  61. btVector3 m_totalTorque;
  62. btScalar m_linearDamping;
  63. btScalar m_angularDamping;
  64. bool m_additionalDamping;
  65. btScalar m_additionalDampingFactor;
  66. btScalar m_additionalLinearDampingThresholdSqr;
  67. btScalar m_additionalAngularDampingThresholdSqr;
  68. btScalar m_additionalAngularDampingFactor;
  69. btScalar m_linearSleepingThreshold;
  70. btScalar m_angularSleepingThreshold;
  71. //m_optionalMotionState allows to automatic synchronize the world transform for active objects
  72. btMotionState* m_optionalMotionState;
  73. //keep track of typed constraints referencing this rigid body, to disable collision between linked bodies
  74. btAlignedObjectArray<btTypedConstraint*> m_constraintRefs;
  75. int m_rigidbodyFlags;
  76. int m_debugBodyId;
  77. protected:
  78. ATTRIBUTE_ALIGNED16(btVector3 m_deltaLinearVelocity);
  79. btVector3 m_deltaAngularVelocity;
  80. btVector3 m_angularFactor;
  81. btVector3 m_invMass;
  82. btVector3 m_pushVelocity;
  83. btVector3 m_turnVelocity;
  84. public:
  85. ///The btRigidBodyConstructionInfo structure provides information to create a rigid body. Setting mass to zero creates a fixed (non-dynamic) rigid body.
  86. ///For dynamic objects, you can use the collision shape to approximate the local inertia tensor, otherwise use the zero vector (default argument)
  87. ///You can use the motion state to synchronize the world transform between physics and graphics objects.
  88. ///And if the motion state is provided, the rigid body will initialize its initial world transform from the motion state,
  89. ///m_startWorldTransform is only used when you don't provide a motion state.
  90. struct btRigidBodyConstructionInfo
  91. {
  92. btScalar m_mass;
  93. ///When a motionState is provided, the rigid body will initialize its world transform from the motion state
  94. ///In this case, m_startWorldTransform is ignored.
  95. btMotionState* m_motionState;
  96. btTransform m_startWorldTransform;
  97. btCollisionShape* m_collisionShape;
  98. btVector3 m_localInertia;
  99. btScalar m_linearDamping;
  100. btScalar m_angularDamping;
  101. ///best simulation results when friction is non-zero
  102. btScalar m_friction;
  103. ///the m_rollingFriction prevents rounded shapes, such as spheres, cylinders and capsules from rolling forever.
  104. ///See Bullet/Demos/RollingFrictionDemo for usage
  105. btScalar m_rollingFriction;
  106. btScalar m_spinningFriction; //torsional friction around contact normal
  107. ///best simulation results using zero restitution.
  108. btScalar m_restitution;
  109. btScalar m_linearSleepingThreshold;
  110. btScalar m_angularSleepingThreshold;
  111. //Additional damping can help avoiding lowpass jitter motion, help stability for ragdolls etc.
  112. //Such damping is undesirable, so once the overall simulation quality of the rigid body dynamics system has improved, this should become obsolete
  113. bool m_additionalDamping;
  114. btScalar m_additionalDampingFactor;
  115. btScalar m_additionalLinearDampingThresholdSqr;
  116. btScalar m_additionalAngularDampingThresholdSqr;
  117. btScalar m_additionalAngularDampingFactor;
  118. btRigidBodyConstructionInfo(btScalar mass, btMotionState* motionState, btCollisionShape* collisionShape, const btVector3& localInertia = btVector3(0, 0, 0)) : m_mass(mass),
  119. m_motionState(motionState),
  120. m_collisionShape(collisionShape),
  121. m_localInertia(localInertia),
  122. m_linearDamping(btScalar(0.)),
  123. m_angularDamping(btScalar(0.)),
  124. m_friction(btScalar(0.5)),
  125. m_rollingFriction(btScalar(0)),
  126. m_spinningFriction(btScalar(0)),
  127. m_restitution(btScalar(0.)),
  128. m_linearSleepingThreshold(btScalar(0.8)),
  129. m_angularSleepingThreshold(btScalar(1.f)),
  130. m_additionalDamping(false),
  131. m_additionalDampingFactor(btScalar(0.005)),
  132. m_additionalLinearDampingThresholdSqr(btScalar(0.01)),
  133. m_additionalAngularDampingThresholdSqr(btScalar(0.01)),
  134. m_additionalAngularDampingFactor(btScalar(0.01))
  135. {
  136. m_startWorldTransform.setIdentity();
  137. }
  138. };
  139. ///btRigidBody constructor using construction info
  140. btRigidBody(const btRigidBodyConstructionInfo& constructionInfo);
  141. ///btRigidBody constructor for backwards compatibility.
  142. ///To specify friction (etc) during rigid body construction, please use the other constructor (using btRigidBodyConstructionInfo)
  143. btRigidBody(btScalar mass, btMotionState* motionState, btCollisionShape* collisionShape, const btVector3& localInertia = btVector3(0, 0, 0));
  144. virtual ~btRigidBody()
  145. {
  146. //No constraints should point to this rigidbody
  147. //Remove constraints from the dynamics world before you delete the related rigidbodies.
  148. btAssert(m_constraintRefs.size() == 0);
  149. }
  150. protected:
  151. ///setupRigidBody is only used internally by the constructor
  152. void setupRigidBody(const btRigidBodyConstructionInfo& constructionInfo);
  153. public:
  154. void proceedToTransform(const btTransform& newTrans);
  155. ///to keep collision detection and dynamics separate we don't store a rigidbody pointer
  156. ///but a rigidbody is derived from btCollisionObject, so we can safely perform an upcast
  157. static const btRigidBody* upcast(const btCollisionObject* colObj)
  158. {
  159. if (colObj->getInternalType() & btCollisionObject::CO_RIGID_BODY)
  160. return (const btRigidBody*)colObj;
  161. return 0;
  162. }
  163. static btRigidBody* upcast(btCollisionObject* colObj)
  164. {
  165. if (colObj->getInternalType() & btCollisionObject::CO_RIGID_BODY)
  166. return (btRigidBody*)colObj;
  167. return 0;
  168. }
  169. /// continuous collision detection needs prediction
  170. void predictIntegratedTransform(btScalar step, btTransform& predictedTransform);
  171. void saveKinematicState(btScalar step);
  172. void applyGravity();
  173. void clearGravity();
  174. void setGravity(const btVector3& acceleration);
  175. const btVector3& getGravity() const
  176. {
  177. return m_gravity_acceleration;
  178. }
  179. void setDamping(btScalar lin_damping, btScalar ang_damping);
  180. btScalar getLinearDamping() const
  181. {
  182. return m_linearDamping;
  183. }
  184. btScalar getAngularDamping() const
  185. {
  186. return m_angularDamping;
  187. }
  188. btScalar getLinearSleepingThreshold() const
  189. {
  190. return m_linearSleepingThreshold;
  191. }
  192. btScalar getAngularSleepingThreshold() const
  193. {
  194. return m_angularSleepingThreshold;
  195. }
  196. void applyDamping(btScalar timeStep);
  197. SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const
  198. {
  199. return m_collisionShape;
  200. }
  201. SIMD_FORCE_INLINE btCollisionShape* getCollisionShape()
  202. {
  203. return m_collisionShape;
  204. }
  205. void setMassProps(btScalar mass, const btVector3& inertia);
  206. const btVector3& getLinearFactor() const
  207. {
  208. return m_linearFactor;
  209. }
  210. void setLinearFactor(const btVector3& linearFactor)
  211. {
  212. m_linearFactor = linearFactor;
  213. m_invMass = m_linearFactor * m_inverseMass;
  214. }
  215. btScalar getInvMass() const { return m_inverseMass; }
  216. btScalar getMass() const { return m_inverseMass == btScalar(0.) ? btScalar(0.) : btScalar(1.0) / m_inverseMass; }
  217. const btMatrix3x3& getInvInertiaTensorWorld() const
  218. {
  219. return m_invInertiaTensorWorld;
  220. }
  221. void integrateVelocities(btScalar step);
  222. void setCenterOfMassTransform(const btTransform& xform);
  223. void applyCentralForce(const btVector3& force)
  224. {
  225. m_totalForce += force * m_linearFactor;
  226. }
  227. const btVector3& getTotalForce() const
  228. {
  229. return m_totalForce;
  230. };
  231. const btVector3& getTotalTorque() const
  232. {
  233. return m_totalTorque;
  234. };
  235. const btVector3& getInvInertiaDiagLocal() const
  236. {
  237. return m_invInertiaLocal;
  238. };
  239. void setInvInertiaDiagLocal(const btVector3& diagInvInertia)
  240. {
  241. m_invInertiaLocal = diagInvInertia;
  242. }
  243. void setSleepingThresholds(btScalar linear, btScalar angular)
  244. {
  245. m_linearSleepingThreshold = linear;
  246. m_angularSleepingThreshold = angular;
  247. }
  248. void applyTorque(const btVector3& torque)
  249. {
  250. m_totalTorque += torque * m_angularFactor;
  251. #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
  252. clampVelocity(m_totalTorque);
  253. #endif
  254. }
  255. void applyForce(const btVector3& force, const btVector3& rel_pos)
  256. {
  257. applyCentralForce(force);
  258. applyTorque(rel_pos.cross(force * m_linearFactor));
  259. }
  260. void applyCentralImpulse(const btVector3& impulse)
  261. {
  262. m_linearVelocity += impulse * m_linearFactor * m_inverseMass;
  263. #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
  264. clampVelocity(m_linearVelocity);
  265. #endif
  266. }
  267. void applyTorqueImpulse(const btVector3& torque)
  268. {
  269. m_angularVelocity += m_invInertiaTensorWorld * torque * m_angularFactor;
  270. #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
  271. clampVelocity(m_angularVelocity);
  272. #endif
  273. }
  274. void applyImpulse(const btVector3& impulse, const btVector3& rel_pos)
  275. {
  276. if (m_inverseMass != btScalar(0.))
  277. {
  278. applyCentralImpulse(impulse);
  279. if (m_angularFactor)
  280. {
  281. applyTorqueImpulse(rel_pos.cross(impulse * m_linearFactor));
  282. }
  283. }
  284. }
  285. void applyPushImpulse(const btVector3& impulse, const btVector3& rel_pos)
  286. {
  287. if (m_inverseMass != btScalar(0.))
  288. {
  289. applyCentralPushImpulse(impulse);
  290. if (m_angularFactor)
  291. {
  292. applyTorqueTurnImpulse(rel_pos.cross(impulse * m_linearFactor));
  293. }
  294. }
  295. }
  296. btVector3 getPushVelocity() const
  297. {
  298. return m_pushVelocity;
  299. }
  300. btVector3 getTurnVelocity() const
  301. {
  302. return m_turnVelocity;
  303. }
  304. void setPushVelocity(const btVector3& v)
  305. {
  306. m_pushVelocity = v;
  307. }
  308. #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
  309. void clampVelocity(btVector3& v) const {
  310. v.setX(
  311. fmax(-BT_CLAMP_VELOCITY_TO,
  312. fmin(BT_CLAMP_VELOCITY_TO, v.getX()))
  313. );
  314. v.setY(
  315. fmax(-BT_CLAMP_VELOCITY_TO,
  316. fmin(BT_CLAMP_VELOCITY_TO, v.getY()))
  317. );
  318. v.setZ(
  319. fmax(-BT_CLAMP_VELOCITY_TO,
  320. fmin(BT_CLAMP_VELOCITY_TO, v.getZ()))
  321. );
  322. }
  323. #endif
  324. void setTurnVelocity(const btVector3& v)
  325. {
  326. m_turnVelocity = v;
  327. #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
  328. clampVelocity(m_turnVelocity);
  329. #endif
  330. }
  331. void applyCentralPushImpulse(const btVector3& impulse)
  332. {
  333. m_pushVelocity += impulse * m_linearFactor * m_inverseMass;
  334. #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
  335. clampVelocity(m_pushVelocity);
  336. #endif
  337. }
  338. void applyTorqueTurnImpulse(const btVector3& torque)
  339. {
  340. m_turnVelocity += m_invInertiaTensorWorld * torque * m_angularFactor;
  341. #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
  342. clampVelocity(m_turnVelocity);
  343. #endif
  344. }
  345. void clearForces()
  346. {
  347. m_totalForce.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0));
  348. m_totalTorque.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0));
  349. }
  350. void updateInertiaTensor();
  351. const btVector3& getCenterOfMassPosition() const
  352. {
  353. return m_worldTransform.getOrigin();
  354. }
  355. btQuaternion getOrientation() const;
  356. const btTransform& getCenterOfMassTransform() const
  357. {
  358. return m_worldTransform;
  359. }
  360. const btVector3& getLinearVelocity() const
  361. {
  362. return m_linearVelocity;
  363. }
  364. const btVector3& getAngularVelocity() const
  365. {
  366. return m_angularVelocity;
  367. }
  368. inline void setLinearVelocity(const btVector3& lin_vel)
  369. {
  370. m_updateRevision++;
  371. m_linearVelocity = lin_vel;
  372. #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
  373. clampVelocity(m_linearVelocity);
  374. #endif
  375. }
  376. inline void setAngularVelocity(const btVector3& ang_vel)
  377. {
  378. m_updateRevision++;
  379. m_angularVelocity = ang_vel;
  380. #if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
  381. clampVelocity(m_angularVelocity);
  382. #endif
  383. }
  384. btVector3 getVelocityInLocalPoint(const btVector3& rel_pos) const
  385. {
  386. //we also calculate lin/ang velocity for kinematic objects
  387. return m_linearVelocity + m_angularVelocity.cross(rel_pos);
  388. //for kinematic objects, we could also use use:
  389. // return (m_worldTransform(rel_pos) - m_interpolationWorldTransform(rel_pos)) / m_kinematicTimeStep;
  390. }
  391. btVector3 getPushVelocityInLocalPoint(const btVector3& rel_pos) const
  392. {
  393. //we also calculate lin/ang velocity for kinematic objects
  394. return m_pushVelocity + m_turnVelocity.cross(rel_pos);
  395. }
  396. void translate(const btVector3& v)
  397. {
  398. m_worldTransform.getOrigin() += v;
  399. }
  400. void getAabb(btVector3& aabbMin, btVector3& aabbMax) const;
  401. SIMD_FORCE_INLINE btScalar computeImpulseDenominator(const btVector3& pos, const btVector3& normal) const
  402. {
  403. btVector3 r0 = pos - getCenterOfMassPosition();
  404. btVector3 c0 = (r0).cross(normal);
  405. btVector3 vec = (c0 * getInvInertiaTensorWorld()).cross(r0);
  406. return m_inverseMass + normal.dot(vec);
  407. }
  408. SIMD_FORCE_INLINE btScalar computeAngularImpulseDenominator(const btVector3& axis) const
  409. {
  410. btVector3 vec = axis * getInvInertiaTensorWorld();
  411. return axis.dot(vec);
  412. }
  413. SIMD_FORCE_INLINE void updateDeactivation(btScalar timeStep)
  414. {
  415. if ((getActivationState() == ISLAND_SLEEPING) || (getActivationState() == DISABLE_DEACTIVATION))
  416. return;
  417. if ((getLinearVelocity().length2() < m_linearSleepingThreshold * m_linearSleepingThreshold) &&
  418. (getAngularVelocity().length2() < m_angularSleepingThreshold * m_angularSleepingThreshold))
  419. {
  420. m_deactivationTime += timeStep;
  421. }
  422. else
  423. {
  424. m_deactivationTime = btScalar(0.);
  425. setActivationState(0);
  426. }
  427. }
  428. SIMD_FORCE_INLINE bool wantsSleeping()
  429. {
  430. if (getActivationState() == DISABLE_DEACTIVATION)
  431. return false;
  432. //disable deactivation
  433. if (gDisableDeactivation || (gDeactivationTime == btScalar(0.)))
  434. return false;
  435. if ((getActivationState() == ISLAND_SLEEPING) || (getActivationState() == WANTS_DEACTIVATION))
  436. return true;
  437. if (m_deactivationTime > gDeactivationTime)
  438. {
  439. return true;
  440. }
  441. return false;
  442. }
  443. const btBroadphaseProxy* getBroadphaseProxy() const
  444. {
  445. return m_broadphaseHandle;
  446. }
  447. btBroadphaseProxy* getBroadphaseProxy()
  448. {
  449. return m_broadphaseHandle;
  450. }
  451. void setNewBroadphaseProxy(btBroadphaseProxy* broadphaseProxy)
  452. {
  453. m_broadphaseHandle = broadphaseProxy;
  454. }
  455. //btMotionState allows to automatic synchronize the world transform for active objects
  456. btMotionState* getMotionState()
  457. {
  458. return m_optionalMotionState;
  459. }
  460. const btMotionState* getMotionState() const
  461. {
  462. return m_optionalMotionState;
  463. }
  464. void setMotionState(btMotionState* motionState)
  465. {
  466. m_optionalMotionState = motionState;
  467. if (m_optionalMotionState)
  468. motionState->getWorldTransform(m_worldTransform);
  469. }
  470. //for experimental overriding of friction/contact solver func
  471. int m_contactSolverType;
  472. int m_frictionSolverType;
  473. void setAngularFactor(const btVector3& angFac)
  474. {
  475. m_updateRevision++;
  476. m_angularFactor = angFac;
  477. }
  478. void setAngularFactor(btScalar angFac)
  479. {
  480. m_updateRevision++;
  481. m_angularFactor.setValue(angFac, angFac, angFac);
  482. }
  483. const btVector3& getAngularFactor() const
  484. {
  485. return m_angularFactor;
  486. }
  487. //is this rigidbody added to a btCollisionWorld/btDynamicsWorld/btBroadphase?
  488. bool isInWorld() const
  489. {
  490. return (getBroadphaseProxy() != 0);
  491. }
  492. void addConstraintRef(btTypedConstraint* c);
  493. void removeConstraintRef(btTypedConstraint* c);
  494. btTypedConstraint* getConstraintRef(int index)
  495. {
  496. return m_constraintRefs[index];
  497. }
  498. int getNumConstraintRefs() const
  499. {
  500. return m_constraintRefs.size();
  501. }
  502. void setFlags(int flags)
  503. {
  504. m_rigidbodyFlags = flags;
  505. }
  506. int getFlags() const
  507. {
  508. return m_rigidbodyFlags;
  509. }
  510. ///perform implicit force computation in world space
  511. btVector3 computeGyroscopicImpulseImplicit_World(btScalar dt) const;
  512. ///perform implicit force computation in body space (inertial frame)
  513. btVector3 computeGyroscopicImpulseImplicit_Body(btScalar step) const;
  514. ///explicit version is best avoided, it gains energy
  515. btVector3 computeGyroscopicForceExplicit(btScalar maxGyroscopicForce) const;
  516. btVector3 getLocalInertia() const;
  517. ///////////////////////////////////////////////
  518. virtual int calculateSerializeBufferSize() const;
  519. ///fills the dataBuffer and returns the struct name (and 0 on failure)
  520. virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
  521. virtual void serializeSingleObject(class btSerializer* serializer) const;
  522. };
  523. //@todo add m_optionalMotionState and m_constraintRefs to btRigidBodyData
  524. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  525. struct btRigidBodyFloatData
  526. {
  527. btCollisionObjectFloatData m_collisionObjectData;
  528. btMatrix3x3FloatData m_invInertiaTensorWorld;
  529. btVector3FloatData m_linearVelocity;
  530. btVector3FloatData m_angularVelocity;
  531. btVector3FloatData m_angularFactor;
  532. btVector3FloatData m_linearFactor;
  533. btVector3FloatData m_gravity;
  534. btVector3FloatData m_gravity_acceleration;
  535. btVector3FloatData m_invInertiaLocal;
  536. btVector3FloatData m_totalForce;
  537. btVector3FloatData m_totalTorque;
  538. float m_inverseMass;
  539. float m_linearDamping;
  540. float m_angularDamping;
  541. float m_additionalDampingFactor;
  542. float m_additionalLinearDampingThresholdSqr;
  543. float m_additionalAngularDampingThresholdSqr;
  544. float m_additionalAngularDampingFactor;
  545. float m_linearSleepingThreshold;
  546. float m_angularSleepingThreshold;
  547. int m_additionalDamping;
  548. };
  549. ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
  550. struct btRigidBodyDoubleData
  551. {
  552. btCollisionObjectDoubleData m_collisionObjectData;
  553. btMatrix3x3DoubleData m_invInertiaTensorWorld;
  554. btVector3DoubleData m_linearVelocity;
  555. btVector3DoubleData m_angularVelocity;
  556. btVector3DoubleData m_angularFactor;
  557. btVector3DoubleData m_linearFactor;
  558. btVector3DoubleData m_gravity;
  559. btVector3DoubleData m_gravity_acceleration;
  560. btVector3DoubleData m_invInertiaLocal;
  561. btVector3DoubleData m_totalForce;
  562. btVector3DoubleData m_totalTorque;
  563. double m_inverseMass;
  564. double m_linearDamping;
  565. double m_angularDamping;
  566. double m_additionalDampingFactor;
  567. double m_additionalLinearDampingThresholdSqr;
  568. double m_additionalAngularDampingThresholdSqr;
  569. double m_additionalAngularDampingFactor;
  570. double m_linearSleepingThreshold;
  571. double m_angularSleepingThreshold;
  572. int m_additionalDamping;
  573. char m_padding[4];
  574. };
  575. #endif //BT_RIGIDBODY_H