2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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:
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.
20 #include <SimdPoint3.h>
21 #include <SimdTransform.h>
22 #include "BroadphaseCollision/BroadphaseProxy.h"
25 #include "CollisionDispatch/CollisionObject.h"
29 typedef SimdScalar dMatrix3[4*3];
31 extern float gLinearAirDamping;
34 #define MAX_RIGIDBODIES 8192
37 /// RigidBody class for RigidBody Dynamics
39 class RigidBody : public CollisionObject
43 RigidBody(const MassProps& massProps,SimdScalar linearDamping,SimdScalar angularDamping,SimdScalar friction,SimdScalar restitution);
45 void proceedToTransform(const SimdTransform& newTrans);
48 /// continuous collision detection needs prediction
49 void predictIntegratedTransform(SimdScalar step, SimdTransform& predictedTransform) const;
51 void applyForces(SimdScalar step);
53 void setGravity(const SimdVector3& acceleration);
55 void setDamping(SimdScalar lin_damping, SimdScalar ang_damping);
57 inline const CollisionShape* GetCollisionShape() const {
58 return m_collisionShape;
61 inline CollisionShape* GetCollisionShape() {
62 return m_collisionShape;
65 void setMassProps(SimdScalar mass, const SimdVector3& inertia);
67 SimdScalar getInvMass() const { return m_inverseMass; }
68 const SimdMatrix3x3& getInvInertiaTensorWorld() const { return m_invInertiaTensorWorld; }
70 void integrateVelocities(SimdScalar step);
72 void setCenterOfMassTransform(const SimdTransform& xform);
74 void applyCentralForce(const SimdVector3& force)
76 m_totalForce += force;
79 const SimdVector3& getInvInertiaDiagLocal()
81 return m_invInertiaLocal;
84 void setInvInertiaDiagLocal(const SimdVector3& diagInvInertia)
86 m_invInertiaLocal = diagInvInertia;
89 void applyTorque(const SimdVector3& torque)
91 m_totalTorque += torque;
94 void applyForce(const SimdVector3& force, const SimdVector3& rel_pos)
96 applyCentralForce(force);
97 applyTorque(rel_pos.cross(force));
100 void applyCentralImpulse(const SimdVector3& impulse)
102 m_linearVelocity += impulse * m_inverseMass;
105 void applyTorqueImpulse(const SimdVector3& torque)
107 m_angularVelocity += m_invInertiaTensorWorld * torque;
111 void applyImpulse(const SimdVector3& impulse, const SimdVector3& rel_pos)
113 if (m_inverseMass != 0.f)
115 applyCentralImpulse(impulse);
116 applyTorqueImpulse(rel_pos.cross(impulse));
122 m_totalForce.setValue(0.0f, 0.0f, 0.0f);
123 m_totalTorque.setValue(0.0f, 0.0f, 0.0f);
126 void updateInertiaTensor();
128 const SimdPoint3& getCenterOfMassPosition() const { return m_worldTransform.getOrigin(); }
129 SimdQuaternion getOrientation() const;
131 const SimdTransform& getCenterOfMassTransform() const { return m_worldTransform; }
132 const SimdVector3& getLinearVelocity() const { return m_linearVelocity; }
133 const SimdVector3& getAngularVelocity() const { return m_angularVelocity; }
136 void setLinearVelocity(const SimdVector3& lin_vel);
137 void setAngularVelocity(const SimdVector3& ang_vel) { m_angularVelocity = ang_vel; }
139 SimdVector3 getVelocityInLocalPoint(const SimdVector3& rel_pos) const
141 return m_linearVelocity + m_angularVelocity.cross(rel_pos);
144 void translate(const SimdVector3& v)
146 m_worldTransform.getOrigin() += v;
150 void getAabb(SimdVector3& aabbMin,SimdVector3& aabbMax) const;
153 void setRestitution(float rest)
155 m_restitution = rest;
157 float getRestitution() const
159 return m_restitution;
161 void setFriction(float frict)
165 float getFriction() const
171 inline float ComputeImpulseDenominator(const SimdPoint3& pos, const SimdVector3& normal) const
173 SimdVector3 r0 = pos - getCenterOfMassPosition();
175 SimdVector3 c0 = (r0).cross(normal);
177 SimdVector3 vec = (c0 * getInvInertiaTensorWorld()).cross(r0);
179 return m_inverseMass + normal.dot(vec);
186 SimdMatrix3x3 m_invInertiaTensorWorld;
187 SimdVector3 m_gravity;
188 SimdVector3 m_invInertiaLocal;
189 SimdVector3 m_totalForce;
190 SimdVector3 m_totalTorque;
191 // SimdQuaternion m_orn1;
193 SimdVector3 m_linearVelocity;
195 SimdVector3 m_angularVelocity;
197 SimdScalar m_linearDamping;
198 SimdScalar m_angularDamping;
199 SimdScalar m_inverseMass;
201 SimdScalar m_friction;
202 SimdScalar m_restitution;
204 BroadphaseProxy* m_broadphaseProxy;
210 const BroadphaseProxy* GetBroadphaseProxy() const
212 return m_broadphaseProxy;
214 BroadphaseProxy* GetBroadphaseProxy()
216 return m_broadphaseProxy;
218 void SetBroadphaseProxy(BroadphaseProxy* broadphaseProxy)
220 m_broadphaseProxy = broadphaseProxy;
224 /// for ode solver-binding
230 float m_padding[1024];
231 SimdVector3 m_tacc;//temp