stop overriding mass when setting motion locks
This commit is contained in:
parent
6de662cd3b
commit
6357bf521a
10 changed files with 253 additions and 142 deletions
|
|
@ -1211,7 +1211,7 @@ public:
|
|||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.name = "full";
|
||||
bodyDef.position = { 0.0f, 1.0f, 2.0f };
|
||||
bodyDef.position = { 0.0f, 1.0f, 3.0f };
|
||||
bodyDef.motionLocks.linearX = true;
|
||||
bodyDef.motionLocks.linearY = true;
|
||||
bodyDef.motionLocks.linearZ = true;
|
||||
|
|
|
|||
|
|
@ -3093,3 +3093,73 @@ public:
|
|||
};
|
||||
|
||||
static int sampleStaticLoad = RegisterSample( "Issues", "Static Load", StaticLoad::Create );
|
||||
|
||||
class TranslationLockedPlatform : public Sample
|
||||
{
|
||||
public:
|
||||
explicit TranslationLockedPlatform( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 0.0f, 10.0f, 10.0f, { 0.0f, 0.5f, 0.0f } );
|
||||
}
|
||||
|
||||
context->hertz = 50.0f;
|
||||
context->subStepCount = 4;
|
||||
b3World_SetGravity( m_worldId, { 0.0f, -20.0f, 0.0f } );
|
||||
|
||||
for ( int i = 0; i < 2; ++i )
|
||||
{
|
||||
float x = i == 0 ? -3.0f : 3.0f;
|
||||
b3BodyDef groundDef = b3DefaultBodyDef();
|
||||
groundDef.type = i == 0 ? b3_staticBody : b3_dynamicBody;
|
||||
groundDef.position = { x, 0.0f, 0.0f };
|
||||
groundDef.enableSleep = false;
|
||||
groundDef.motionLocks.linearX = true;
|
||||
groundDef.motionLocks.linearY = true;
|
||||
groundDef.motionLocks.linearZ = true;
|
||||
groundDef.motionLocks.angularX = true;
|
||||
groundDef.motionLocks.angularY = true;
|
||||
b3BodyId groundId = b3CreateBody( m_worldId, &groundDef );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.density = 2.5f;
|
||||
b3BoxHull box = b3MakeBoxHull( 2.0f, 0.05f, 0.5f );
|
||||
b3CreateHullShape( groundId, &shapeDef, &box.base );
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.position = { x, 0.65f, 0.0f };
|
||||
bodyDef.enableSleep = false;
|
||||
m_spheres[i] = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
b3Sphere sphere = { b3Vec3_zero, 0.5f };
|
||||
b3CreateSphereShape( m_spheres[i], &shapeDef, &sphere );
|
||||
|
||||
b3MassData massData = b3Body_GetMassData( m_spheres[i] );
|
||||
massData.inertia = b3MulSM( 10.0f / massData.mass, massData.inertia );
|
||||
massData.mass = 10.0f;
|
||||
b3Body_SetMassData( m_spheres[i], massData );
|
||||
}
|
||||
}
|
||||
|
||||
void Render() override
|
||||
{
|
||||
DrawTextLine( "10 kg spheres dropped onto 0.1 m thick platforms." );
|
||||
DrawTextLine( "Right platform: 1 kg, translation locked, rotation about Z free." );
|
||||
DrawTextLine( "Expected: both gaps settle near zero. Negative means penetration." );
|
||||
DrawTextLine( "Left (static): gap = %.3f m", (float)b3Body_GetPosition( m_spheres[0] ).y - 0.55f );
|
||||
DrawTextLine( "Right (locked): gap = %.3f m", (float)b3Body_GetPosition( m_spheres[1] ).y - 0.55f );
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new TranslationLockedPlatform( context );
|
||||
}
|
||||
|
||||
b3BodyId m_spheres[2];
|
||||
};
|
||||
|
||||
static int sampleTranslationLockedPlatform =
|
||||
RegisterSample( "Issues", "Translation Locked Platform", TranslationLockedPlatform::Create );
|
||||
|
|
|
|||
|
|
@ -2035,6 +2035,9 @@ public:
|
|||
}
|
||||
|
||||
m_motionLocks = {};
|
||||
m_motionLocks.linearX = true;
|
||||
m_motionLocks.linearY = true;
|
||||
m_motionLocks.linearZ = true;
|
||||
|
||||
for ( int i = 0; i < m_capacity; ++i )
|
||||
{
|
||||
|
|
@ -2045,6 +2048,7 @@ public:
|
|||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.enableSleep = false;
|
||||
bodyDef.motionLocks = m_motionLocks;
|
||||
|
||||
b3BoxHull box = b3MakeBoxHull( 1.0f, 1.0f, 0.5f );
|
||||
|
||||
|
|
@ -2056,6 +2060,7 @@ public:
|
|||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.density = 1.0f;
|
||||
|
||||
#if 1
|
||||
// distance joint
|
||||
{
|
||||
assert( m_count < m_capacity );
|
||||
|
|
@ -2086,30 +2091,28 @@ public:
|
|||
++m_count;
|
||||
|
||||
// motor joint
|
||||
#if 0
|
||||
{
|
||||
assert( m_bodyCount < e_count );
|
||||
assert( m_count < m_capacity );
|
||||
|
||||
bodyDef.position = position;
|
||||
m_bodyIds[m_bodyCount] = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateHullShape( m_bodyIds[m_bodyCount], &shapeDef, &box.base );
|
||||
m_bodyIds[m_count] = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateHullShape( m_bodyIds[m_count], &shapeDef, &box.base );
|
||||
|
||||
b3MotorJointDef jointDef = b3DefaultMotorJointDef();
|
||||
jointDef.base.bodyIdA = groundId;
|
||||
jointDef.base.bodyIdB = m_bodyIds[m_bodyCount];
|
||||
jointDef.base.bodyIdB = m_bodyIds[m_count];
|
||||
jointDef.base.localFrameA.p = position;
|
||||
jointDef.maxForce = 1000.0f;
|
||||
jointDef.maxTorque = 20.0f;
|
||||
jointDef.maxSpringForce = 1000.0f;
|
||||
jointDef.maxSpringTorque = 20.0f;
|
||||
jointDef.base.forceThreshold = forceThreshold;
|
||||
jointDef.base.torqueThreshold = torqueThreshold;
|
||||
jointDef.base.collideConnected = true;
|
||||
jointDef.base.userData = (void*)(intptr_t)m_bodyCount;
|
||||
jointDef.base.userData = (void*)(intptr_t)m_count;
|
||||
b3CreateMotorJoint( m_worldId, &jointDef );
|
||||
}
|
||||
|
||||
position.x += 5.0f;
|
||||
++m_count;
|
||||
#endif
|
||||
|
||||
// prismatic joint
|
||||
{
|
||||
|
|
@ -2131,6 +2134,7 @@ public:
|
|||
jointDef.base.userData = (void*)(intptr_t)m_count;
|
||||
b3CreatePrismaticJoint( m_worldId, &jointDef );
|
||||
}
|
||||
#endif
|
||||
|
||||
position.x += 5.0f;
|
||||
++m_count;
|
||||
|
|
@ -2159,6 +2163,7 @@ public:
|
|||
position.x += 5.0f;
|
||||
++m_count;
|
||||
|
||||
#if 1
|
||||
// weld joint
|
||||
{
|
||||
assert( m_count < m_capacity );
|
||||
|
|
@ -2186,9 +2191,8 @@ public:
|
|||
++m_count;
|
||||
|
||||
// wheel joint
|
||||
#if 0
|
||||
{
|
||||
assert( index < e_count );
|
||||
assert( m_count < m_capacity );
|
||||
|
||||
bodyDef.position = position;
|
||||
b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
|
@ -2200,18 +2204,18 @@ public:
|
|||
jointDef.base.bodyIdB = bodyId;
|
||||
jointDef.base.localFrameA.p = b3Body_GetLocalPoint( jointDef.base.bodyIdA, pivot );
|
||||
jointDef.base.localFrameB.p = b3Body_GetLocalPoint( jointDef.base.bodyIdB, pivot );
|
||||
jointDef.hertz = 1.0f;
|
||||
jointDef.dampingRatio = 0.7f;
|
||||
jointDef.lowerTranslation = -1.0f;
|
||||
jointDef.upperTranslation = 1.0f;
|
||||
jointDef.enableLimit = true;
|
||||
jointDef.enableMotor = true;
|
||||
jointDef.maxMotorTorque = 10.0f;
|
||||
jointDef.motorSpeed = 1.0f;
|
||||
jointDef.suspensionHertz = 1.0f;
|
||||
jointDef.suspensionDampingRatio = 0.7f;
|
||||
jointDef.lowerSuspensionLimit = -1.0f;
|
||||
jointDef.upperSuspensionLimit = 1.0f;
|
||||
jointDef.enableSuspensionLimit = true;
|
||||
jointDef.enableSpinMotor = true;
|
||||
jointDef.maxSpinTorque = 10.0f;
|
||||
jointDef.spinSpeed = 1.0f;
|
||||
jointDef.base.forceThreshold = forceThreshold;
|
||||
jointDef.base.torqueThreshold = torqueThreshold;
|
||||
jointDef.base.collideConnected = true;
|
||||
jointDef.base.userData = (void*)(intptr_t)index;
|
||||
jointDef.base.userData = (void*)(intptr_t)m_count;
|
||||
b3CreateWheelJoint( m_worldId, &jointDef );
|
||||
}
|
||||
|
||||
|
|
@ -2289,7 +2293,7 @@ public:
|
|||
return new MotionLocks( context );
|
||||
}
|
||||
|
||||
static constexpr int m_capacity = 6;
|
||||
static constexpr int m_capacity = 7;
|
||||
b3BodyId m_bodyIds[m_capacity];
|
||||
int m_count;
|
||||
b3MotionLocks m_motionLocks;
|
||||
|
|
|
|||
Loading…
Reference in a new issue