stop overriding mass when setting motion locks

This commit is contained in:
Erin Catto 2026-11-17 22:50:41 -08:00
commit 6357bf521a
10 changed files with 253 additions and 142 deletions

View file

@ -500,7 +500,8 @@ int b3Body_GetContactData( b3BodyId bodyId, b3ContactData* contactData, int capa
b3Shape* shapeA = b3Array_Get( world->shapes, contact->shapeIdA );
b3Shape* shapeB = b3Array_Get( world->shapes, contact->shapeIdB );
contactData[index].contactId = (b3ContactId){ contact->contactId + 1, bodyId.world0, 0, contact->generation };
contactData[index].contactId =
(b3ContactId){ contact->contactId + 1, bodyId.world0, 0, contact->generation };
contactData[index].shapeIdA = (b3ShapeId){ shapeA->id + 1, bodyId.world0, shapeA->generation };
contactData[index].shapeIdB = (b3ShapeId){ shapeB->id + 1, bodyId.world0, shapeB->generation };
contactData[index].manifolds = contact->manifolds;
@ -593,8 +594,8 @@ float b3Body_GetClosestPoint( b3BodyId bodyId, b3Vec3* result, b3Vec3 target )
return closestDistance;
}
b3BodyCastResult b3Body_CastRay( b3BodyId bodyId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter, float maxFraction,
b3WorldTransform bodyTransform )
b3BodyCastResult b3Body_CastRay( b3BodyId bodyId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter,
float maxFraction, b3WorldTransform bodyTransform )
{
b3World* world = b3GetUnlockedWorld( bodyId.world0 );
if ( world == NULL )
@ -660,7 +661,8 @@ b3BodyCastResult b3Body_CastRay( b3BodyId bodyId, b3Pos origin, b3Vec3 translati
}
b3BodyCastResult b3Body_CastShape( b3BodyId bodyId, b3Pos origin, const b3ShapeProxy* proxy, b3Vec3 translation,
b3QueryFilter filter, float maxFraction, bool canEncroach, b3WorldTransform bodyTransform )
b3QueryFilter filter, float maxFraction, bool canEncroach,
b3WorldTransform bodyTransform )
{
b3World* world = b3GetUnlockedWorld( bodyId.world0 );
if ( world == NULL )
@ -757,8 +759,8 @@ bool b3Body_OverlapShape( b3BodyId bodyId, b3Pos origin, const b3ShapeProxy* pro
return false;
}
int b3Body_CollideMover( b3BodyId bodyId, b3BodyPlaneResult* bodyPlanes, int planeCapacity, b3Pos origin, const b3Capsule* mover,
b3QueryFilter filter, b3WorldTransform bodyTransform )
int b3Body_CollideMover( b3BodyId bodyId, b3BodyPlaneResult* bodyPlanes, int planeCapacity, b3Pos origin,
const b3Capsule* mover, b3QueryFilter filter, b3WorldTransform bodyTransform )
{
b3World* world = b3GetUnlockedWorld( bodyId.world0 );
if ( world == NULL )
@ -811,8 +813,9 @@ int b3Body_CollideMover( b3BodyId bodyId, b3BodyPlaneResult* bodyPlanes, int pla
return resultCount;
}
b3BodyTOIResult b3Body_TimeOfImpactMover( b3BodyId bodyId, b3Pos origin, const b3Capsule* mover, b3Vec3 moverTranslation,
b3QueryFilter filter, b3WorldTransform bodyTransform1, b3WorldTransform bodyTransform2 )
b3BodyTOIResult b3Body_TimeOfImpactMover( b3BodyId bodyId, b3Pos origin, const b3Capsule* mover,
b3Vec3 moverTranslation, b3QueryFilter filter,
b3WorldTransform bodyTransform1, b3WorldTransform bodyTransform2 )
{
b3BodyTOIResult result = { 0 };
result.fraction = 1.0f;
@ -874,7 +877,7 @@ b3BodyTOIResult b3Body_TimeOfImpactMover( b3BodyId bodyId, b3Pos origin, const b
B3_VALIDATE( output.state != b3_toiStateUnknown );
// Mimic behavior in b3ContinuousQueryCallback. Ignore shapes that initially overlap.
if (0.0f < output.fraction && output.fraction < result.fraction)
if ( 0.0f < output.fraction && output.fraction < result.fraction )
{
input.maxFraction = output.fraction;
@ -911,7 +914,8 @@ static void b3UpdateIsotropicInertia( b3World* world, b3Body* body, b3BodySim* b
float tolerance = world->isotropicInertiaTolerance;
if ( 2.0f * deviation > 3.0f * tolerance * tolerance * mean * mean )
bool fixedRotation = ( body->flags & b3_fixedRotation ) == b3_fixedRotation;
if ( fixedRotation == false && 2.0f * deviation > 3.0f * tolerance * tolerance * mean * mean )
{
body->flags |= b3_enableGyroscopicTorque;
}
@ -923,6 +927,27 @@ static void b3UpdateIsotropicInertia( b3World* world, b3Body* body, b3BodySim* b
b3SyncBodyFlags( world, body );
}
static void b3UpdateInverseInertia( b3BodySim* bodySim )
{
float det = b3Det( bodySim->inertia );
B3_ASSERT( det >= 0.0f );
if ( det > 0.0f && ( bodySim->flags & b3_fixedRotation ) != b3_fixedRotation )
{
// This call is faster than b3Invert
bodySim->invInertiaLocal = b3InvertT( bodySim->inertia );
b3Matrix3 rotationMatrix = b3MakeMatrixFromQuat( bodySim->transform.q );
bodySim->invInertiaWorld =
b3MulMM( b3MulMM( rotationMatrix, bodySim->invInertiaLocal ), b3Transpose( rotationMatrix ) );
}
else
{
bodySim->invInertiaLocal = b3Mat3_zero;
bodySim->invInertiaWorld = b3Mat3_zero;
}
}
void b3UpdateBodyMassData( b3World* world, b3Body* body )
{
b3BodySim* bodySim = b3GetBodySim( world, body );
@ -1024,17 +1049,7 @@ void b3UpdateBodyMassData( b3World* world, b3Body* body )
b3StackFree( &world->stack, masses );
masses = NULL;
float det = b3Det( bodySim->inertia );
B3_ASSERT( det >= 0.0f );
if ( det > 0.0f )
{
// This call is faster than b3Invert
bodySim->invInertiaLocal = b3InvertT( bodySim->inertia );
b3Matrix3 rotationMatrix = b3MakeMatrixFromQuat( bodySim->transform.q );
bodySim->invInertiaWorld = b3MulMM( b3MulMM( rotationMatrix, bodySim->invInertiaLocal ), b3Transpose( rotationMatrix ) );
}
b3UpdateInverseInertia( bodySim );
// Move center of mass.
b3Pos oldCenter = bodySim->center;
@ -1076,14 +1091,6 @@ void b3UpdateBodyMassData( b3World* world, b3Body* body )
edgeKey = contact->edges[edgeIndex].nextKey;
}
// Apply fixed rotation
if ( ( bodySim->flags & b3_fixedRotation ) == b3_fixedRotation )
{
bodySim->inertia = b3Mat3_zero;
bodySim->invInertiaLocal = b3Mat3_zero;
bodySim->invInertiaWorld = b3Mat3_zero;
}
b3UpdateIsotropicInertia( world, body, bodySim );
}
@ -1160,7 +1167,8 @@ void b3Body_SetTransform( b3BodyId bodyId, b3Pos position, b3Quat rotation )
bodySim->center = b3TransformWorldPoint( bodySim->transform, bodySim->localCenter );
b3Matrix3 rotationMatrix = b3MakeMatrixFromQuat( bodySim->transform.q );
bodySim->invInertiaWorld = b3MulMM( b3MulMM( rotationMatrix, bodySim->invInertiaLocal ), b3Transpose( rotationMatrix ) );
bodySim->invInertiaWorld =
b3MulMM( b3MulMM( rotationMatrix, bodySim->invInertiaLocal ), b3Transpose( rotationMatrix ) );
bodySim->rotation0 = bodySim->transform.q;
bodySim->center0 = bodySim->center;
@ -1926,31 +1934,7 @@ void b3Body_SetMassData( b3BodyId bodyId, b3MassData massData )
state->linearVelocity = b3Add( state->linearVelocity, deltaLinear );
}
float det = b3Det( bodySim->inertia );
B3_ASSERT( det >= 0.0f );
if ( det > 0.0f )
{
// This call is faster than b3Invert
bodySim->invInertiaLocal = b3InvertT( bodySim->inertia );
b3Matrix3 rotationMatrix = b3MakeMatrixFromQuat( bodySim->transform.q );
bodySim->invInertiaWorld = b3MulMM( b3MulMM( rotationMatrix, bodySim->invInertiaLocal ), b3Transpose( rotationMatrix ) );
}
else
{
bodySim->invInertiaLocal = b3Mat3_zero;
bodySim->invInertiaWorld = b3Mat3_zero;
}
// Apply fixed rotation
if ( ( bodySim->flags & b3_fixedRotation ) == b3_fixedRotation )
{
bodySim->inertia = b3Mat3_zero;
bodySim->invInertiaLocal = b3Mat3_zero;
bodySim->invInertiaWorld = b3Mat3_zero;
}
b3UpdateInverseInertia( bodySim );
b3UpdateIsotropicInertia( world, body, bodySim );
// Update extents using supplied mass center.
@ -2253,7 +2237,8 @@ void b3Body_Disable( b3BodyId bodyId )
continue;
}
B3_ASSERT( joint->setIndex == set->setIndex || set->setIndex == b3_staticSet || joint->setIndex == b3_staticSet );
B3_ASSERT( joint->setIndex == set->setIndex || set->setIndex == b3_staticSet ||
joint->setIndex == b3_staticSet );
// Remove joint from island
b3UnlinkJoint( world, joint );
@ -2445,7 +2430,9 @@ void b3Body_SetMotionLocks( b3BodyId bodyId, b3MotionLocks locks )
if ( fixedRotation1 != fixedRotation2 )
{
b3UpdateBodyMassData( world, body );
b3BodySim* bodySim = b3GetBodySim( world, body );
b3UpdateInverseInertia( bodySim );
b3UpdateIsotropicInertia( world, body, bodySim );
}
}

View file

@ -66,12 +66,15 @@ enum b3BodyFlags
b3_enableGyroscopicTorque = 0x00010000,
// All lock flags
b3_allLocks = b3_lockLinearX | b3_lockLinearY | b3_lockLinearZ | b3_lockAngularX | b3_lockAngularY | b3_lockAngularZ,
// If all these flags are set then the body has fixed rotation
b3_fixedRotation = b3_lockAngularX | b3_lockAngularY | b3_lockAngularZ,
// If all these flags are set then the body has fixed translation
b3_fixedTranslation = b3_lockLinearX | b3_lockLinearY | b3_lockLinearZ,
// All lock flags
b3_allLocks = b3_fixedRotation | b3_fixedTranslation,
// These flags are transient per time step. These may be different across b3Body, b3BodySim, and b3BodyState.
b3_bodyTransientFlags = b3_isSpeedCapped | b3_hadTimeOfImpact,
};

View file

@ -449,20 +449,28 @@ void b3SolveSphericalJoint( b3JointSim* base, b3StepContext* context, bool useBi
void b3SolveWeldJoint( b3JointSim* base, b3StepContext* context, bool useBias );
void b3SolveWheelJoint( b3JointSim* base, b3StepContext* context, bool useBias );
void b3DrawDistanceJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB );
void b3DrawDistanceJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA,
b3WorldTransform transformB );
void b3DrawMoverJoint( b3DebugDraw* draw, b3World* world, b3JointSim* base, b3WorldTransform transformA,
b3WorldTransform transformB );
void b3DrawPogoJoint( b3DebugDraw* draw, b3World* world, b3JointSim* base, b3WorldTransform transformA,
b3WorldTransform transformB, float scale );
void b3DrawParallelJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale );
void b3DrawPrismaticJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale );
void b3DrawRevoluteJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale );
void b3DrawSphericalJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale );
void b3DrawWeldJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale );
void b3DrawWheelJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale );
void b3DrawParallelJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB,
float scale );
void b3DrawPrismaticJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA,
b3WorldTransform transformB, float scale );
void b3DrawRevoluteJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB,
float scale );
void b3DrawSphericalJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA,
b3WorldTransform transformB, float scale );
void b3DrawWeldJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB,
float scale );
void b3DrawWheelJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB,
float scale );
// K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)]
static inline b3Vec3 b3SolvePointConstraint( float mA, float mB, b3Matrix3 iA, b3Matrix3 iB, b3Vec3 rA, b3Vec3 rB, b3Vec3 rhs )
static inline b3Vec3 b3SolvePointConstraint( float mA, float mB, b3Matrix3 iA, b3Matrix3 iB, b3Vec3 rA, b3Vec3 rB,
b3Vec3 rhs )
{
float axy = rA.z * iA.cy.y - rA.y * iA.cz.y;
float axz = rA.z * iA.cy.z - rA.y * iA.cz.z;

View file

@ -355,7 +355,8 @@ static inline b3Manifold* b3AllocateManifolds( b3World* world, int count )
int index = count - 1;
// Need lock because this is called from the parallel narrow phase
// Need lock because this is called from the parallel narrow phase.
// todo use atomic?
b3LockMutex( world->manifoldAllocatorMutex );
int currentCount = world->manifoldAllocators.count;
for ( int i = currentCount; i < count; ++i )

View file

@ -5,9 +5,9 @@
#include "joint.h"
#include "math_internal.h"
#include "physics_world.h"
#include "recording.h"
#include "solver.h"
#include "solver_set.h"
#include "recording.h"
// needed for dll export
#include "box3d/box3d.h"
@ -240,10 +240,10 @@ b3Vec3 b3GetRevoluteJointTorque( b3World* world, b3JointSim* base )
b3Quat relQ = b3InvMulQuat( joint->frameA.q, joint->frameB.q );
// These are needed for warm starting
joint->perpAxisX = b3MulSV(
0.5f, b3RotateVector( joint->frameA.q, b3Add( b3MulSV( relQ.s, b3Vec3_axisX ), b3Cross( relQ.v, b3Vec3_axisX ) ) ) );
joint->perpAxisY = b3MulSV(
0.5f, b3RotateVector( joint->frameA.q, b3Add( b3MulSV( relQ.s, b3Vec3_axisY ), b3Cross( relQ.v, b3Vec3_axisY ) ) ) );
joint->perpAxisX = b3MulSV( 0.5f, b3RotateVector( joint->frameA.q, b3Add( b3MulSV( relQ.s, b3Vec3_axisX ),
b3Cross( relQ.v, b3Vec3_axisX ) ) ) );
joint->perpAxisY = b3MulSV( 0.5f, b3RotateVector( joint->frameA.q, b3Add( b3MulSV( relQ.s, b3Vec3_axisY ),
b3Cross( relQ.v, b3Vec3_axisY ) ) ) );
float axialImpulse = joint->springImpulse + joint->motorImpulse + joint->lowerImpulse - joint->upperImpulse;
b3Vec3 angularImpulse =
@ -251,8 +251,8 @@ b3Vec3 b3GetRevoluteJointTorque( b3World* world, b3JointSim* base )
angularImpulse = b3MulAdd( angularImpulse, axialImpulse, joint->rotationAxisZ );
// todo add pivot torque
b3Vec3 impulse = b3MulAdd( angularImpulse,
joint->springImpulse + joint->motorImpulse + joint->lowerImpulse - joint->upperImpulse, axis );
b3Vec3 impulse = b3MulAdd(
angularImpulse, joint->springImpulse + joint->motorImpulse + joint->lowerImpulse - joint->upperImpulse, axis );
b3Vec3 torque = b3MulSV( world->inv_h, impulse );
return torque;
}
@ -263,8 +263,8 @@ void b3PrepareRevoluteJoint( b3JointSim* base, b3StepContext* context )
b3World* world = context->world;
b3Body* bodyA = b3Array_Get( world->bodies, base->bodyIdA );
b3Body* bodyB = b3Array_Get( world->bodies, base->bodyIdB );
b3Body* bodyA = b3Array_Get( world->bodies, base->bodyIdA );
b3Body* bodyB = b3Array_Get( world->bodies, base->bodyIdB );
B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet );
b3SolverSet* setA = b3GetFixedSolverSet( world, bodyA->setIndex );
@ -273,8 +273,8 @@ void b3PrepareRevoluteJoint( b3JointSim* base, b3StepContext* context )
int localIndexA = bodyA->localIndex;
int localIndexB = bodyB->localIndex;
b3BodySim* bodySimA = b3Array_Get( setA->bodySims, localIndexA );
b3BodySim* bodySimB = b3Array_Get( setB->bodySims, localIndexB );
b3BodySim* bodySimA = b3Array_Get( setA->bodySims, localIndexA );
b3BodySim* bodySimB = b3Array_Get( setB->bodySims, localIndexB );
base->invMassA = bodySimA->invMass;
base->invMassB = bodySimB->invMass;
@ -312,10 +312,10 @@ void b3PrepareRevoluteJoint( b3JointSim* base, b3StepContext* context )
{
// These are needed for warm starting
joint->perpAxisX = b3MulSV(
0.5f, b3RotateVector( joint->frameA.q, b3Add( b3MulSV( relQ.s, b3Vec3_axisX ), b3Cross( relQ.v, b3Vec3_axisX ) ) ) );
joint->perpAxisY = b3MulSV(
0.5f, b3RotateVector( joint->frameA.q, b3Add( b3MulSV( relQ.s, b3Vec3_axisY ), b3Cross( relQ.v, b3Vec3_axisY ) ) ) );
joint->perpAxisX = b3MulSV( 0.5f, b3RotateVector( joint->frameA.q, b3Add( b3MulSV( relQ.s, b3Vec3_axisX ),
b3Cross( relQ.v, b3Vec3_axisX ) ) ) );
joint->perpAxisY = b3MulSV( 0.5f, b3RotateVector( joint->frameA.q, b3Add( b3MulSV( relQ.s, b3Vec3_axisY ),
b3Cross( relQ.v, b3Vec3_axisY ) ) ) );
}
joint->springSoftness = b3MakeSoft( joint->hertz, joint->dampingRatio, context->h );
@ -432,7 +432,8 @@ void b3SolveRevoluteJoint( b3JointSim* base, b3StepContext* context, bool useBia
float massScale = joint->springSoftness.massScale;
float impulseScale = joint->springSoftness.impulseScale;
float deltaImpulse = -massScale * joint->axialMass * ( axialCdot + bias ) - impulseScale * joint->springImpulse;
float deltaImpulse =
-massScale * joint->axialMass * ( axialCdot + bias ) - impulseScale * joint->springImpulse;
joint->springImpulse += deltaImpulse;
axialCdot += k * deltaImpulse;
@ -444,7 +445,8 @@ void b3SolveRevoluteJoint( b3JointSim* base, b3StepContext* context, bool useBia
float cdot = axialCdot - joint->motorSpeed;
float oldImpulse = joint->motorImpulse;
float maxImpulse = joint->maxMotorTorque * context->h;
float deltaImpulse = b3ClampFloat( -joint->axialMass * cdot, -maxImpulse - oldImpulse, maxImpulse - oldImpulse );
float deltaImpulse =
b3ClampFloat( -joint->axialMass * cdot, -maxImpulse - oldImpulse, maxImpulse - oldImpulse );
joint->motorImpulse = oldImpulse + deltaImpulse;
axialCdot += k * deltaImpulse;
@ -476,8 +478,8 @@ void b3SolveRevoluteJoint( b3JointSim* base, b3StepContext* context, bool useBia
}
float oldImpulse = joint->lowerImpulse;
float deltaImpulse =
b3MaxFloat( -massScale * joint->axialMass * ( axialCdot + bias ) - impulseScale * oldImpulse, -oldImpulse );
float deltaImpulse = b3MaxFloat(
-massScale * joint->axialMass * ( axialCdot + bias ) - impulseScale * oldImpulse, -oldImpulse );
joint->lowerImpulse = oldImpulse + deltaImpulse;
axialCdot += k * deltaImpulse;
@ -505,8 +507,8 @@ void b3SolveRevoluteJoint( b3JointSim* base, b3StepContext* context, bool useBia
// sign flipped on Cdot
float cdot = -axialCdot;
float oldImpulse = joint->upperImpulse;
float deltaImpulse =
b3MaxFloat( -massScale * joint->axialMass * ( cdot + bias ) - impulseScale * oldImpulse, -oldImpulse );
float deltaImpulse = b3MaxFloat(
-massScale * joint->axialMass * ( cdot + bias ) - impulseScale * oldImpulse, -oldImpulse );
joint->upperImpulse = oldImpulse + deltaImpulse;
// sign flipped on applied impulse
@ -534,10 +536,10 @@ void b3SolveRevoluteJoint( b3JointSim* base, b3StepContext* context, bool useBia
}
// Collinearity constraint as 2-by-2
b3Vec3 perpAxisX =
b3MulSV( 0.5f, b3RotateVector( quatA, b3Add( b3MulSV( relQ.s, b3Vec3_axisX ), b3Cross( relQ.v, b3Vec3_axisX ) ) ) );
b3Vec3 perpAxisY =
b3MulSV( 0.5f, b3RotateVector( quatA, b3Add( b3MulSV( relQ.s, b3Vec3_axisY ), b3Cross( relQ.v, b3Vec3_axisY ) ) ) );
b3Vec3 perpAxisX = b3MulSV(
0.5f, b3RotateVector( quatA, b3Add( b3MulSV( relQ.s, b3Vec3_axisX ), b3Cross( relQ.v, b3Vec3_axisX ) ) ) );
b3Vec3 perpAxisY = b3MulSV(
0.5f, b3RotateVector( quatA, b3Add( b3MulSV( relQ.s, b3Vec3_axisY ), b3Cross( relQ.v, b3Vec3_axisY ) ) ) );
joint->perpAxisX = perpAxisX;
joint->perpAxisY = perpAxisY;
@ -606,22 +608,29 @@ void b3SolveRevoluteJoint( b3JointSim* base, b3StepContext* context, bool useBia
}
}
void b3DrawRevoluteJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale )
void b3DrawRevoluteJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB,
float scale )
{
b3WorldTransform frameA = b3MulWorldTransforms( transformA, base->localFrameA );
float length1 = 0.1f * scale;
draw->DrawSegmentFcn( frameA.p, b3OffsetPos( frameA.p, b3MulSV( length1, b3RotateVector( frameA.q, b3Vec3_axisX ) ) ), b3_colorRed,
draw->context );
draw->DrawSegmentFcn( frameA.p, b3OffsetPos( frameA.p, b3MulSV( length1, b3RotateVector( frameA.q, b3Vec3_axisY ) ) ), b3_colorGreen,
draw->context );
draw->DrawSegmentFcn( frameA.p, b3OffsetPos( frameA.p, b3MulSV( length1, b3RotateVector( frameA.q, b3Vec3_axisZ ) ) ), b3_colorBlue,
draw->context );
draw->DrawSegmentFcn( frameA.p,
b3OffsetPos( frameA.p, b3MulSV( length1, b3RotateVector( frameA.q, b3Vec3_axisX ) ) ),
b3_colorRed, draw->context );
draw->DrawSegmentFcn( frameA.p,
b3OffsetPos( frameA.p, b3MulSV( length1, b3RotateVector( frameA.q, b3Vec3_axisY ) ) ),
b3_colorGreen, draw->context );
draw->DrawSegmentFcn( frameA.p,
b3OffsetPos( frameA.p, b3MulSV( length1, b3RotateVector( frameA.q, b3Vec3_axisZ ) ) ),
b3_colorBlue, draw->context );
b3WorldTransform frameB = b3MulWorldTransforms( transformB, base->localFrameB );
b3RevoluteJoint* joint = &base->revoluteJoint;
enum { kSliceCount = 16 };
enum
{
kSliceCount = 16
};
// Twist limit
if ( joint->enableLimit )
@ -657,8 +666,8 @@ void b3DrawRevoluteJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform
{
draw->DrawSegmentFcn( b3TransformWorldPoint( frameA, vertex2 ), frameA.p, b3_colorCyan, draw->context );
}
draw->DrawSegmentFcn( b3TransformWorldPoint( frameA, vertex1 ), b3TransformWorldPoint( frameA, vertex2 ), b3_colorCyan,
draw->context );
draw->DrawSegmentFcn( b3TransformWorldPoint( frameA, vertex1 ), b3TransformWorldPoint( frameA, vertex2 ),
b3_colorCyan, draw->context );
}
float twistAngle = b3GetTwistAngle( relQ );