Skip to content

Commit

Permalink
SIMD rolling resistance
Browse files Browse the repository at this point in the history
  • Loading branch information
erincatto committed Jan 26, 2025
1 parent b6984de commit bdea14c
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 199 deletions.
1 change: 1 addition & 0 deletions samples/car.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void Car::Spawn( b2WorldId worldId, b2Vec2 position, float scale, float hertz, f

shapeDef.density = 2.0f / scale;
shapeDef.friction = 1.5f;
shapeDef.rollingResistance = 0.1f;

bodyDef.position = b2Add( { -1.0f * scale, 0.35f * scale }, position );
bodyDef.allowFastRotation = true;
Expand Down
2 changes: 2 additions & 0 deletions samples/sample_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class BenchmarkBarrel : public Sample
{
m_bodies[index] = b2CreateBody( m_worldId, &bodyDef );
circle.radius = RandomFloatRange( 0.25f, 0.75f );
shapeDef.rollingResistance = 0.2f;
b2CreateCircleShape( m_bodies[index], &shapeDef, &circle );
}
else if ( m_shapeType == e_capsuleShape )
Expand All @@ -230,6 +231,7 @@ class BenchmarkBarrel : public Sample
float length = RandomFloatRange( 0.25f, 1.0f );
capsule.center1 = { 0.0f, -0.5f * length };
capsule.center2 = { 0.0f, 0.5f * length };
shapeDef.rollingResistance = 0.2f;
b2CreateCapsuleShape( m_bodies[index], &shapeDef, &capsule );
}
else if ( m_shapeType == e_mixShape )
Expand Down
8 changes: 4 additions & 4 deletions samples/sample_joints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2072,11 +2072,11 @@ class Driving : public Sample

m_throttle = 0.0f;
m_speed = 35.0f;
m_torque = 2.5f;
m_torque = 5.0f;
m_hertz = 5.0f;
m_dampingRatio = 0.7f;

m_car.Spawn( m_worldId, { 0.0f, 0.0f }, 1.0f, m_hertz, m_dampingRatio, m_torque, NULL );
m_car.Spawn( m_worldId, { 0.0f, 0.0f }, 1.0f, m_hertz, m_dampingRatio, m_torque, nullptr );
}

void UpdateUI() override
Expand All @@ -2103,7 +2103,7 @@ class Driving : public Sample
m_car.SetSpeed( m_throttle * m_speed );
}

if ( ImGui::SliderFloat( "Torque", &m_torque, 0.0f, 5.0f, "%.1f" ) )
if ( ImGui::SliderFloat( "Torque", &m_torque, 0.0f, 10.0f, "%.1f" ) )
{
m_car.SetTorque( m_torque );
}
Expand Down Expand Up @@ -2491,7 +2491,7 @@ class ScissorLift : public Sample
m_liftJointId = b2CreateDistanceJoint( m_worldId, &distanceDef );

Car car;
car.Spawn( m_worldId, { 0.0f, y + 2.0f }, 1.0f, 3.0f, 0.7f, 0.0f, NULL );
car.Spawn( m_worldId, { 0.0f, y + 2.0f }, 1.0f, 3.0f, 0.7f, 0.0f, nullptr );
}

void UpdateUI() override
Expand Down
6 changes: 4 additions & 2 deletions samples/sample_shapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ class RollingResistance : public Sample
}

m_lift = 0.0f;
m_resistScale = 0.02f;
CreateScene();
}

Expand All @@ -990,7 +991,7 @@ class RollingResistance : public Sample
bodyDef.linearVelocity = { 5.0f, 0.0f };

b2BodyId bodyId = b2CreateBody( m_worldId, &bodyDef );
shapeDef.rollingResistance = 0.1f * i;
shapeDef.rollingResistance = m_resistScale * i;
b2CreateCircleShape( bodyId, &shapeDef, &circle );
}
}
Expand Down Expand Up @@ -1029,7 +1030,7 @@ class RollingResistance : public Sample

for ( int i = 0; i < 20; ++i )
{
g_draw.DrawString( { -41.5f, 2.0f * i + 1.0f }, "%.2f", 0.1f * i );
g_draw.DrawString( { -41.5f, 2.0f * i + 1.0f }, "%.2f", m_resistScale * i );
}
}

Expand All @@ -1038,6 +1039,7 @@ class RollingResistance : public Sample
return new RollingResistance( settings );
}

float m_resistScale;
float m_lift;
};

Expand Down
2 changes: 1 addition & 1 deletion src/constraint_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// cause horrible cache stalls. To make this feasible I would need a way to block these writes.

// This is used for debugging by making all constraints be assigned to overflow.
#define B2_FORCE_OVERFLOW 1
#define B2_FORCE_OVERFLOW 0

_Static_assert( B2_GRAPH_COLOR_COUNT == 12, "graph color count assumed to be 12" );

Expand Down
Loading

0 comments on commit bdea14c

Please sign in to comment.