Skip to content

Commit 5b9f690

Browse files
committedFeb 9, 2025·
Improve accuracy of world overlap functions. Also add a tolerance to consider small distances as overlap.
1 parent c902c3c commit 5b9f690

17 files changed

+187
-104
lines changed
 

‎samples/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static void UpdateUI()
519519

520520
ImGui::End();
521521

522-
s_sample->UpdateUI();
522+
s_sample->UpdateGui();
523523
}
524524
}
525525

‎samples/sample.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Sample
4646

4747
void DrawTitle( const char* string );
4848
virtual void Step( Settings& settings );
49-
virtual void UpdateUI()
49+
virtual void UpdateGui()
5050
{
5151
}
5252
virtual void Keyboard( int )

‎samples/sample_benchmark.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class BenchmarkBarrel : public Sample
294294
}
295295
}
296296

297-
void UpdateUI() override
297+
void UpdateGui() override
298298
{
299299
float height = 80.0f;
300300
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -468,7 +468,7 @@ class BenchmarkManyTumblers : public Sample
468468
m_bodyIndex = 0;
469469
}
470470

471-
void UpdateUI() override
471+
void UpdateGui() override
472472
{
473473
float height = 110.0f;
474474
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -1199,7 +1199,7 @@ class BenchmarkCast : public Sample
11991199
m_minTime = 1e6f;
12001200
}
12011201

1202-
void UpdateUI() override
1202+
void UpdateGui() override
12031203
{
12041204
float height = 240.0f;
12051205
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );

‎samples/sample_bodies.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class BodyType : public Sample
183183
}
184184
}
185185

186-
void UpdateUI() override
186+
void UpdateGui() override
187187
{
188188
float height = 140.0f;
189189
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -534,7 +534,7 @@ class Weeble : public Sample
534534
m_explosionMagnitude = 8.0f;
535535
}
536536

537-
void UpdateUI() override
537+
void UpdateGui() override
538538
{
539539
float height = 120.0f;
540540
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -700,7 +700,7 @@ class Sleep : public Sample
700700
}
701701
}
702702

703-
void UpdateUI() override
703+
void UpdateGui() override
704704
{
705705
float height = 100.0f;
706706
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );

‎samples/sample_collision.cpp

+36-16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616

1717
constexpr int SIMPLEX_CAPACITY = 20;
1818

19+
/*
20+
- input 0x0000008f63efcee0 {proxyA={points=0x0000008f63efcee0 {{...}, {...}, {...}, {...}, {...}, {...}, {...}, ...} ...} ...} const b2DistanceInput *
21+
+ [0] {x=-0.400000006 y=-0.400000006 } b2Vec2
22+
+ [1] {x=0.400000006 y=-0.400000006 } b2Vec2
23+
+ [2] {x=0.400000006 y=0.400000006 } b2Vec2
24+
+ [3] {x=-0.400000006 y=0.400000006 } b2Vec2
25+
26+
+ [0] {x=-0.500000000 y=-0.500000000 } b2Vec2
27+
+ [1] {x=0.500000000 y=-0.500000000 } b2Vec2
28+
+ [2] {x=0.500000000 y=0.500000000 } b2Vec2
29+
+ [3] {x=-0.500000000 y=0.500000000 } b2Vec2
30+
31+
+ transformA {p={x=3.00000000 y=5.00000000 } q={c=1.00000000 s=0.00000000 } } b2Transform
32+
+ transformB {p={x=3.00000000 y=5.00000000 } q={c=1.00000000 s=0.00000000 } } b2Transform
33+
useRadii true bool
34+
*/
1935
class ShapeDistance : public Sample
2036
{
2137
public:
@@ -43,11 +59,14 @@ class ShapeDistance : public Sample
4359
b2Vec2 points[3] = { { -0.5f, 0.0f }, { 0.5f, 0.0f }, { 0.0f, 1.0f } };
4460
b2Hull hull = b2ComputeHull( points, 3 );
4561
m_triangle = b2MakePolygon( &hull, 0.0f );
62+
63+
m_triangle = b2MakeSquare( 0.4f );
4664
}
4765

48-
m_box = b2MakeBox( 0.5f, 0.5f );
66+
m_box = b2MakeSquare( 0.5f );
4967

