[1963] | 1 | /* |
---|
| 2 | Bullet Continuous Collision Detection and Physics Library |
---|
| 3 | Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ |
---|
| 4 | |
---|
| 5 | This software is provided 'as-is', without any express or implied warranty. |
---|
| 6 | In no event will the authors be held liable for any damages arising from the use of this software. |
---|
| 7 | Permission is granted to anyone to use this software for any purpose, |
---|
| 8 | including commercial applications, and to alter it and redistribute it freely, |
---|
| 9 | subject to the following restrictions: |
---|
| 10 | |
---|
| 11 | 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. |
---|
| 12 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. |
---|
| 13 | 3. This notice may not be removed or altered from any source distribution. |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #ifndef BT_SOLVER_BODY_H |
---|
| 17 | #define BT_SOLVER_BODY_H |
---|
| 18 | |
---|
| 19 | class btRigidBody; |
---|
| 20 | #include "LinearMath/btVector3.h" |
---|
| 21 | #include "LinearMath/btMatrix3x3.h" |
---|
| 22 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
| 23 | #include "LinearMath/btAlignedAllocator.h" |
---|
| 24 | #include "LinearMath/btTransformUtil.h" |
---|
| 25 | |
---|
| 26 | |
---|
[2430] | 27 | ///The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packed to increase cache coherence/performance. |
---|
[1963] | 28 | ATTRIBUTE_ALIGNED16 (struct) btSolverBody |
---|
| 29 | { |
---|
| 30 | BT_DECLARE_ALIGNED_ALLOCATOR(); |
---|
[2908] | 31 | |
---|
| 32 | btMatrix3x3 m_worldInvInertiaTensor; |
---|
| 33 | |
---|
| 34 | btVector3 m_angularVelocity; |
---|
| 35 | btVector3 m_linearVelocity; |
---|
| 36 | btVector3 m_centerOfMassPosition; |
---|
[2430] | 37 | btVector3 m_pushVelocity; |
---|
[2908] | 38 | btVector3 m_turnVelocity; |
---|
[2430] | 39 | |
---|
[2908] | 40 | float m_angularFactor; |
---|
| 41 | float m_invMass; |
---|
| 42 | float m_friction; |
---|
| 43 | btRigidBody* m_originalBody; |
---|
[1963] | 44 | |
---|
[2908] | 45 | |
---|
| 46 | SIMD_FORCE_INLINE void getVelocityInLocalPoint(const btVector3& rel_pos, btVector3& velocity ) const |
---|
[1963] | 47 | { |
---|
[2908] | 48 | velocity = m_linearVelocity + m_angularVelocity.cross(rel_pos); |
---|
[1963] | 49 | } |
---|
| 50 | |
---|
[2908] | 51 | //Optimization for the iterative solver: avoid calculating constant terms involving inertia, normal, relative position |
---|
| 52 | SIMD_FORCE_INLINE void internalApplyImpulse(const btVector3& linearComponent, const btVector3& angularComponent,btScalar impulseMagnitude) |
---|
[1963] | 53 | { |
---|
[2908] | 54 | if (m_invMass) |
---|
| 55 | { |
---|
| 56 | m_linearVelocity += linearComponent*impulseMagnitude; |
---|
| 57 | m_angularVelocity += angularComponent*(impulseMagnitude*m_angularFactor); |
---|
| 58 | } |
---|
[1963] | 59 | } |
---|
[2908] | 60 | |
---|
| 61 | SIMD_FORCE_INLINE void internalApplyPushImpulse(const btVector3& linearComponent, const btVector3& angularComponent,btScalar impulseMagnitude) |
---|
[1963] | 62 | { |
---|
[2908] | 63 | if (m_invMass) |
---|
[1963] | 64 | { |
---|
[2908] | 65 | m_pushVelocity += linearComponent*impulseMagnitude; |
---|
| 66 | m_turnVelocity += angularComponent*(impulseMagnitude*m_angularFactor); |
---|
[1963] | 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | void writebackVelocity() |
---|
| 72 | { |
---|
| 73 | if (m_invMass) |
---|
| 74 | { |
---|
[2908] | 75 | m_originalBody->setLinearVelocity(m_linearVelocity); |
---|
| 76 | m_originalBody->setAngularVelocity(m_angularVelocity); |
---|
[1963] | 77 | |
---|
| 78 | //m_originalBody->setCompanionId(-1); |
---|
| 79 | } |
---|
| 80 | } |
---|
[2908] | 81 | |
---|
[1963] | 82 | |
---|
[2908] | 83 | void writebackVelocity(btScalar timeStep) |
---|
[1963] | 84 | { |
---|
| 85 | if (m_invMass) |
---|
| 86 | { |
---|
[2908] | 87 | m_originalBody->setLinearVelocity(m_linearVelocity); |
---|
| 88 | m_originalBody->setAngularVelocity(m_angularVelocity); |
---|
| 89 | |
---|
| 90 | //correct the position/orientation based on push/turn recovery |
---|
| 91 | btTransform newTransform; |
---|
| 92 | btTransformUtil::integrateTransform(m_originalBody->getWorldTransform(),m_pushVelocity,m_turnVelocity,timeStep,newTransform); |
---|
| 93 | m_originalBody->setWorldTransform(newTransform); |
---|
| 94 | |
---|
[1963] | 95 | //m_originalBody->setCompanionId(-1); |
---|
| 96 | } |
---|
| 97 | } |
---|
[2908] | 98 | |
---|
| 99 | void readVelocity() |
---|
| 100 | { |
---|
| 101 | if (m_invMass) |
---|
| 102 | { |
---|
| 103 | m_linearVelocity = m_originalBody->getLinearVelocity(); |
---|
| 104 | m_angularVelocity = m_originalBody->getAngularVelocity(); |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
[1963] | 108 | |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | }; |
---|
| 112 | |
---|
| 113 | #endif //BT_SOLVER_BODY_H |
---|
| 114 | |
---|
| 115 | |
---|