Missing functions (#21)
- add some missing functions - added config.h for users that vendor Box3D - joint unit tests - improve joint limit consistency - extend build matrix
This commit is contained in:
parent
70ba099709
commit
8441b4a06d
31 changed files with 918 additions and 410 deletions
|
|
@ -240,199 +240,6 @@ public:
|
|||
|
||||
static int sampleOverlapRecovery = RegisterSample( "Robustness", "Overlap Recovery", OverlapRecovery::Create );
|
||||
|
||||
class Cart : public Sample
|
||||
{
|
||||
public:
|
||||
explicit Cart( SampleContext* context )
|
||||
: Sample( context )
|
||||
{
|
||||
if ( context->restart == false )
|
||||
{
|
||||
m_camera->SetView( 45.0f, 30.0f, 15.0f, { 0.0f, 2.0f, 0.0f } );
|
||||
//context->settings.subStepCount = 12;
|
||||
|
||||
}
|
||||
|
||||
AddGroundBox( 20.0f );
|
||||
|
||||
b3World_SetGravity( m_worldId, { 0, -22, 0 } );
|
||||
|
||||
m_contactHertz = 240.0f;
|
||||
m_contactDampingRatio = 10.0f;
|
||||
m_contactSpeed = 0.5f;
|
||||
b3World_SetContactTuning( m_worldId, m_contactHertz, m_contactDampingRatio, m_contactSpeed );
|
||||
|
||||
m_constraintHertz = 240.0f;
|
||||
m_constraintDampingRatio = 0.0f;
|
||||
|
||||
m_chassisId = {};
|
||||
m_wheelId1 = {};
|
||||
m_wheelId2 = {};
|
||||
m_wheelId3 = {};
|
||||
m_wheelId4 = {};
|
||||
m_jointId1 = {};
|
||||
m_jointId2 = {};
|
||||
m_jointId3 = {};
|
||||
m_jointId4 = {};
|
||||
|
||||
CreateScene();
|
||||
}
|
||||
|
||||
void CreateScene()
|
||||
{
|
||||
if ( B3_IS_NON_NULL( m_chassisId ) )
|
||||
{
|
||||
b3DestroyBody( m_chassisId );
|
||||
}
|
||||
|
||||
if ( B3_IS_NON_NULL( m_wheelId1 ) )
|
||||
{
|
||||
b3DestroyBody( m_wheelId1 );
|
||||
}
|
||||
|
||||
if ( B3_IS_NON_NULL( m_wheelId2 ) )
|
||||
{
|
||||
b3DestroyBody( m_wheelId2 );
|
||||
}
|
||||
|
||||
if ( B3_IS_NON_NULL( m_wheelId3 ) )
|
||||
{
|
||||
b3DestroyBody( m_wheelId3 );
|
||||
}
|
||||
|
||||
if ( B3_IS_NON_NULL( m_wheelId4 ) )
|
||||
{
|
||||
b3DestroyBody( m_wheelId4 );
|
||||
}
|
||||
|
||||
float yBase = 1.0f;
|
||||
|
||||
b3BodyDef bodyDef = b3DefaultBodyDef();
|
||||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.position = { 0.0f, yBase, 0.0f };
|
||||
m_chassisId = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.density = 1000.0f;
|
||||
|
||||
b3BoxHull box = b3MakeTransformedBoxHull( 1.0f, 0.25f, 0.5f, { { 0.0f, 0.25f, 0.0f }, b3Quat_identity } );
|
||||
b3CreateHullShape( m_chassisId, &shapeDef, &box.base );
|
||||
|
||||
shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.baseMaterial.rollingResistance = 0.02f;
|
||||
shapeDef.density = 200.0f;
|
||||
|
||||
b3Sphere sphere = { b3Vec3_zero, 0.1f };
|
||||
bodyDef.position = { -0.9f, yBase - 0.15f, 0.4f };
|
||||
m_wheelId1 = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateSphereShape( m_wheelId1, &shapeDef, &sphere );
|
||||
|
||||
bodyDef.position = { 0.9f, yBase - 0.15f, 0.4f };
|
||||
m_wheelId2 = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateSphereShape( m_wheelId2, &shapeDef, &sphere );
|
||||
|
||||
bodyDef.position = { 0.9f, yBase - 0.15f, -0.4f };
|
||||
m_wheelId3 = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateSphereShape( m_wheelId3, &shapeDef, &sphere );
|
||||
|
||||
bodyDef.position = { -0.9f, yBase - 0.15f, -0.4f };
|
||||
m_wheelId4 = b3CreateBody( m_worldId, &bodyDef );
|
||||
b3CreateSphereShape( m_wheelId4, &shapeDef, &sphere );
|
||||
|
||||
b3SphericalJointDef jointDef = b3DefaultSphericalJointDef();
|
||||
jointDef.base.constraintHertz = m_constraintHertz;
|
||||
jointDef.base.constraintDampingRatio = m_constraintDampingRatio;
|
||||
jointDef.base.drawScale = 0.5f;
|
||||
|
||||
jointDef.base.bodyIdA = m_chassisId;
|
||||
jointDef.base.bodyIdB = m_wheelId1;
|
||||
jointDef.base.localFrameA.p = { -0.9f, -0.15f, 0.4f };
|
||||
jointDef.base.localFrameB.p = { 0.0f, 0.0f, 0.0f };
|
||||
m_jointId1 = b3CreateSphericalJoint( m_worldId, &jointDef );
|
||||
|
||||
jointDef.base.bodyIdA = m_chassisId;
|
||||
jointDef.base.bodyIdB = m_wheelId2;
|
||||
jointDef.base.localFrameA.p = { 0.9f, -0.15f, 0.4f };
|
||||
jointDef.base.localFrameB.p = { 0.0f, 0.0f, 0.0f };
|
||||
m_jointId2 = b3CreateSphericalJoint( m_worldId, &jointDef );
|
||||
|
||||
jointDef.base.bodyIdA = m_chassisId;
|
||||
jointDef.base.bodyIdB = m_wheelId3;
|
||||
jointDef.base.localFrameA.p = { 0.9f, -0.15f, -0.4f };
|
||||
jointDef.base.localFrameB.p = { 0.0f, 0.0f, 0.0f };
|
||||
m_jointId3 = b3CreateSphericalJoint( m_worldId, &jointDef );
|
||||
|
||||
jointDef.base.bodyIdA = m_chassisId;
|
||||
jointDef.base.bodyIdB = m_wheelId4;
|
||||
jointDef.base.localFrameA.p = { -0.9f, -0.15f, -0.4f };
|
||||
jointDef.base.localFrameB.p = { 0.0f, 0.0f, 0.0f };
|
||||
m_jointId4 = b3CreateSphericalJoint( m_worldId, &jointDef );
|
||||
}
|
||||
|
||||
bool DrawControls() override
|
||||
{
|
||||
ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() );
|
||||
|
||||
bool changed = false;
|
||||
ImGui::Text( "Contact" );
|
||||
changed = changed || ImGui::SliderFloat( "Hertz##contact", &m_contactHertz, 0.0f, 240.0f, "%.f" );
|
||||
changed = changed || ImGui::SliderFloat( "Damping Ratio##contact", &m_contactDampingRatio, 0.0f, 100.0f, "%.f" );
|
||||
changed = changed || ImGui::SliderFloat( "Speed", &m_contactSpeed, 0.0f, 5.0f, "%.1f" );
|
||||
|
||||
if ( changed )
|
||||
{
|
||||
b3World_SetContactTuning( m_worldId, m_contactHertz, m_contactDampingRatio, m_contactSpeed );
|
||||
CreateScene();
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
changed = false;
|
||||
ImGui::Text( "Joint" );
|
||||
changed = changed || ImGui::SliderFloat( "Hertz##joint", &m_constraintHertz, 0.0f, 240.0f, "%.f" );
|
||||
changed = changed || ImGui::SliderFloat( "Damping Ratio##joint", &m_constraintDampingRatio, 0.0f, 20.0f, "%.f" );
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
changed = changed || ImGui::Button( "Reset Scene" );
|
||||
|
||||
if ( changed )
|
||||
{
|
||||
b3Joint_SetConstraintTuning( m_jointId1, m_constraintHertz, m_constraintDampingRatio );
|
||||
b3Joint_SetConstraintTuning( m_jointId2, m_constraintHertz, m_constraintDampingRatio );
|
||||
b3Joint_SetConstraintTuning( m_jointId3, m_constraintHertz, m_constraintDampingRatio );
|
||||
b3Joint_SetConstraintTuning( m_jointId4, m_constraintHertz, m_constraintDampingRatio );
|
||||
CreateScene();
|
||||
}
|
||||
|
||||
ImGui::PopItemWidth();
|
||||
return true;
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* context )
|
||||
{
|
||||
return new Cart( context );
|
||||
}
|
||||
|
||||
b3BodyId m_chassisId;
|
||||
b3BodyId m_wheelId1;
|
||||
b3BodyId m_wheelId2;
|
||||
b3BodyId m_wheelId3;
|
||||
b3BodyId m_wheelId4;
|
||||
b3JointId m_jointId1;
|
||||
b3JointId m_jointId2;
|
||||
b3JointId m_jointId3;
|
||||
b3JointId m_jointId4;
|
||||
|
||||
float m_contactHertz;
|
||||
float m_contactDampingRatio;
|
||||
float m_contactSpeed;
|
||||
float m_constraintHertz;
|
||||
float m_constraintDampingRatio;
|
||||
};
|
||||
|
||||
static int sampleCart = RegisterSample( "Robustness", "Cart", Cart::Create );
|
||||
|
||||
// This forces a constraint graph color overflow
|
||||
class OverflowColorPile : public Sample
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue