Add 1D and 2D support for Bullet: using rigidbody->angularFactor(const btVector3& factor) and body->setLinearFactor(const btVector3& linearFactor);

For example, to only allow linear motion in the X-Z plane, and only rotation around Y axis use:
	body->setLinearFactor(btVector3(1,0,1));
	body->setAngularFactor(btVector3(0,1,0));
Fix build issues with CodeBlocks, when generating projectfiles using CMake 2.6:
${OPENGL_glU_LIBRARY} should be ${OPENGL_glu_LIBRARY}
Fix build issue with CodeBlocks, comment out xmlfree in Extras/COLLADA_DOM/src/modules/LIBXMLPlugin/daeLIBXMLPlugin.cpp (will leak memory)
This commit is contained in:
erwin.coumans
2009-03-08 04:14:17 +00:00
parent 3317f17270
commit 700db838b1
8 changed files with 91 additions and 77 deletions

View File

@@ -44,7 +44,8 @@ void btRigidBody::setupRigidBody(const btRigidBody::btRigidBodyConstructionInfo&
m_linearVelocity.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0));
m_angularVelocity.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
m_angularFactor = btScalar(1.);
m_angularFactor.setValue(1,1,1);
m_linearFactor.setValue(1,1,1);
m_gravity.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0));
m_gravity_acceleration.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0));
m_totalForce.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0));

View File

@@ -45,7 +45,8 @@ class btRigidBody : public btCollisionObject
btVector3 m_linearVelocity;
btVector3 m_angularVelocity;
btScalar m_inverseMass;
btScalar m_angularFactor;
btVector3 m_angularFactor;
btVector3 m_linearFactor;
btVector3 m_gravity;
btVector3 m_gravity_acceleration;
@@ -219,6 +220,14 @@ public:
void setMassProps(btScalar mass, const btVector3& inertia);
const btVector3& getLinearFactor() const
{
return m_linearFactor;
}
void setLinearFactor(const btVector3& linearFactor)
{
m_linearFactor = linearFactor;
}
btScalar getInvMass() const { return m_inverseMass; }
const btMatrix3x3& getInvInertiaTensorWorld() const {
return m_invInertiaTensorWorld;
@@ -230,7 +239,7 @@ public:
void applyCentralForce(const btVector3& force)
{
m_totalForce += force;
m_totalForce += force*m_linearFactor;
}
const btVector3& getTotalForce()
@@ -261,23 +270,23 @@ public:
void applyTorque(const btVector3& torque)
{
m_totalTorque += torque;
m_totalTorque += torque*m_angularFactor;
}
void applyForce(const btVector3& force, const btVector3& rel_pos)
{
applyCentralForce(force);
applyTorque(rel_pos.cross(force)*m_angularFactor);
applyTorque(rel_pos.cross(force*m_linearFactor));
}
void applyCentralImpulse(const btVector3& impulse)
{
m_linearVelocity += impulse * m_inverseMass;
m_linearVelocity += impulse *m_linearFactor * m_inverseMass;
}
void applyTorqueImpulse(const btVector3& torque)
{
m_angularVelocity += m_invInertiaTensorWorld * torque;
m_angularVelocity += m_invInertiaTensorWorld * torque * m_angularFactor;
}
void applyImpulse(const btVector3& impulse, const btVector3& rel_pos)
@@ -287,7 +296,7 @@ public:
applyCentralImpulse(impulse);
if (m_angularFactor)
{
applyTorqueImpulse(rel_pos.cross(impulse)*m_angularFactor);
applyTorqueImpulse(rel_pos.cross(impulse*m_linearFactor));
}
}
}
@@ -297,10 +306,10 @@ public:
{
if (m_inverseMass != btScalar(0.))
{
m_linearVelocity += linearComponent*impulseMagnitude;
m_linearVelocity += linearComponent*m_linearFactor*impulseMagnitude;
if (m_angularFactor)
{
m_angularVelocity += angularComponent*impulseMagnitude*m_angularFactor;
m_angularVelocity += angularComponent*m_angularFactor*impulseMagnitude;
}
}
}
@@ -450,11 +459,16 @@ public:
int m_contactSolverType;
int m_frictionSolverType;
void setAngularFactor(btScalar angFac)
void setAngularFactor(const btVector3& angFac)
{
m_angularFactor = angFac;
}
btScalar getAngularFactor() const
void setAngularFactor(btScalar angFac)
{
m_angularFactor.setValue(angFac,angFac,angFac);
}
const btVector3& getAngularFactor() const
{
return m_angularFactor;
}