Set mass data consistent velocity (#45)
- Rename b3Body_GetWorldCenterOfMass to b3Body_GetWorldCenter. - Rename b3Body_GetLocalCenterOfMass to b3Body_GetLocalCenter. - Fixed b3Body_SetMassData to correct velocity when local center moves.
This commit is contained in:
parent
1bec63c9ee
commit
0f6fdad541
14 changed files with 94 additions and 30 deletions
|
|
@ -2292,7 +2292,7 @@ void CharacterMover::SolveMove( float timeStep, b3Vec3 forward, b3Vec3 right, b3
|
|||
float invMassB = b3Body_GetInverseMass( bodyId );
|
||||
b3Matrix3 invIB = b3Body_GetWorldInverseRotationalInertia( bodyId );
|
||||
|
||||
b3Pos pB = b3Body_GetWorldCenterOfMass( bodyId );
|
||||
b3Pos pB = b3Body_GetWorldCenter( bodyId );
|
||||
b3Vec3 rB = b3SubPos( point, pB );
|
||||
|
||||
b3Vec3 rnB = b3Cross( rB, normal );
|
||||
|
|
|
|||
|
|
@ -334,23 +334,37 @@ public:
|
|||
bodyDef.type = b3_dynamicBody;
|
||||
bodyDef.position = { 0.0f, 2.0f, 0.0f };
|
||||
bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisX, -0.5f * B3_PI );
|
||||
bodyDef.angularVelocity = { 0.01f, 0.01f, 10.0f };
|
||||
bodyDef.gravityScale = 0.0f;
|
||||
b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
m_bodyId = b3CreateBody( m_worldId, &bodyDef );
|
||||
|
||||
b3ShapeDef shapeDef = b3DefaultShapeDef();
|
||||
shapeDef.updateBodyMass = false;
|
||||
b3HullData* cylinder = b3CreateCylinder( 0.6f, 0.15f, 0.0f, 32 );
|
||||
b3BoxHull box = b3MakeBoxHull( 1.0f, 0.05f, 0.1f );
|
||||
b3CreateHullShape( bodyId, &shapeDef, cylinder );
|
||||
b3CreateHullShape( bodyId, &shapeDef, &box.base );
|
||||
b3CreateHullShape( m_bodyId, &shapeDef, cylinder );
|
||||
b3CreateHullShape( m_bodyId, &shapeDef, &box.base );
|
||||
b3Body_ApplyMassFromShapes( m_bodyId );
|
||||
|
||||
// Set the angular velocity after creating the shapes and the local center of mass is fixed.
|
||||
b3Body_SetAngularVelocity( m_bodyId, { 0.01f, 0.01f, 10.0f } );
|
||||
|
||||
b3DestroyHull( cylinder );
|
||||
}
|
||||
|
||||
void Step() override
|
||||
{
|
||||
Sample::Step();
|
||||
|
||||
b3Pos c = b3Body_GetWorldCenter( m_bodyId );
|
||||
DrawTextLine( "center %.3g %.3g %.3g", c.x, c.y, c.z );
|
||||
}
|
||||
|
||||
static Sample* Create( SampleContext* sampleContext )
|
||||
{
|
||||
return new GyroscopicTorque( sampleContext );
|
||||
}
|
||||
|
||||
b3BodyId m_bodyId;
|
||||
};
|
||||
|
||||
static int sampleGyroscopicTorque = RegisterSample( "Bodies", "Gyroscopic Torque", GyroscopicTorque::Create );
|
||||
|
|
@ -631,7 +645,7 @@ public:
|
|||
{
|
||||
PickRay pickRay = m_camera->BuildPickRay( p.x, p.y );
|
||||
b3Pos origin = pickRay.origin + 10.0f * b3Normalize( pickRay.translation );
|
||||
m_transform.p = m_baseTranslation + b3SubPos(origin, m_origin);
|
||||
m_transform.p = m_baseTranslation + b3SubPos( origin, m_origin );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1249,7 +1249,7 @@ struct RigidbodyCharacter
|
|||
// 3. TryStep — 4-phase step-up
|
||||
m_didStep = TryStep( m_stepUpHeight );
|
||||
|
||||
m_massCenterWorld = b3Body_GetWorldCenterOfMass( m_bodyId );
|
||||
m_massCenterWorld = b3Body_GetWorldCenter( m_bodyId );
|
||||
}
|
||||
|
||||
// --- PostStep: RestoreStep + Reground + CategorizeGround ---
|
||||
|
|
|
|||
|
|
@ -666,7 +666,7 @@ public:
|
|||
continue;
|
||||
}
|
||||
|
||||
b3Pos massCenter = b3Body_GetWorldCenterOfMass( bodyId );
|
||||
b3Pos massCenter = b3Body_GetWorldCenter( bodyId );
|
||||
if ( massCenter.y < -2.0f )
|
||||
{
|
||||
IndexPair pair = ConvertToPair( b3Body_GetUserData( bodyId ) );
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ public:
|
|||
{
|
||||
b3Body_ApplyMassFromShapes( bodyId );
|
||||
|
||||
b3Pos center = b3Body_GetWorldCenterOfMass( bodyId );
|
||||
b3Pos center = b3Body_GetWorldCenter( bodyId );
|
||||
b3Vec3 omega = { 0.0f, 0.0f, -1.0f * velocityScale };
|
||||
b3Vec3 v = b3Cross( omega, b3SubPos( center, b3OffsetPos( b3Pos_zero, origin ) ) );
|
||||
b3Body_SetAngularVelocity( bodyId, omega );
|
||||
|
|
@ -272,7 +272,7 @@ public:
|
|||
b3BoxHull dynamicBox = b3MakeTransformedBoxHull( 0.5f, 10.0f, 0.5f, { { 0.0f, 10.0f, 0.0f }, b3Quat_identity } );
|
||||
b3CreateHullShape( m_bodyId, &shapeDef, &dynamicBox.base );
|
||||
|
||||
b3Pos center = b3Body_GetWorldCenterOfMass( m_bodyId );
|
||||
b3Pos center = b3Body_GetWorldCenter( m_bodyId );
|
||||
|
||||
b3Vec3 r = b3SubPos( pivot, center );
|
||||
float rr = b3LengthSquared( r );
|
||||
|
|
@ -635,7 +635,7 @@ public:
|
|||
if ( B3_IS_NON_NULL( m_contactId ) && b3Contact_IsValid( m_contactId ) )
|
||||
{
|
||||
b3ContactData data = b3Contact_GetData( m_contactId );
|
||||
b3Pos centerOfMass = b3Body_GetWorldCenterOfMass( b3Shape_GetBody( data.shapeIdA ) );
|
||||
b3Pos centerOfMass = b3Body_GetWorldCenter( b3Shape_GetBody( data.shapeIdA ) );
|
||||
|
||||
for ( int i = 0; i < data.manifoldCount; ++i )
|
||||
{
|
||||
|
|
@ -822,7 +822,7 @@ public:
|
|||
{
|
||||
b3BodyId sensorBodyId = b3Shape_GetBody( sensorShapeId );
|
||||
b3WorldTransform t = b3Body_GetTransform( sensorBodyId );
|
||||
t.p = b3Body_GetWorldCenterOfMass( sensorBodyId );
|
||||
t.p = b3Body_GetWorldCenter( sensorBodyId );
|
||||
m_transforms[m_transformCount] = t;
|
||||
m_transformCount += 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1161,7 +1161,7 @@ public:
|
|||
b3Vec3 linearVelocity = b3Body_GetLinearVelocity( m_bodyId );
|
||||
float kineticEnergy = 0.5f * b3Dot( angularVelocity, b3MulMV( massData.inertia, angularVelocity ) );
|
||||
kineticEnergy += 0.5f * massData.mass * b3Dot( linearVelocity, linearVelocity );
|
||||
b3Pos center = b3Body_GetWorldCenterOfMass( m_bodyId );
|
||||
b3Pos center = b3Body_GetWorldCenter( m_bodyId );
|
||||
b3Vec3 gravity = b3World_GetGravity( m_worldId );
|
||||
float potentialEnergy = -massData.mass * center.y * gravity.y;
|
||||
DrawTextLine( "kinetic energy = %g", kineticEnergy );
|
||||
|
|
|
|||
|
|
@ -938,7 +938,7 @@ public:
|
|||
int count = b3Body_GetContactData( body, contacts, capacity );
|
||||
for ( int i = 0; i < count; ++i )
|
||||
{
|
||||
b3Pos originA = b3Body_GetWorldCenterOfMass( b3Shape_GetBody( contacts[i].shapeIdA ) );
|
||||
b3Pos originA = b3Body_GetWorldCenter( b3Shape_GetBody( contacts[i].shapeIdA ) );
|
||||
for ( int m = 0; m < contacts[i].manifoldCount; ++m )
|
||||
{
|
||||
const b3Manifold* manifold = &contacts[i].manifolds[m];
|
||||
|
|
@ -965,7 +965,7 @@ public:
|
|||
}
|
||||
b3BodyId body = b3Shape_GetBody( shape );
|
||||
DrawAxes( b3Body_GetTransform( body ), 0.5f );
|
||||
DrawPoint( b3Body_GetWorldCenterOfMass( body ), 8.0f, MakeColor( b3_colorYellow ) );
|
||||
DrawPoint( b3Body_GetWorldCenter( body ), 8.0f, MakeColor( b3_colorYellow ) );
|
||||
DrawBodyContacts( body );
|
||||
}
|
||||
else if ( m_selKind == SelBody )
|
||||
|
|
@ -976,7 +976,7 @@ public:
|
|||
return;
|
||||
}
|
||||
DrawAxes( b3Body_GetTransform( body ), 0.5f );
|
||||
DrawPoint( b3Body_GetWorldCenterOfMass( body ), 8.0f, MakeColor( b3_colorYellow ) );
|
||||
DrawPoint( b3Body_GetWorldCenter( body ), 8.0f, MakeColor( b3_colorYellow ) );
|
||||
DrawBodyContacts( body );
|
||||
}
|
||||
else if ( m_selKind == SelJoint )
|
||||
|
|
@ -990,11 +990,11 @@ public:
|
|||
b3BodyId b = b3Joint_GetBodyB( joint );
|
||||
if ( b3Body_IsValid( a ) )
|
||||
{
|
||||
DrawPoint( b3Body_GetWorldCenterOfMass( a ), 8.0f, MakeColor( b3_colorMagenta ) );
|
||||
DrawPoint( b3Body_GetWorldCenter( a ), 8.0f, MakeColor( b3_colorMagenta ) );
|
||||
}
|
||||
if ( b3Body_IsValid( b ) )
|
||||
{
|
||||
DrawPoint( b3Body_GetWorldCenterOfMass( b ), 8.0f, MakeColor( b3_colorMagenta ) );
|
||||
DrawPoint( b3Body_GetWorldCenter( b ), 8.0f, MakeColor( b3_colorMagenta ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ public:
|
|||
|
||||
// Height of the top box above the ground, measured in the offset's own frame. This holds
|
||||
// steady at any offset under double precision and drifts once float runs out of resolution.
|
||||
b3Vec3 top = b3SubPos( b3Body_GetWorldCenterOfMass( m_topBodyId ), m_base );
|
||||
b3Vec3 top = b3SubPos( b3Body_GetWorldCenter( m_topBodyId ), m_base );
|
||||
|
||||
DrawTextLine( "double precision: %s", b3IsDoublePrecision() ? "ON" : "OFF" );
|
||||
DrawTextLine( "world offset: %.1f km", m_offsetKilometers );
|
||||
|
|
|
|||
Loading…
Reference in a new issue