50-
m_transform = { { 1.5f, -1.5f }, b2Rot_identity };
68+
//m_transform = { { 1.5f, -1.5f }, b2Rot_identity };
69+
m_transform = { { 0.0f, 0.0f }, b2Rot_identity };
5170
m_angle = 0.0f;
5271

5372
m_cache = b2_emptySimplexCache;
@@ -90,10 +109,11 @@ class ShapeDistance : public Sample
90109
break;
91110

92111
case e_triangle:
93-
proxy.points[0] = m_triangle.vertices[0];
94-
proxy.points[1] = m_triangle.vertices[1];
95-
proxy.points[2] = m_triangle.vertices[2];
96-
proxy.count = 3;
112+
for (int i = 0; i < m_triangle.count; ++i)
113+
{
114+
proxy.points[i] = m_triangle.vertices[i];
115+
}
116+
proxy.count = m_triangle.count;
97117
break;
98118

99119
case e_box:
@@ -146,19 +166,19 @@ class ShapeDistance : public Sample
146166
break;
147167

148168
case e_triangle:
149-
g_draw.DrawSolidPolygon( transform, m_triangle.vertices, 3, radius, color );
169+
g_draw.DrawSolidPolygon( transform, m_triangle.vertices, m_triangle.count, radius, color );
150170
break;
151171

152172
case e_box:
153-
g_draw.DrawSolidPolygon( transform, m_box.vertices, 4, radius, color );
173+
g_draw.DrawSolidPolygon( transform, m_box.vertices, m_box.count, radius, color );
154174
break;
155175

156176
default:
157177
assert( false );
158178
}
159179
}
160180

161-
void UpdateUI() override
181+
void UpdateGui() override
162182
{
163183
float height = 310.0f;
164184
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -311,7 +331,7 @@ class ShapeDistance : public Sample
311331
input.proxyB = m_proxyB;
312332
input.transformA = b2Transform_identity;
313333
input.transformB = m_transform;
314-
input.useRadii = m_radiusA > 0.0f || m_radiusB > 0.0f;
334+
input.useRadii = true || m_radiusA > 0.0f || m_radiusB > 0.0f;
315335

316336
if ( m_useCache == false )
317337
{
@@ -567,7 +587,7 @@ class DynamicTree : public Sample
567587
}
568588
}
569589

570-
void UpdateUI() override
590+
void UpdateGui() override
571591
{
572592
float height = 320.0f;
573593
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -912,7 +932,7 @@ class RayCast : public Sample
912932
m_showFraction = false;
913933
}
914934

915-
void UpdateUI() override
935+
void UpdateGui() override
916936
{
917937
float height = 230.0f;
918938
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -1580,7 +1600,7 @@ class RayCastWorld : public Sample
15801600
}
15811601
}
15821602

1583-
void UpdateUI() override
1603+
void UpdateGui() override
15841604
{
15851605
float height = 300.0f;
15861606
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -2066,7 +2086,7 @@ class OverlapWorld : public Sample
20662086
}
20672087
}
20682088

2069-
void UpdateUI() override
2089+
void UpdateGui() override
20702090
{
20712091
float height = 330.0f;
20722092
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -2272,7 +2292,7 @@ class Manifold : public Sample
22722292
m_wedge = b2ComputeHull( points, 3 );
22732293
}
22742294

2275-
void UpdateUI() override
2295+
void UpdateGui() override
22762296
{
22772297
float height = 300.0f;
22782298
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -2963,7 +2983,7 @@ class SmoothManifold : public Sample
29632983
free( m_segments );
29642984
}
29652985

2966-
void UpdateUI() override
2986+
void UpdateGui() override
29672987
{
29682988
float height = 290.0f;
29692989
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );

‎samples/sample_continuous.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class BounceHouse : public Sample
119119
}
120120
}
121121

122-
void UpdateUI() override
122+
void UpdateGui() override
123123
{
124124
float height = 100.0f;
125125
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -341,7 +341,7 @@ class ChainDrop : public Sample
341341
//m_shapeId = b2CreatePolygonShape( m_bodyId, &shapeDef, &box );
342342
}
343343

344-
void UpdateUI() override
344+
void UpdateGui() override
345345
{
346346
float height = 140.0f;
347347
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -547,7 +547,7 @@ class SkinnyBox : public Sample
547547
}
548548
}
549549

550-
void UpdateUI() override
550+
void UpdateGui() override
551551
{
552552
float height = 110.0f;
553553
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -816,7 +816,7 @@ class GhostBumps : public Sample
816816
}
817817
}
818818

