dynamic mover
This commit is contained in:
parent
f36d061ba2
commit
f0b1ed2fca
29 changed files with 3078 additions and 432 deletions
|
|
@ -296,6 +296,102 @@ static int TestMotorJoint( void )
|
|||
return FinishJoint( jointId, f.worldId );
|
||||
}
|
||||
|
||||
static int TestMoverJoint( void )
|
||||
{
|
||||
JointFixture f = CreateJointFixture();
|
||||
|
||||
b3MoverJointDef def = b3DefaultMoverJointDef();
|
||||
SetCommonFrames( &def.base, &f );
|
||||
b3JointId jointId = b3CreateMoverJoint( f.worldId, &def );
|
||||
|
||||
if ( ExerciseJointBase( jointId, f.worldId, f.groundId, f.bodyId, b3_moverJoint ) != 0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
b3Vec3 velocity = { 1.0f, 2.0f, -3.0f };
|
||||
b3MoverJoint_SetLinearVelocity( jointId, velocity );
|
||||
b3Vec3 gotVelocity = b3MoverJoint_GetLinearVelocity( jointId );
|
||||
ENSURE( gotVelocity.x == 1.0f && gotVelocity.y == 2.0f && gotVelocity.z == -3.0f );
|
||||
|
||||
// The y axis has no force budget, so it must stay at rest while x and z reach the target
|
||||
b3Vec3 maxForce = { 1000.0f, 0.0f, 1000.0f };
|
||||
b3MoverJoint_SetMaxVelocityForce( jointId, maxForce );
|
||||
b3Vec3 gotForce = b3MoverJoint_GetMaxVelocityForce( jointId );
|
||||
ENSURE( gotForce.x == 1000.0f && gotForce.y == 0.0f && gotForce.z == 1000.0f );
|
||||
|
||||
for ( int i = 0; i < 30; ++i )
|
||||
{
|
||||
b3World_Step( f.worldId, 1.0f / 60.0f, 4 );
|
||||
}
|
||||
|
||||
b3Vec3 v = b3Body_GetLinearVelocity( f.bodyId );
|
||||
ENSURE_SMALL( v.x - 1.0f, 1.0e-4f );
|
||||
ENSURE_SMALL( v.y, 1.0e-4f );
|
||||
ENSURE_SMALL( v.z + 3.0f, 1.0e-4f );
|
||||
|
||||
b3Vec3 w = b3Body_GetAngularVelocity( f.bodyId );
|
||||
ENSURE( w.x == 0.0f && w.y == 0.0f && w.z == 0.0f );
|
||||
|
||||
return FinishJoint( jointId, f.worldId );
|
||||
}
|
||||
|
||||
// A box held up by a pogo spring under gravity should settle at the rest length
|
||||
static int TestPogoJoint( void )
|
||||
{
|
||||
JointFixture f = CreateJointFixture();
|
||||
b3World_SetGravity( f.worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } );
|
||||
|
||||
float restLength = 2.0f;
|
||||
float mass = b3Body_GetMass( f.bodyId );
|
||||
|
||||
b3PogoJointDef def = b3DefaultPogoJointDef();
|
||||
def.base.bodyIdA = f.groundId;
|
||||
def.base.bodyIdB = f.bodyId;
|
||||
def.base.localFrameA.p = (b3Vec3){ 0.0f, 1.0f, 0.0f };
|
||||
def.base.localFrameB.p = (b3Vec3){ 0.0f, 0.0f, 0.0f };
|
||||
def.normal = b3Vec3_axisY;
|
||||
def.restLength = restLength;
|
||||
def.hertz = 2.0f;
|
||||
def.dampingRatio = 1.0f;
|
||||
def.maxCompressionForce = 100.0f * 10.0f * mass;
|
||||
def.maxTensionForce = 100.0f * 10.0f * mass;
|
||||
b3JointId jointId = b3CreatePogoJoint( f.worldId, &def );
|
||||
|
||||
if ( ExerciseJointBase( jointId, f.worldId, f.groundId, f.bodyId, b3_pogoJoint ) != 0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
b3PogoJoint_SetRestLength( jointId, restLength );
|
||||
ENSURE( b3PogoJoint_GetRestLength( jointId ) == restLength );
|
||||
|
||||
b3PogoJoint_SetSpringHertz( jointId, 3.0f );
|
||||
ENSURE( b3PogoJoint_GetSpringHertz( jointId ) == 3.0f );
|
||||
|
||||
b3PogoJoint_SetSpringDampingRatio( jointId, 0.9f );
|
||||
ENSURE( b3PogoJoint_GetSpringDampingRatio( jointId ) == 0.9f );
|
||||
|
||||
// Starts stretched by one meter
|
||||
ENSURE_SMALL( b3PogoJoint_GetCurrentLength( jointId ) - 3.0f, 1.0e-5f );
|
||||
|
||||
for ( int i = 0; i < 300; ++i )
|
||||
{
|
||||
b3World_Step( f.worldId, 1.0f / 60.0f, 4 );
|
||||
}
|
||||
|
||||
ENSURE_SMALL( b3PogoJoint_GetCurrentLength( jointId ) - restLength, 0.01f );
|
||||
ENSURE_SMALL( b3Body_GetLinearVelocity( f.bodyId ).y, 0.01f );
|
||||
|
||||
// Holding the weight takes an impulse of m * g * h each sub-step
|
||||
ENSURE_SMALL( b3PogoJoint_GetImpulse( jointId ) - mass * 10.0f / 240.0f, 0.001f * mass );
|
||||
|
||||
b3Vec3 force = b3Joint_GetConstraintForce( jointId );
|
||||
ENSURE_SMALL( force.y - mass * 10.0f, 0.1f * mass );
|
||||
|
||||
return FinishJoint( jointId, f.worldId );
|
||||
}
|
||||
|
||||
static int TestPrismaticJoint( void )
|
||||
{
|
||||
JointFixture f = CreateJointFixture();
|
||||
|
|
@ -673,6 +769,8 @@ int JointTest( void )
|
|||
RUN_SUBTEST( TestDistanceJoint );
|
||||
RUN_SUBTEST( TestFilterJoint );
|
||||
RUN_SUBTEST( TestMotorJoint );
|
||||
RUN_SUBTEST( TestMoverJoint );
|
||||
RUN_SUBTEST( TestPogoJoint );
|
||||
RUN_SUBTEST( TestPrismaticJoint );
|
||||
RUN_SUBTEST( TestRevoluteJoint );
|
||||
RUN_SUBTEST( TestSphericalJoint );
|
||||
|
|
|
|||
Loading…
Reference in a new issue