Skip to content

Commit

Permalink
Hull validation (#178)
Browse files Browse the repository at this point in the history
sample UI clean up

for #172
  • Loading branch information
erincatto authored Jul 30, 2024
1 parent e71aad9 commit b407b70
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 96 deletions.
2 changes: 2 additions & 0 deletions include/box2d/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ typedef struct b2SmoothSegment
B2_API bool b2IsValidRay(const b2RayCastInput* input);

/// Make a convex polygon from a convex hull. This will assert if the hull is not valid.
/// @warning Do not manually fill in the hull data, it must come directly from b2ComputeHull
B2_API b2Polygon b2MakePolygon(const b2Hull* hull, float radius);

/// Make an offset convex polygon from a convex hull. This will assert if the hull is not valid.
/// @warning Do not manually fill in the hull data, it must come directly from b2ComputeHull
B2_API b2Polygon b2MakeOffsetPolygon(const b2Hull* hull, float radius, b2Transform transform);

/// Make a square polygon, bypassing the need for a convex hull.
Expand Down
32 changes: 19 additions & 13 deletions samples/sample_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ class BenchmarkBarrel : public Sample

void UpdateUI() override
{
float height = 100.0f;
float height = 80.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::Begin("Stacks", nullptr, ImGuiWindowFlags_NoResize);
ImGui::SetNextWindowSize(ImVec2(220.0f, height));
ImGui::Begin("Benchmark: Barrel", nullptr, ImGuiWindowFlags_NoResize);

bool changed = false;
const char* shapeTypes[] = {"Circle", "Capsule", "Mix", "Compound", "Human"};
Expand Down Expand Up @@ -372,10 +372,11 @@ class BenchmarkTumbler : public Sample

void UpdateUI() override
{
float height = 100.0f;
float height = 60.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::Begin("Tumbler", nullptr, ImGuiWindowFlags_NoResize);
ImGui::SetNextWindowSize(ImVec2(200.0f, height));
ImGui::Begin("Benchmark: Tumbler", nullptr, ImGuiWindowFlags_NoResize);
ImGui::PushItemWidth(120.0f);

if (ImGui::SliderFloat("Speed", &m_motorSpeed, 0.0f, 100.0f, "%.f"))
{
Expand All @@ -387,6 +388,7 @@ class BenchmarkTumbler : public Sample
}
}

ImGui::PopItemWidth();
ImGui::End();
}

Expand Down Expand Up @@ -515,10 +517,11 @@ class BenchmarkManyTumblers : public Sample

void UpdateUI() override
{
float height = 120.0f;
float height = 110.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::Begin("Many Tumblers", nullptr, ImGuiWindowFlags_NoResize);
ImGui::SetNextWindowSize(ImVec2(200.0f, height));
ImGui::Begin("Benchmark: Many Tumblers", nullptr, ImGuiWindowFlags_NoResize);
ImGui::PushItemWidth(100.0f);

bool changed = false;
changed = changed || ImGui::SliderInt("Row Count", &m_rowCount, 1, 32);
Expand All @@ -538,6 +541,7 @@ class BenchmarkManyTumblers : public Sample
}
}

ImGui::PopItemWidth();
ImGui::End();
}

Expand Down Expand Up @@ -770,8 +774,9 @@ class BenchmarkManyPyramids : public Sample
{
float height = 160.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::Begin("Stacks", nullptr, ImGuiWindowFlags_NoResize);
ImGui::SetNextWindowSize(ImVec2(200.0f, height));
ImGui::Begin("Benchmark: Many Pyramids", nullptr, ImGuiWindowFlags_NoResize);
ImGui::PushItemWidth(100.0f);

bool changed = false;
changed = changed || ImGui::SliderInt("Row Count", &m_rowCount, 1, 32);
Expand All @@ -786,6 +791,7 @@ class BenchmarkManyPyramids : public Sample
CreateScene();
}

ImGui::PopItemWidth();
ImGui::End();
}

Expand Down Expand Up @@ -1152,10 +1158,10 @@ class BenchmarkJointGrid : public Sample