819-
void UpdateUI() override
819+
void UpdateGui() override
820820
{
821821
float height = 140.0f;
822822
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );

‎samples/sample_determinism.cpp

+58
Original file line numberDiff line numberDiff line change
@@ -613,3 +613,61 @@ class BulletBug : public Sample
613613
};
614614

615615
static int sampleBulletBug = RegisterSample( "Bugs", "Bullet Bug", BulletBug::Create );
616+
617+
bool hit = false;
618+
bool callback( b2ShapeId id, void* context )
619+
{
620+
printf( "hit" );
621+
hit = true;
622+
return false;
623+
}
624+
625+
class OverlapBug : public Sample
626+
{
627+
public:
628+
explicit OverlapBug( Settings& settings )
629+
: Sample( settings )
630+
{
631+
if ( settings.restart == false )
632+
{
633+
g_camera.m_center = { 0.0f, 2.5f };
634+
g_camera.m_zoom = 3.5f;
635+
}
636+
637+
float boxSize = 0.5f;
638+
b2BodyDef body_def = b2DefaultBodyDef();
639+
body_def.type = b2_staticBody;
640+
body_def.position = { x, y };
641+
b2BodyId body_id = b2CreateBody( m_worldId, &body_def );
642+
b2Polygon polygon = b2MakeSquare( boxSize );
643+
b2ShapeDef shape_def = b2DefaultShapeDef();
644+
b2CreatePolygonShape( body_id, &shape_def, &polygon );
645+
}
646+
647+
void Step( Settings& settings ) override
648+
{
649+
Sample::Step( settings );
650+
651+
float testSize = 0.4f;
652+
b2Polygon test_polygon = b2MakeSquare( testSize );
653+
b2Transform tfm = { { x, y }, { 1.0f, 0.0f } };
654+
b2World_OverlapPolygon( m_worldId, &test_polygon, tfm, b2DefaultQueryFilter(), callback, nullptr );
655+
656+
b2Vec2 vertices[4];
657+
vertices[0] = b2TransformPoint(tfm, test_polygon.vertices[0]);
658+
vertices[1] = b2TransformPoint(tfm, test_polygon.vertices[1]);
659+
vertices[2] = b2TransformPoint(tfm, test_polygon.vertices[2]);
660+
vertices[3] = b2TransformPoint(tfm, test_polygon.vertices[3]);
661+
g_draw.DrawPolygon(vertices, 4, b2_colorOrange);
662+
}
663+
664+
static Sample* Create( Settings& settings )
665+
{
666+
return new OverlapBug( settings );
667+
}
668+
669+
float x = 3.0f;
670+
float y = 5.0f;
671+
};
672+
673+
static int sampleSingleBox = RegisterSample( "Bugs", "Overlap", OverlapBug::Create );

‎samples/sample_events.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class SensorFunnel : public Sample
233233
}
234234
}
235235

236-
void UpdateUI() override
236+
void UpdateGui() override
237237
{
238238
float height = 90.0f;
239239
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -398,7 +398,7 @@ class SensorBookend : public Sample
398398
m_visitorShapeId = b2CreateCircleShape( m_visitorBodyId, &shapeDef, &circle );
399399
}
400400

401-
void UpdateUI() override
401+
void UpdateGui() override
402402
{
403403
float height = 160.0f;
404404
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -764,7 +764,7 @@ class ContactEvent : public Sample
764764
}
765765
}
766766

767-
void UpdateUI() override
767+
void UpdateGui() override
768768
{
769769
float height = 60.0f;
770770
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -1199,7 +1199,7 @@ class Platformer : public Sample
11991199
return false;
12001200
}
12011201

1202-
void UpdateUI() override
1202+
void UpdateGui() override
12031203
{
12041204
float height = 100.0f;
12051205
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -1414,7 +1414,7 @@ class BodyMove : public Sample
14141414
}
14151415
}
14161416

1417-
void UpdateUI() override
1417+
void UpdateGui() override
14181418
{
14191419
float height = 100.0f;
14201420
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );

‎samples/sample_joints.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class DistanceJoint : public Sample
112112
}
113113
}
114114

115-
void UpdateUI() override
115+
void UpdateGui() override
116116
{
117117
float height = 240.0f;
118118
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -276,7 +276,7 @@ class MotorJoint : public Sample
276276
m_time = 0.0f;
277277
}
278278

279-
void UpdateUI() override
279+
void UpdateGui() override
280280
{
281281
float height = 140.0f;
282282
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -509,7 +509,7 @@ class RevoluteJoint : public Sample
509509
}
510510
}
511511

512-
void UpdateUI() override
512+
void UpdateGui() override
513513
{
514514
float height = 220.0f;
515515
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -663,7 +663,7 @@ class PrismaticJoint : public Sample
663663
}
664664
}
665665

666-
void UpdateUI() override
666+
void UpdateGui() override
667667
{
668668
float height = 220.0f;
669669
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -814,7 +814,7 @@ class WheelJoint : public Sample
814814
}
815815
}
816816

817-
void UpdateUI() override
817+
void UpdateGui() override
818818
{
819819
float height = 220.0f;
820820
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -995,7 +995,7 @@ class Bridge : public Sample
995995
}
996996
}
997997

998-
void UpdateUI() override
998+
void UpdateGui() override
999999
{
10001000
float height = 80.0f;
10011001
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -1116,7 +1116,7 @@ class BallAndChain : public Sample
11161116
}
11171117
}
11181118

1119-
void UpdateUI() override
1119+
void UpdateGui() override
11201120
{
11211121
float height = 60.0f;
11221122
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -1217,7 +1217,7 @@ class Cantilever : public Sample
12171217
}
12181218
}
12191219

1220-
void UpdateUI() override
1220+
void UpdateGui() override
12211221
{
12221222
float height = 180.0f;
12231223
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -1506,7 +1506,7 @@ class FixedRotation : public Sample
15061506
++index;
15071507
}
15081508

1509-
void UpdateUI() override
1509+
void UpdateGui() override
15101510
{
15111511
float height = 60.0f;
15121512
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -1722,7 +1722,7 @@ class BreakableJoint : public Sample
17221722
m_breakForce = 1000.0f;
17231723
}
17241724

1725-
void UpdateUI() override
1725+
void UpdateGui() override
17261726
{
17271727
float height = 100.0f;
17281728
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -2079,7 +2079,7 @@ class Driving : public Sample
20792079
m_car.Spawn( m_worldId, { 0.0f, 0.0f }, 1.0f, m_hertz, m_dampingRatio, m_torque, nullptr );
20802080
}
20812081

2082-
void UpdateUI() override
2082+
void UpdateGui() override
20832083
{
20842084
float height = 140.0f;
20852085
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -2201,7 +2201,7 @@ class Ragdoll : public Sample
22012201
Human_ApplyRandomAngularImpulse( &m_human, 10.0f );
22022202
}
22032203

2204-
void UpdateUI() override
2204+
void UpdateGui() override
22052205
{
22062206
float height = 140.0f;
22072207
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -2494,7 +2494,7 @@ class ScissorLift : public Sample
24942494
car.Spawn( m_worldId, { 0.0f, y + 2.0f }, 1.0f, 3.0f, 0.7f, 0.0f, nullptr );
24952495
}
24962496

2497-
void UpdateUI() override
2497+
void UpdateGui() override
24982498
{
24992499
float height = 140.0f;
25002500
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );

‎samples/sample_robustness.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class OverlapRecovery : public Sample
274274
assert( bodyIndex == m_bodyCount );
275275
}
276276

277-
void UpdateUI() override
277+
void UpdateGui() override
278278
{
279279
float height = 210.0f;
280280
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );

‎samples/sample_shapes.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ChainShape : public Sample
172172
m_stepCount = 0;
173173
}
174174

175-
void UpdateUI() override
175+
void UpdateGui() override
176176
{
177177
float height = 155.0f;
178178
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -404,7 +404,7 @@ class CompoundShapes : public Sample
404404
}
405405
}
406406

407-
void UpdateUI() override
407+
void UpdateGui() override
408408
{
409409
float height = 100.0f;
410410
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -521,7 +521,7 @@ class ShapeFilter : public Sample
521521
}
522522
}
523523

524-
void UpdateUI() override
524+
void UpdateGui() override
525525
{
526526
float height = 240.0f;
527527
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -855,7 +855,7 @@ class Restitution : public Sample
855855
}
856856
}
857857

858-
void UpdateUI() override
858+
void UpdateGui() override
859859
{
860860
float height = 100.0f;
861861
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -1200,7 +1200,7 @@ class TangentSpeed : public Sample
12001200
m_bodyIds.clear();
12011201
}
12021202

1203-
void UpdateUI() override
1203+
void UpdateGui() override
12041204
{
12051205
float height = 80.0f;
12061206
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -1324,7 +1324,7 @@ class ModifyGeometry : public Sample
13241324
b2Body_ApplyMassFromShapes( bodyId );
13251325
}
13261326

1327-
void UpdateUI() override
1327+
void UpdateGui() override
13281328
{
13291329
float height = 230.0f;
13301330
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -1668,7 +1668,7 @@ class Explosion : public Sample
16681668
m_impulse = 10.0f;
16691669
}
16701670

1671-
void UpdateUI() override
1671+
void UpdateGui() override
16721672
{
16731673
float height = 160.0f;
16741674
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );

‎samples/sample_stacking.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class VerticalStack : public Sample
325325
}
326326
}
327327

328-
void UpdateUI() override
328+
void UpdateGui() override
329329
{
330330
float height = 230.0f;
331331
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );
@@ -670,7 +670,7 @@ class Cliff : public Sample
670670
}
671671
}
672672

673-
void UpdateUI() override
673+
void UpdateGui() override
674674
{
675675
float height = 60.0f;
676676
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );

‎samples/sample_world.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class LargeWorld : public Sample
143143
m_followCar = false;
144144
}
145145

146-
void UpdateUI() override
146+
void UpdateGui() override
147147
{
148148
float height = 160.0f;
149149
ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once );

‎shared/human.c

+31-31
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale,
1515
{
1616
assert( human->isSpawned == false );
1717

18-
for ( int i = 0; i < boneId_count; ++i )
18+
for ( int i = 0; i < bone_count; ++i )
1919
{
2020
human->bones[i].bodyId = b2_nullBodyId;
2121
human->bones[i].jointId = b2_nullJointId;
@@ -62,7 +62,7 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale,
6262

6363
// hip
6464
{
65-
Bone* bone = human->bones + boneId_hip;
65+
Bone* bone = human->bones + bone_hip;
6666
bone->parentIndex = -1;
6767

6868
bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.95f * s }, position );
@@ -80,8 +80,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale,
8080

8181
// torso
8282
{
83-
Bone* bone = human->bones + boneId_torso;
84-
bone->parentIndex = boneId_hip;
83+
Bone* bone = human->bones + bone_torso;
84+
bone->parentIndex = bone_hip;
8585

8686
bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 1.2f * s }, position );
8787
bodyDef.linearDamping = 0.0f;
@@ -119,8 +119,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale,
119119

120120
// head
121121
{
122-
Bone* bone = human->bones + boneId_head;
123-
bone->parentIndex = boneId_torso;
122+
Bone* bone = human->bones + bone_head;
123+
bone->parentIndex = bone_torso;
124124

125125
bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f * s, 1.475f * s }, position );
126126
bodyDef.linearDamping = 0.1f;
@@ -161,8 +161,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale,
161161

162162
// upper left leg
163163
{
164-
Bone* bone = human->bones + boneId_upperLeftLeg;
165-
bone->parentIndex = boneId_hip;
164+
Bone* bone = human->bones + bone_upperLeftLeg;
165+
bone->parentIndex = bone_hip;
166166

167167
bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.775f * s }, position );
168168
bodyDef.linearDamping = 0.0f;
@@ -208,8 +208,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale,
208208

209209
// lower left leg
210210
{
211-
Bone* bone = human->bones + boneId_lowerLeftLeg;
212-
bone->parentIndex = boneId_upperLeftLeg;
211+
Bone* bone = human->bones + bone_lowerLeftLeg;
212+
bone->parentIndex = bone_upperLeftLeg;
213213

214214
bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.475f * s }, position );
215215
bodyDef.linearDamping = 0.0f;
@@ -253,8 +253,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale,
253253

254254
// upper right leg
255255
{
256-
Bone* bone = human->bones + boneId_upperRightLeg;
257-
bone->parentIndex = boneId_hip;
256+
Bone* bone = human->bones + bone_upperRightLeg;
257+
bone->parentIndex = bone_hip;
258258

259259
bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.775f * s }, position );
260260
bodyDef.linearDamping = 0.0f;
@@ -290,8 +290,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale,
290290

