added Bullet rigidbodies that behave like Sumo 'dynamic', without rotations. Done using a special hinge constraint (no translational degrees of freedom removed)

This commit is contained in:
Erwin Coumans 2006-04-26 06:01:46 +00:00
parent 45d0123a59
commit f9597df32d
6 changed files with 80 additions and 39 deletions

@ -28,7 +28,8 @@ HingeConstraint::HingeConstraint(RigidBody& rbA,RigidBody& rbB, const SimdVector
SimdVector3& axisInA,SimdVector3& axisInB)
:TypedConstraint(rbA,rbB),m_pivotInA(pivotInA),m_pivotInB(pivotInB),
m_axisInA(axisInA),
m_axisInB(axisInB)
m_axisInB(axisInB),
m_angularOnly(false)
{
}
@ -38,7 +39,8 @@ HingeConstraint::HingeConstraint(RigidBody& rbA,const SimdVector3& pivotInA,Simd
:TypedConstraint(rbA),m_pivotInA(pivotInA),m_pivotInB(rbA.getCenterOfMassTransform()(pivotInA)),
m_axisInA(axisInA),
//fixed axis in worldspace
m_axisInB(rbA.getCenterOfMassTransform().getBasis() * -axisInA)
m_axisInB(rbA.getCenterOfMassTransform().getBasis() * -axisInA),
m_angularOnly(false)
{
}
@ -47,6 +49,8 @@ void HingeConstraint::BuildJacobian()
{
SimdVector3 normal(0,0,0);
if (!m_angularOnly)
{
for (int i=0;i<3;i++)
{
normal[i] = 1;
@ -62,6 +66,7 @@ void HingeConstraint::BuildJacobian()
m_rbB.getInvMass());
normal[i] = 0;
}
}
//calculate two perpendicular jointAxis, orthogonal to hingeAxis
//these two jointAxis require equal angular velocities for both bodies
@ -97,6 +102,8 @@ void HingeConstraint::SolveConstraint(SimdScalar timeStep)
SimdScalar tau = 0.3f;
SimdScalar damping = 1.f;
if (!m_angularOnly)
{
for (int i=0;i<3;i++)
{
normal[i] = 1;
@ -120,6 +127,7 @@ void HingeConstraint::SolveConstraint(SimdScalar timeStep)
normal[i] = 0;
}
}
///solve angular part

@ -36,6 +36,7 @@ class HingeConstraint : public TypedConstraint
SimdVector3 m_axisInA;
SimdVector3 m_axisInB;
bool m_angularOnly;
public:
@ -60,6 +61,11 @@ public:
return m_rbB;
}
void setAngularOnly(bool angularOnly)
{
m_angularOnly = angularOnly;
}
};

@ -508,7 +508,6 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep)
if (!SimdFuzzyZero(timeStep))
{
@ -1153,6 +1152,8 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl
(rb1->getCenterOfMassTransform().getBasis().inverse()*(rb0->getCenterOfMassTransform().getBasis() * -axisInA)) :
rb0->getCenterOfMassTransform().getBasis() * -axisInA;
bool hingeAngularOnly = false;
switch (type)
{
case PHY_POINT2POINT_CONSTRAINT:
@ -1179,6 +1180,8 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl
break;
}
case PHY_ANGULAR_CONSTRAINT:
hingeAngularOnly = true;
case PHY_LINEHINGE_CONSTRAINT:
{
HingeConstraint* hinge = 0;
@ -1196,7 +1199,7 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl
pivotInA,axisInA);
}
hinge->setAngularOnly( hingeAngularOnly );
m_constraints.push_back(hinge);
hinge->SetUserConstraintId(gConstraintUid++);
hinge->SetUserConstraintType(type);

@ -1064,6 +1064,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
ci.m_collisionShape = bm;
ci.m_friction = smmaterial->m_friction;//tweak the friction a bit, so the default 0.5 works nice
ci.m_restitution = smmaterial->m_restitution;
ci.m_physicsEnv = env;
@ -1088,6 +1089,25 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
if (objprop->m_disableSleeping)
physicscontroller->GetRigidBody()->SetActivationState(DISABLE_DEACTIVATION);
if (!objprop->m_angular_rigidbody)
{
/*
//setting the inertia could achieve similar results to constraint the up
//but it is prone to instability, so use special 'Angular' constraint
SimdVector3 inertia = physicscontroller->GetRigidBody()->getInvInertiaDiagLocal();
inertia.setX(0.f);
inertia.setZ(0.f);
physicscontroller->GetRigidBody()->setInvInertiaDiagLocal(inertia);
physicscontroller->GetRigidBody()->updateInertiaTensor();
*/
env->createConstraint(physicscontroller,0,PHY_ANGULAR_CONSTRAINT,0,0,0,0,0,1);
}
bool isActor = objprop->m_isactor;
gameobj->getClientInfo()->m_type = (isActor ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC);
// store materialname in auxinfo, needed for touchsensors

@ -508,7 +508,6 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep)
if (!SimdFuzzyZero(timeStep))
{
@ -1153,6 +1152,8 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl
(rb1->getCenterOfMassTransform().getBasis().inverse()*(rb0->getCenterOfMassTransform().getBasis() * -axisInA)) :
rb0->getCenterOfMassTransform().getBasis() * -axisInA;
bool hingeAngularOnly = false;
switch (type)
{
case PHY_POINT2POINT_CONSTRAINT:
@ -1179,6 +1180,8 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl
break;
}
case PHY_ANGULAR_CONSTRAINT:
hingeAngularOnly = true;
case PHY_LINEHINGE_CONSTRAINT:
{
HingeConstraint* hinge = 0;
@ -1196,7 +1199,7 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl
pivotInA,axisInA);
}
hinge->setAngularOnly( hingeAngularOnly );
m_constraints.push_back(hinge);
hinge->SetUserConstraintId(gConstraintUid++);
hinge->SetUserConstraintType(type);

@ -99,6 +99,7 @@ typedef enum PHY_PhysicsType {
typedef enum PHY_ConstraintType {
PHY_POINT2POINT_CONSTRAINT=1,
PHY_LINEHINGE_CONSTRAINT=2,
PHY_ANGULAR_CONSTRAINT = 3,//hinge without ball socket
PHY_VEHICLE_CONSTRAINT=11,//complex 'constraint' that turns a rigidbody into a vehicle
} PHY_ConstraintType;