void UpdateUI() override
{
float height = 100.0f;
float height = 60.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::Begin("Joint Grid", nullptr, ImGuiWindowFlags_NoResize);
ImGui::Begin("Benchmark: Joint Grid", nullptr, ImGuiWindowFlags_NoResize);

if (ImGui::SliderFloat("gravity", &m_gravity, 0.0f, 20.0f, "%.1f"))
{
Expand Down
15 changes: 8 additions & 7 deletions samples/sample_bodies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ class BodyType : public Sample

void UpdateUI() override
{
float height = 150.0f;
float height = 140.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
ImGui::SetNextWindowSize(ImVec2(180.0f, height));
ImGui::Begin("Body Type", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

if (ImGui::RadioButton("Static", m_type == b2_staticBody))
{
Expand Down Expand Up @@ -525,11 +525,10 @@ class Weeble : public Sample

void UpdateUI() override
{
float height = 160.0f;
float height = 120.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::SetNextWindowSize(ImVec2(200.0f, height));
ImGui::Begin("Weeble", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

if (ImGui::Button("Teleport"))
{
b2Body_SetTransform(m_weebleId, {0.0f, 5.0f}, 0.95 * b2_pi);
Expand All @@ -539,9 +538,11 @@ class Weeble : public Sample
{
b2World_Explode(m_worldId, m_explosionPosition, m_explosionRadius, m_explosionMagnitude);
}
ImGui::PushItemWidth(100.0f);

ImGui::SliderFloat("Magnitude", &m_explosionMagnitude, -100.0f, 100.0f, "%.1f");

ImGui::PopItemWidth();
ImGui::End();
}

Expand Down Expand Up @@ -679,7 +680,7 @@ class Sleep : public Sample
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::Begin("Sleep", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

ImGui::PushItemWidth(140.0f);
ImGui::PushItemWidth(120.0f);

ImGui::Text("Pendulum Tuning");

Expand Down
59 changes: 31 additions & 28 deletions samples/sample_collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,13 @@ class DynamicTree : public Sample

void UpdateUI() override
{
float height = 340.0f;
float height = 320.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::SetNextWindowSize(ImVec2(200.0f, height));

ImGui::Begin("Dynamic Tree", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

ImGui::Begin("Tree Controls", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
ImGui::PushItemWidth(100.0f);

bool changed = false;
if (ImGui::SliderInt("rows", &m_rowCount, 0, 1000, "%d"))
Expand Down Expand Up @@ -632,6 +634,7 @@ class DynamicTree : public Sample
ImGui::Text("mouse button 1: ray cast");
ImGui::Text("mouse button 1 + shift: query");

ImGui::PopItemWidth();
ImGui::End();

if (changed)
Expand Down Expand Up @@ -910,17 +913,14 @@ class RayCast : public Sample
{
float height = 230.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::SetNextWindowSize(ImVec2(200.0f, height));

ImGui::Begin("RayCast Controls", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
ImGui::Begin("Ray-cast", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

if (ImGui::SliderFloat("x offset", &m_transform.p.x, -2.0f, 2.0f, "%.2f"))
{
}
ImGui::PushItemWidth(100.0f);

if (ImGui::SliderFloat("y offset", &m_transform.p.y, -2.0f, 2.0f, "%.2f"))
{
}
ImGui::SliderFloat("x offset", &m_transform.p.x, -2.0f, 2.0f, "%.2f");
ImGui::SliderFloat("y offset", &m_transform.p.y, -2.0f, 2.0f, "%.2f");

if (ImGui::SliderFloat("angle", &m_angle, -b2_pi, b2_pi, "%.2f"))
{
Expand All @@ -931,9 +931,8 @@ class RayCast : public Sample
//{
// }

if (ImGui::Checkbox("show fraction", &m_showFraction))
{
}
ImGui::Checkbox("show fraction", &m_showFraction);


if (ImGui::Button("Reset"))
{
Expand All @@ -947,6 +946,8 @@ class RayCast : public Sample
ImGui::Text("mouse btn 1 + shft: translate");
ImGui::Text("mouse btn 1 + ctrl: rotate");

ImGui::PopItemWidth();

ImGui::End();
}

Expand Down Expand Up @@ -1566,9 +1567,9 @@ class RayCastWorld : public Sample
{
float height = 300.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::SetNextWindowSize(ImVec2(200.0f, height));

ImGui::Begin("Options", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
ImGui::Begin("Ray-cast World", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

ImGui::Checkbox("Simple", &m_simple);

Expand Down Expand Up @@ -2051,9 +2052,9 @@ class OverlapWorld : public Sample
{
float height = 330.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::SetNextWindowSize(ImVec2(140.0f, height));

ImGui::Begin("Options", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
ImGui::Begin("Overlap World", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

if (ImGui::Button("Polygon 1"))
Create(0);
Expand Down Expand Up @@ -2256,7 +2257,7 @@ class Manifold : public Sample
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));

ImGui::Begin("Manifold Controls", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
ImGui::Begin("Manifold", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

ImGui::SliderFloat("x offset", &m_transform.p.x, -2.0f, 2.0f, "%.2f");
ImGui::SliderFloat("y offset", &m_transform.p.y, -2.0f, 2.0f, "%.2f");
Expand Down Expand Up @@ -2907,11 +2908,12 @@ class SmoothManifold : public Sample

void UpdateUI() override
{
float height = 270.0f;
float height = 290.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::SetNextWindowSize(ImVec2(180.0f, height));

ImGui::Begin("Smooth Manifold", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
ImGui::PushItemWidth(100.0f);

{
const char* shapeTypes[] = {"Circle", "Box"};
Expand All @@ -2920,18 +2922,18 @@ class SmoothManifold : public Sample
m_shapeType = ShapeType(shapeType);
}

ImGui::SliderFloat("x offset", &m_transform.p.x, -2.0f, 2.0f, "%.2f");
ImGui::SliderFloat("y offset", &m_transform.p.y, -2.0f, 2.0f, "%.2f");
ImGui::SliderFloat("x Offset", &m_transform.p.x, -2.0f, 2.0f, "%.2f");
ImGui::SliderFloat("y Offset", &m_transform.p.y, -2.0f, 2.0f, "%.2f");

if (ImGui::SliderFloat("angle", &m_angle, -b2_pi, b2_pi, "%.2f"))
if (ImGui::SliderFloat("Angle", &m_angle, -b2_pi, b2_pi, "%.2f"))
{
m_transform.q = b2MakeRot(m_angle);
}

ImGui::SliderFloat("round", &m_round, 0.0f, 0.4f, "%.1f");
ImGui::Checkbox("show ids", &m_showIds);
ImGui::Checkbox("show separation", &m_showSeparation);
ImGui::Checkbox("show anchors", &m_showAnchors);
ImGui::SliderFloat("Round", &m_round, 0.0f, 0.4f, "%.1f");
ImGui::Checkbox("Show Ids", &m_showIds);
ImGui::Checkbox("Show Separation", &m_showSeparation);
ImGui::Checkbox("Show Anchors", &m_showAnchors);

if (ImGui::Button("Reset"))
{
Expand All @@ -2944,6 +2946,7 @@ class SmoothManifold : public Sample
ImGui::Text("mouse button 1: drag");
ImGui::Text("mouse button 1 + shift: rotate");

ImGui::PopItemWidth();
ImGui::End();
}

Expand Down
12 changes: 7 additions & 5 deletions samples/sample_continuous.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ class SkinnyBox : public Sample

void UpdateUI() override
{
float height = 130.0f;
float height = 110.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::SetNextWindowSize(ImVec2(140.0f, height));

ImGui::Begin("Options", nullptr, ImGuiWindowFlags_NoResize);
ImGui::Begin("Skinny Box", nullptr, ImGuiWindowFlags_NoResize);

ImGui::Checkbox("Capsule", &m_capsule);

Expand Down Expand Up @@ -603,11 +603,12 @@ class GhostCollision : public Sample

void UpdateUI() override
{
float height = 160.0f;
float height = 140.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::SetNextWindowSize(ImVec2(180.0f, height));

ImGui::Begin("Ghost Collision", nullptr, ImGuiWindowFlags_NoResize);
ImGui::PushItemWidth(100.0f);

if (ImGui::Checkbox("Chain", &m_useChain))
{
Expand Down Expand Up @@ -649,6 +650,7 @@ class GhostCollision : public Sample
Launch();
}

ImGui::PopItemWidth();
ImGui::End();
}

Expand Down
6 changes: 3 additions & 3 deletions samples/sample_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ class SensorEvent : public Sample

void UpdateUI() override
{
float height = 100.0f;
float height = 90.0f;
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));
ImGui::SetNextWindowSize(ImVec2(140.0f, height));

ImGui::Begin("Sensor Event", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

Expand Down Expand Up @@ -445,7 +445,7 @@ class ContactEvent : public Sample
ImGui::SetNextWindowPos(ImVec2(10.0f, g_camera.m_height - height - 50.0f), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(240.0f, height));

ImGui::Begin("Sample Controls", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
ImGui::Begin("Contact Event", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

ImGui::SliderFloat("force", &m_force, 100.0f, 500.0f, "%.1f");

Expand Down
Loading

0 comments on commit b407b70

Please sign in to comment.