291291
// lower right leg
292292
{
293-
Bone* bone = human->bones + boneId_lowerRightLeg;
294-
bone->parentIndex = boneId_upperRightLeg;
293+
Bone* bone = human->bones + bone_lowerRightLeg;
294+
bone->parentIndex = bone_upperRightLeg;
295295

296296
bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.475f * s }, position );
297297
bodyDef.linearDamping = 0.0f;
@@ -335,8 +335,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale,
335335

336336
// upper left arm
337337
{
338-
Bone* bone = human->bones + boneId_upperLeftArm;
339-
bone->parentIndex = boneId_torso;
338+
Bone* bone = human->bones + bone_upperLeftArm;
339+
bone->parentIndex = bone_torso;
340340
bone->frictionScale = 0.5f;
341341

342342
bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 1.225f * s }, position );
@@ -372,8 +372,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale,
372372

373373
// lower left arm
374374
{
375-
Bone* bone = human->bones + boneId_lowerLeftArm;
376-
bone->parentIndex = boneId_upperLeftArm;
375+
Bone* bone = human->bones + bone_lowerLeftArm;
376+
bone->parentIndex = bone_upperLeftArm;
377377

378378
bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.975f * s }, position );
379379
bodyDef.linearDamping = 0.1f;
@@ -410,8 +410,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale,
410410

411411
// upper right arm
412412
{
413-
Bone* bone = human->bones + boneId_upperRightArm;
414-
bone->parentIndex = boneId_torso;
413+
Bone* bone = human->bones + bone_upperRightArm;
414+
bone->parentIndex = bone_torso;
415415

416416
bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 1.225f * s }, position );
417417
bodyDef.linearDamping = 0.0f;
@@ -447,8 +447,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale,
447447

448448
// lower right arm
449449
{
450-
Bone* bone = human->bones + boneId_lowerRightArm;
451-
bone->parentIndex = boneId_upperRightArm;
450+
Bone* bone = human->bones + bone_lowerRightArm;
451+
bone->parentIndex = bone_upperRightArm;
452452

453453
bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.975f * s }, position );
454454
bodyDef.linearDamping = 0.1f;
@@ -490,7 +490,7 @@ void DestroyHuman( Human* human )
490490
{
491491
assert( human->isSpawned == true );
492492

493-
for ( int i = 0; i < boneId_count; ++i )
493+
for ( int i = 0; i < bone_count; ++i )
494494
{
495495
if ( B2_IS_NULL( human->bones[i].jointId ) )
496496
{
@@ -501,7 +501,7 @@ void DestroyHuman( Human* human )
501501
human->bones[i].jointId = b2_nullJointId;
502502
}
503503

504-
for ( int i = 0; i < boneId_count; ++i )
504+
for ( int i = 0; i < bone_count; ++i )
505505
{
506506
if ( B2_IS_NULL( human->bones[i].bodyId ) )
507507
{
@@ -517,7 +517,7 @@ void DestroyHuman( Human* human )
517517

518518
void Human_SetVelocity( Human* human, b2Vec2 velocity )
519519
{
520-
for ( int i = 0; i < boneId_count; ++i )
520+
for ( int i = 0; i < bone_count; ++i )
521521
{
522522
b2BodyId bodyId = human->bones[i].bodyId;
523523

@@ -534,22 +534,22 @@ void Human_ApplyRandomAngularImpulse( Human* human, float magnitude )
534534
{
535535
assert( human->isSpawned == true );
536536
float impulse = RandomFloatRange( -magnitude, magnitude );
537-
b2Body_ApplyAngularImpulse( human->bones[boneId_torso].bodyId, impulse, true );
537+
b2Body_ApplyAngularImpulse( human->bones[bone_torso].bodyId, impulse, true );
538538
}
539539

540540
void Human_SetJointFrictionTorque( Human* human, float torque )
541541
{
542542
assert( human->isSpawned == true );
543543
if ( torque == 0.0f )
544544
{
545-
for ( int i = 1; i < boneId_count; ++i )
545+
for ( int i = 1; i < bone_count; ++i )
546546
{
547547
b2RevoluteJoint_EnableMotor( human->bones[i].jointId, false );
548548
}
549549
}
550550
else
551551
{
552-
for ( int i = 1; i < boneId_count; ++i )
552+
for ( int i = 1; i < bone_count; ++i )
553553
{
554554
b2RevoluteJoint_EnableMotor( human->bones[i].jointId, true );
555555
float scale = human->scale * human->bones[i].frictionScale;
@@ -563,14 +563,14 @@ void Human_SetJointSpringHertz( Human* human, float hertz )
563563
assert( human->isSpawned == true );
564564
if ( hertz == 0.0f )
565565
{
566-
for ( int i = 1; i < boneId_count; ++i )
566+
for ( int i = 1; i < bone_count; ++i )
567567
{
568568
b2RevoluteJoint_EnableSpring( human->bones[i].jointId, false );
569569
}
570570
}
571571
else
572572
{
573-
for ( int i = 1; i < boneId_count; ++i )
573+
for ( int i = 1; i < bone_count; ++i )
574574
{
575575
b2RevoluteJoint_EnableSpring( human->bones[i].jointId, true );
576576
b2RevoluteJoint_SetSpringHertz( human->bones[i].jointId, hertz );
@@ -581,7 +581,7 @@ void Human_SetJointSpringHertz( Human* human, float hertz )
581581
void Human_SetJointDampingRatio( Human* human, float dampingRatio )
582582
{
583583
assert( human->isSpawned == true );
584-
for ( int i = 1; i < boneId_count; ++i )
584+
for ( int i = 1; i < bone_count; ++i )
585585
{
586586
b2RevoluteJoint_SetSpringDampingRatio( human->bones[i].jointId, dampingRatio );
587587
}

‎shared/human.h

+13-13
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77

88
typedef enum BoneId
99
{
10-
boneId_hip = 0,
11-
boneId_torso = 1,
12-
boneId_head = 2,
13-
boneId_upperLeftLeg = 3,
14-
boneId_lowerLeftLeg = 4,
15-
boneId_upperRightLeg = 5,
16-
boneId_lowerRightLeg = 6,
17-
boneId_upperLeftArm = 7,
18-
boneId_lowerLeftArm = 8,
19-
boneId_upperRightArm = 9,
20-
boneId_lowerRightArm = 10,
21-
boneId_count = 11,
10+
bone_hip = 0,
11+
bone_torso = 1,
12+
bone_head = 2,
13+
bone_upperLeftLeg = 3,
14+
bone_lowerLeftLeg = 4,
15+
bone_upperRightLeg = 5,
16+
bone_lowerRightLeg = 6,
17+
bone_upperLeftArm = 7,
18+
bone_lowerLeftArm = 8,
19+
bone_upperRightArm = 9,
20+
bone_lowerRightArm = 10,
21+
bone_count = 11,
2222
} BoneId;
2323

2424
typedef struct Bone
@@ -31,7 +31,7 @@ typedef struct Bone
3131

3232
typedef struct Human
3333
{
34-
Bone bones[boneId_count];
34+
Bone bones[bone_count];
3535
float scale;
3636
bool isSpawned;
3737
} Human;

‎src/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ if (MSVC)
147147
target_compile_options(box2d PRIVATE /arch:AVX2)
148148
endif()
149149

150+
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
151+
target_compile_options(box2d PRIVATE -Wmissing-prototypes)
152+
endif()
153+
150154
elseif (MINGW)
151155
message(STATUS "Box2D on MinGW")
152156
if (BOX2D_AVX2)

‎src/world.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -2073,14 +2073,15 @@ static bool TreeOverlapCallback( int proxyId, int shapeId, void* context )
20732073
b2DistanceInput input;
20742074
input.proxyA = worldContext->proxy;
20752075
input.proxyB = b2MakeShapeDistanceProxy( shape );
2076-
input.transformA = worldContext->transform;
2077-
input.transformB = transform;
2076+
input.transformA = b2Transform_identity;
2077+
input.transformB = b2InvMulTransforms(worldContext->transform, transform);
20782078
input.useRadii = true;
20792079

20802080
b2SimplexCache cache = { 0 };
20812081
b2DistanceOutput output = b2ShapeDistance( &cache, &input, NULL, 0 );
20822082

2083-
if ( output.distance > 0.0f )
2083+
float tolerance = 0.1f * B2_LINEAR_SLOP;
2084+
if ( output.distance > tolerance )
20842085
{
20852086
return true;
20862087
}

0 commit comments

Comments
 (0)
Please sign in to comment.