yet more fixes
This commit is contained in:
parent
7ebe18f745
commit
6190a96483
3 changed files with 56 additions and 16 deletions
|
|
@ -373,9 +373,10 @@ void DynamicMover::Update( float timeStep, b3Vec3 forward, b3Vec3 right, b3Vec2
|
|||
// The mover joint can be destroyed if attached to a platform that gets destroyed.
|
||||
bool moverJointValid = b3Joint_IsValid( m_moverJointId );
|
||||
|
||||
if ( moverJointValid == false || B3_ID_EQUALS( b3Joint_GetBodyA( m_moverJointId ), baseId ) == false )
|
||||
if ( moverJointValid == false ||
|
||||
B3_ID_EQUALS( b3Joint_GetBodyA( m_moverJointId ), baseId ) == false )
|
||||
{
|
||||
if (moverJointValid)
|
||||
if ( moverJointValid )
|
||||
{
|
||||
b3DestroyJoint( m_moverJointId, false );
|
||||
}
|
||||
|
|
@ -457,8 +458,10 @@ void DynamicMover::Update( float timeStep, b3Vec3 forward, b3Vec3 right, b3Vec2
|
|||
m_velocity.z += accelSpeed * desiredDirection.z;
|
||||
}
|
||||
|
||||
if ( m_castResult.hit == true )
|
||||
if ( m_castResult.hit == true && b3IsNormalized( m_castResult.normal ) )
|
||||
{
|
||||
m_pogoLength = m_castResult.fraction * rayLength;
|
||||
|
||||
float moverMass = b3Body_GetMass( m_moverId );
|
||||
float gravity = b3Length( b3World_GetGravity( m_worldId ) );
|
||||
float moverWeight = m_gravityScale * gravity * moverMass;
|
||||
|
|
@ -471,7 +474,6 @@ void DynamicMover::Update( float timeStep, b3Vec3 forward, b3Vec3 right, b3Vec2
|
|||
{
|
||||
if ( pogoJointValid )
|
||||
{
|
||||
m_pogoLength = b3PogoJoint_GetCurrentLength( m_pogoJointId );
|
||||
m_pogoImpulse = b3PogoJoint_GetImpulse( m_pogoJointId );
|
||||
m_pogoVelocity = b3PogoJoint_GetCurrentSpeed( m_pogoJointId );
|
||||
|
||||
|
|
@ -519,6 +521,12 @@ void DynamicMover::Update( float timeStep, b3Vec3 forward, b3Vec3 right, b3Vec2
|
|||
localFrameA.p = b3Body_GetLocalPoint( m_surfaceBodyId, m_castResult.point );
|
||||
localFrameA.q = b3Quat_identity;
|
||||
b3Joint_SetLocalFrameA( m_pogoJointId, localFrameA );
|
||||
|
||||
b3Transform localFrameB;
|
||||
localFrameB.p = m_capsule.center1 + pogoOffset;
|
||||
localFrameB.q = b3Quat_identity;
|
||||
b3Joint_SetLocalFrameB( m_pogoJointId, localFrameB );
|
||||
|
||||
b3PogoJoint_SetNormal( m_pogoJointId, m_castResult.normal );
|
||||
|
||||
if ( m_jumping )
|
||||
|
|
@ -550,6 +558,7 @@ void DynamicMover::Update( float timeStep, b3Vec3 forward, b3Vec3 right, b3Vec2
|
|||
m_surfaceBodyId = b3_nullBodyId;
|
||||
m_pogoImpulse = 0.0f;
|
||||
m_pogoVelocity = 0.0f;
|
||||
m_pogoLength = 0.0f;
|
||||
}
|
||||
|
||||
b3MoverJoint_SetLinearVelocity( m_moverJointId, m_velocity );
|
||||
|
|
|
|||
|
|
@ -242,17 +242,17 @@ void b3DrawMoverJoint( b3DebugDraw* draw, b3World* world, b3JointSim* base,
|
|||
b3Vec3 vA = stateA != NULL ? stateA->linearVelocity : b3Vec3_zero;
|
||||
b3Vec3 vB = stateB != NULL ? stateB->linearVelocity : b3Vec3_zero;
|
||||
|
||||
b3Vec3 relativeVelocity = b3Sub( vB, vA );
|
||||
b3Vec2 planarVelocity = { b3Dot( relativeVelocity, axisX ), b3Dot( relativeVelocity, axisZ ) };
|
||||
b3Vec3 velocityError = b3Sub( b3Sub( vB, vA ), joint->linearVelocity );
|
||||
b3Vec2 planarVelocityError = { b3Dot( velocityError, axisX ), b3Dot( velocityError, axisZ ) };
|
||||
b3Vec2 targetVelocity = { b3Dot( joint->linearVelocity, axisX ),
|
||||
b3Dot( joint->linearVelocity, axisZ ) };
|
||||
b3Dot( joint->linearVelocity, axisZ ) };
|
||||
|
||||
// Colorize ring by ratio of actual speed to target speed.
|
||||
// Colorize ring by ratio of velocity error magnitude to target speed.
|
||||
b3HexColor color = b3_colorWhite;
|
||||
float targetSpeed = b3Length2( targetVelocity );
|
||||
if (targetSpeed > 0.0f)
|
||||
if ( targetSpeed > 0.0f )
|
||||
{
|
||||
float t = b3ClampFloat( b3Length2( planarVelocity ) / targetSpeed, 0.0f, 1.0f );
|
||||
float t = b3ClampFloat( b3Length2( planarVelocityError ) / targetSpeed, 0.0f, 1.0f );
|
||||
color = b3LerpColor( b3_colorWhite, b3_colorBlue, t );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,14 @@
|
|||
void b3PogoJoint_SetRestLength( b3JointId jointId, float length )
|
||||
{
|
||||
B3_ASSERT( b3IsValidFloat( length ) && length >= 0.0f );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
if ( joint->pogoJoint.restLength == length )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
b3World* world = b3GetWorld( jointId.world0 );
|
||||
B3_REC( world, PogoJointSetRestLength, jointId, length );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
joint->pogoJoint.restLength = length;
|
||||
}
|
||||
|
||||
|
|
@ -33,9 +38,14 @@ float b3PogoJoint_GetRestLength( b3JointId jointId )
|
|||
void b3PogoJoint_SetSpringHertz( b3JointId jointId, float hertz )
|
||||
{
|
||||
B3_ASSERT( b3IsValidFloat( hertz ) && hertz >= 0.0f );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
if ( joint->pogoJoint.hertz == hertz )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
b3World* world = b3GetWorld( jointId.world0 );
|
||||
B3_REC( world, PogoJointSetSpringHertz, jointId, hertz );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
joint->pogoJoint.hertz = hertz;
|
||||
}
|
||||
|
||||
|
|
@ -48,9 +58,14 @@ float b3PogoJoint_GetSpringHertz( b3JointId jointId )
|
|||
void b3PogoJoint_SetSpringDampingRatio( b3JointId jointId, float dampingRatio )
|
||||
{
|
||||
B3_ASSERT( b3IsValidFloat( dampingRatio ) && dampingRatio >= 0.0f );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
if ( joint->pogoJoint.dampingRatio == dampingRatio )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
b3World* world = b3GetWorld( jointId.world0 );
|
||||
B3_REC( world, PogoJointSetSpringDampingRatio, jointId, dampingRatio );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
joint->pogoJoint.dampingRatio = dampingRatio;
|
||||
}
|
||||
|
||||
|
|
@ -63,9 +78,14 @@ float b3PogoJoint_GetSpringDampingRatio( b3JointId jointId )
|
|||
void b3PogoJoint_SetMaxTensionForce( b3JointId jointId, float force )
|
||||
{
|
||||
B3_ASSERT( b3IsValidFloat( force ) && force >= 0.0f );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
if ( joint->pogoJoint.maxTensionForce == force )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
b3World* world = b3GetWorld( jointId.world0 );
|
||||
B3_REC( world, PogoJointSetMaxTensionForce, jointId, force );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
joint->pogoJoint.maxTensionForce = force;
|
||||
}
|
||||
|
||||
|
|
@ -78,9 +98,14 @@ float b3PogoJoint_GetMaxTensionForce(b3JointId jointId)
|
|||
void b3PogoJoint_SetMaxCompressionForce(b3JointId jointId, float force)
|
||||
{
|
||||
B3_ASSERT( b3IsValidFloat( force ) && force >= 0.0f );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
if ( joint->pogoJoint.maxCompressionForce == force )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
b3World* world = b3GetWorld( jointId.world0 );
|
||||
B3_REC( world, PogoJointSetMaxCompressionForce, jointId, force );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
joint->pogoJoint.maxCompressionForce = force;
|
||||
}
|
||||
|
||||
|
|
@ -93,9 +118,15 @@ float b3PogoJoint_GetMaxCompressionForce(b3JointId jointId)
|
|||
void b3PogoJoint_SetNormal( b3JointId jointId, b3Vec3 normal )
|
||||
{
|
||||
B3_ASSERT( b3IsValidVec3( normal ) && b3IsNormalized( normal ) );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
b3Vec3 current = joint->pogoJoint.normal;
|
||||
if ( current.x == normal.x && current.y == normal.y && current.z == normal.z )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
b3World* world = b3GetWorld( jointId.world0 );
|
||||
B3_REC( world, PogoJointSetNormal, jointId, normal );
|
||||
b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint );
|
||||
joint->pogoJoint.normal = normal;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue