diff --git a/samples/main.cpp b/samples/main.cpp index d80c821be..29653264c 100644 --- a/samples/main.cpp +++ b/samples/main.cpp @@ -519,7 +519,7 @@ static void UpdateUI() ImGui::End(); - s_sample->UpdateUI(); + s_sample->UpdateGui(); } } diff --git a/samples/sample.h b/samples/sample.h index 259b88a04..f26bf25f2 100644 --- a/samples/sample.h +++ b/samples/sample.h @@ -46,7 +46,7 @@ class Sample void DrawTitle( const char* string ); virtual void Step( Settings& settings ); - virtual void UpdateUI() + virtual void UpdateGui() { } virtual void Keyboard( int ) diff --git a/samples/sample_benchmark.cpp b/samples/sample_benchmark.cpp index c02dbf64a..54efdbf94 100644 --- a/samples/sample_benchmark.cpp +++ b/samples/sample_benchmark.cpp @@ -294,7 +294,7 @@ class BenchmarkBarrel : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 80.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -468,7 +468,7 @@ class BenchmarkManyTumblers : public Sample m_bodyIndex = 0; } - void UpdateUI() override + void UpdateGui() override { float height = 110.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -1199,7 +1199,7 @@ class BenchmarkCast : public Sample m_minTime = 1e6f; } - void UpdateUI() override + void UpdateGui() override { float height = 240.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); diff --git a/samples/sample_bodies.cpp b/samples/sample_bodies.cpp index 987e0ffa0..ec7dc521d 100644 --- a/samples/sample_bodies.cpp +++ b/samples/sample_bodies.cpp @@ -183,7 +183,7 @@ class BodyType : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 140.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -534,7 +534,7 @@ class Weeble : public Sample m_explosionMagnitude = 8.0f; } - void UpdateUI() override + void UpdateGui() override { float height = 120.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -700,7 +700,7 @@ class Sleep : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 100.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); diff --git a/samples/sample_collision.cpp b/samples/sample_collision.cpp index b4e0b540c..0a0b07eae 100644 --- a/samples/sample_collision.cpp +++ b/samples/sample_collision.cpp @@ -16,6 +16,22 @@ constexpr int SIMPLEX_CAPACITY = 20; +/* +- input 0x0000008f63efcee0 {proxyA={points=0x0000008f63efcee0 {{...}, {...}, {...}, {...}, {...}, {...}, {...}, ...} ...} ...} const b2DistanceInput * ++ [0] {x=-0.400000006 y=-0.400000006 } b2Vec2 ++ [1] {x=0.400000006 y=-0.400000006 } b2Vec2 ++ [2] {x=0.400000006 y=0.400000006 } b2Vec2 ++ [3] {x=-0.400000006 y=0.400000006 } b2Vec2 + ++ [0] {x=-0.500000000 y=-0.500000000 } b2Vec2 ++ [1] {x=0.500000000 y=-0.500000000 } b2Vec2 ++ [2] {x=0.500000000 y=0.500000000 } b2Vec2 ++ [3] {x=-0.500000000 y=0.500000000 } b2Vec2 + ++ transformA {p={x=3.00000000 y=5.00000000 } q={c=1.00000000 s=0.00000000 } } b2Transform ++ transformB {p={x=3.00000000 y=5.00000000 } q={c=1.00000000 s=0.00000000 } } b2Transform + useRadii true bool + */ class ShapeDistance : public Sample { public: @@ -43,11 +59,14 @@ class ShapeDistance : public Sample b2Vec2 points[3] = { { -0.5f, 0.0f }, { 0.5f, 0.0f }, { 0.0f, 1.0f } }; b2Hull hull = b2ComputeHull( points, 3 ); m_triangle = b2MakePolygon( &hull, 0.0f ); + + m_triangle = b2MakeSquare( 0.4f ); } - m_box = b2MakeBox( 0.5f, 0.5f ); + m_box = b2MakeSquare( 0.5f ); - m_transform = { { 1.5f, -1.5f }, b2Rot_identity }; + //m_transform = { { 1.5f, -1.5f }, b2Rot_identity }; + m_transform = { { 0.0f, 0.0f }, b2Rot_identity }; m_angle = 0.0f; m_cache = b2_emptySimplexCache; @@ -90,10 +109,11 @@ class ShapeDistance : public Sample break; case e_triangle: - proxy.points[0] = m_triangle.vertices[0]; - proxy.points[1] = m_triangle.vertices[1]; - proxy.points[2] = m_triangle.vertices[2]; - proxy.count = 3; + for (int i = 0; i < m_triangle.count; ++i) + { + proxy.points[i] = m_triangle.vertices[i]; + } + proxy.count = m_triangle.count; break; case e_box: @@ -146,11 +166,11 @@ class ShapeDistance : public Sample break; case e_triangle: - g_draw.DrawSolidPolygon( transform, m_triangle.vertices, 3, radius, color ); + g_draw.DrawSolidPolygon( transform, m_triangle.vertices, m_triangle.count, radius, color ); break; case e_box: - g_draw.DrawSolidPolygon( transform, m_box.vertices, 4, radius, color ); + g_draw.DrawSolidPolygon( transform, m_box.vertices, m_box.count, radius, color ); break; default: @@ -158,7 +178,7 @@ class ShapeDistance : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 310.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -311,7 +331,7 @@ class ShapeDistance : public Sample input.proxyB = m_proxyB; input.transformA = b2Transform_identity; input.transformB = m_transform; - input.useRadii = m_radiusA > 0.0f || m_radiusB > 0.0f; + input.useRadii = true || m_radiusA > 0.0f || m_radiusB > 0.0f; if ( m_useCache == false ) { @@ -567,7 +587,7 @@ class DynamicTree : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 320.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -912,7 +932,7 @@ class RayCast : public Sample m_showFraction = false; } - void UpdateUI() override + void UpdateGui() override { float height = 230.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -1580,7 +1600,7 @@ class RayCastWorld : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 300.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -2066,7 +2086,7 @@ class OverlapWorld : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 330.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -2272,7 +2292,7 @@ class Manifold : public Sample m_wedge = b2ComputeHull( points, 3 ); } - void UpdateUI() override + void UpdateGui() override { float height = 300.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -2963,7 +2983,7 @@ class SmoothManifold : public Sample free( m_segments ); } - void UpdateUI() override + void UpdateGui() override { float height = 290.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); diff --git a/samples/sample_continuous.cpp b/samples/sample_continuous.cpp index 3d1749e81..551415ae6 100644 --- a/samples/sample_continuous.cpp +++ b/samples/sample_continuous.cpp @@ -119,7 +119,7 @@ class BounceHouse : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 100.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -341,7 +341,7 @@ class ChainDrop : public Sample //m_shapeId = b2CreatePolygonShape( m_bodyId, &shapeDef, &box ); } - void UpdateUI() override + void UpdateGui() override { float height = 140.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -547,7 +547,7 @@ class SkinnyBox : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 110.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -816,7 +816,7 @@ class GhostBumps : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 140.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); diff --git a/samples/sample_determinism.cpp b/samples/sample_determinism.cpp index 86ac9b873..475665afe 100644 --- a/samples/sample_determinism.cpp +++ b/samples/sample_determinism.cpp @@ -613,3 +613,61 @@ class BulletBug : public Sample }; static int sampleBulletBug = RegisterSample( "Bugs", "Bullet Bug", BulletBug::Create ); + +bool hit = false; +bool callback( b2ShapeId id, void* context ) +{ + printf( "hit" ); + hit = true; + return false; +} + +class OverlapBug : public Sample +{ +public: + explicit OverlapBug( Settings& settings ) + : Sample( settings ) + { + if ( settings.restart == false ) + { + g_camera.m_center = { 0.0f, 2.5f }; + g_camera.m_zoom = 3.5f; + } + + float boxSize = 0.5f; + b2BodyDef body_def = b2DefaultBodyDef(); + body_def.type = b2_staticBody; + body_def.position = { x, y }; + b2BodyId body_id = b2CreateBody( m_worldId, &body_def ); + b2Polygon polygon = b2MakeSquare( boxSize ); + b2ShapeDef shape_def = b2DefaultShapeDef(); + b2CreatePolygonShape( body_id, &shape_def, &polygon ); + } + + void Step( Settings& settings ) override + { + Sample::Step( settings ); + + float testSize = 0.4f; + b2Polygon test_polygon = b2MakeSquare( testSize ); + b2Transform tfm = { { x, y }, { 1.0f, 0.0f } }; + b2World_OverlapPolygon( m_worldId, &test_polygon, tfm, b2DefaultQueryFilter(), callback, nullptr ); + + b2Vec2 vertices[4]; + vertices[0] = b2TransformPoint(tfm, test_polygon.vertices[0]); + vertices[1] = b2TransformPoint(tfm, test_polygon.vertices[1]); + vertices[2] = b2TransformPoint(tfm, test_polygon.vertices[2]); + vertices[3] = b2TransformPoint(tfm, test_polygon.vertices[3]); + g_draw.DrawPolygon(vertices, 4, b2_colorOrange); + } + + static Sample* Create( Settings& settings ) + { + return new OverlapBug( settings ); + } + + float x = 3.0f; + float y = 5.0f; +}; + +static int sampleSingleBox = RegisterSample( "Bugs", "Overlap", OverlapBug::Create ); diff --git a/samples/sample_events.cpp b/samples/sample_events.cpp index 4cffd5e13..4a08ea882 100644 --- a/samples/sample_events.cpp +++ b/samples/sample_events.cpp @@ -233,7 +233,7 @@ class SensorFunnel : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 90.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -398,7 +398,7 @@ class SensorBookend : public Sample m_visitorShapeId = b2CreateCircleShape( m_visitorBodyId, &shapeDef, &circle ); } - void UpdateUI() override + void UpdateGui() override { float height = 160.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -764,7 +764,7 @@ class ContactEvent : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 60.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -1199,7 +1199,7 @@ class Platformer : public Sample return false; } - void UpdateUI() override + void UpdateGui() override { float height = 100.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -1414,7 +1414,7 @@ class BodyMove : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 100.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); diff --git a/samples/sample_joints.cpp b/samples/sample_joints.cpp index 3dd06d951..8c2eb28ba 100644 --- a/samples/sample_joints.cpp +++ b/samples/sample_joints.cpp @@ -112,7 +112,7 @@ class DistanceJoint : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 240.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -276,7 +276,7 @@ class MotorJoint : public Sample m_time = 0.0f; } - void UpdateUI() override + void UpdateGui() override { float height = 140.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -509,7 +509,7 @@ class RevoluteJoint : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 220.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -663,7 +663,7 @@ class PrismaticJoint : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 220.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -814,7 +814,7 @@ class WheelJoint : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 220.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -995,7 +995,7 @@ class Bridge : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 80.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -1116,7 +1116,7 @@ class BallAndChain : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 60.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -1217,7 +1217,7 @@ class Cantilever : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 180.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -1506,7 +1506,7 @@ class FixedRotation : public Sample ++index; } - void UpdateUI() override + void UpdateGui() override { float height = 60.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -1722,7 +1722,7 @@ class BreakableJoint : public Sample m_breakForce = 1000.0f; } - void UpdateUI() override + void UpdateGui() override { float height = 100.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -2079,7 +2079,7 @@ class Driving : public Sample m_car.Spawn( m_worldId, { 0.0f, 0.0f }, 1.0f, m_hertz, m_dampingRatio, m_torque, nullptr ); } - void UpdateUI() override + void UpdateGui() override { float height = 140.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -2201,7 +2201,7 @@ class Ragdoll : public Sample Human_ApplyRandomAngularImpulse( &m_human, 10.0f ); } - void UpdateUI() override + void UpdateGui() override { float height = 140.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -2494,7 +2494,7 @@ class ScissorLift : public Sample car.Spawn( m_worldId, { 0.0f, y + 2.0f }, 1.0f, 3.0f, 0.7f, 0.0f, nullptr ); } - void UpdateUI() override + void UpdateGui() override { float height = 140.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); diff --git a/samples/sample_robustness.cpp b/samples/sample_robustness.cpp index 0ae02e6ba..2ee4c319d 100644 --- a/samples/sample_robustness.cpp +++ b/samples/sample_robustness.cpp @@ -274,7 +274,7 @@ class OverlapRecovery : public Sample assert( bodyIndex == m_bodyCount ); } - void UpdateUI() override + void UpdateGui() override { float height = 210.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); diff --git a/samples/sample_shapes.cpp b/samples/sample_shapes.cpp index a24e97c46..af0a188c5 100644 --- a/samples/sample_shapes.cpp +++ b/samples/sample_shapes.cpp @@ -172,7 +172,7 @@ class ChainShape : public Sample m_stepCount = 0; } - void UpdateUI() override + void UpdateGui() override { float height = 155.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -404,7 +404,7 @@ class CompoundShapes : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 100.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -521,7 +521,7 @@ class ShapeFilter : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 240.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -855,7 +855,7 @@ class Restitution : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 100.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -1200,7 +1200,7 @@ class TangentSpeed : public Sample m_bodyIds.clear(); } - void UpdateUI() override + void UpdateGui() override { float height = 80.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -1324,7 +1324,7 @@ class ModifyGeometry : public Sample b2Body_ApplyMassFromShapes( bodyId ); } - void UpdateUI() override + void UpdateGui() override { float height = 230.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -1668,7 +1668,7 @@ class Explosion : public Sample m_impulse = 10.0f; } - void UpdateUI() override + void UpdateGui() override { float height = 160.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); diff --git a/samples/sample_stacking.cpp b/samples/sample_stacking.cpp index 7036b8571..6c5d5e909 100644 --- a/samples/sample_stacking.cpp +++ b/samples/sample_stacking.cpp @@ -325,7 +325,7 @@ class VerticalStack : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 230.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); @@ -670,7 +670,7 @@ class Cliff : public Sample } } - void UpdateUI() override + void UpdateGui() override { float height = 60.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); diff --git a/samples/sample_world.cpp b/samples/sample_world.cpp index b10d8ca63..046ffaa48 100644 --- a/samples/sample_world.cpp +++ b/samples/sample_world.cpp @@ -143,7 +143,7 @@ class LargeWorld : public Sample m_followCar = false; } - void UpdateUI() override + void UpdateGui() override { float height = 160.0f; ImGui::SetNextWindowPos( ImVec2( 10.0f, g_camera.m_height - height - 50.0f ), ImGuiCond_Once ); diff --git a/shared/human.c b/shared/human.c index 5084f261d..b4c7311db 100644 --- a/shared/human.c +++ b/shared/human.c @@ -15,7 +15,7 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, { assert( human->isSpawned == false ); - for ( int i = 0; i < boneId_count; ++i ) + for ( int i = 0; i < bone_count; ++i ) { human->bones[i].bodyId = b2_nullBodyId; human->bones[i].jointId = b2_nullJointId; @@ -62,7 +62,7 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, // hip { - Bone* bone = human->bones + boneId_hip; + Bone* bone = human->bones + bone_hip; bone->parentIndex = -1; bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.95f * s }, position ); @@ -80,8 +80,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, // torso { - Bone* bone = human->bones + boneId_torso; - bone->parentIndex = boneId_hip; + Bone* bone = human->bones + bone_torso; + bone->parentIndex = bone_hip; bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 1.2f * s }, position ); bodyDef.linearDamping = 0.0f; @@ -119,8 +119,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, // head { - Bone* bone = human->bones + boneId_head; - bone->parentIndex = boneId_torso; + Bone* bone = human->bones + bone_head; + bone->parentIndex = bone_torso; bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f * s, 1.475f * s }, position ); bodyDef.linearDamping = 0.1f; @@ -161,8 +161,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, // upper left leg { - Bone* bone = human->bones + boneId_upperLeftLeg; - bone->parentIndex = boneId_hip; + Bone* bone = human->bones + bone_upperLeftLeg; + bone->parentIndex = bone_hip; bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.775f * s }, position ); bodyDef.linearDamping = 0.0f; @@ -208,8 +208,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, // lower left leg { - Bone* bone = human->bones + boneId_lowerLeftLeg; - bone->parentIndex = boneId_upperLeftLeg; + Bone* bone = human->bones + bone_lowerLeftLeg; + bone->parentIndex = bone_upperLeftLeg; bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.475f * s }, position ); bodyDef.linearDamping = 0.0f; @@ -253,8 +253,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, // upper right leg { - Bone* bone = human->bones + boneId_upperRightLeg; - bone->parentIndex = boneId_hip; + Bone* bone = human->bones + bone_upperRightLeg; + bone->parentIndex = bone_hip; bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.775f * s }, position ); bodyDef.linearDamping = 0.0f; @@ -290,8 +290,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, // lower right leg { - Bone* bone = human->bones + boneId_lowerRightLeg; - bone->parentIndex = boneId_upperRightLeg; + Bone* bone = human->bones + bone_lowerRightLeg; + bone->parentIndex = bone_upperRightLeg; bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.475f * s }, position ); bodyDef.linearDamping = 0.0f; @@ -335,8 +335,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, // upper left arm { - Bone* bone = human->bones + boneId_upperLeftArm; - bone->parentIndex = boneId_torso; + Bone* bone = human->bones + bone_upperLeftArm; + bone->parentIndex = bone_torso; bone->frictionScale = 0.5f; bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 1.225f * s }, position ); @@ -372,8 +372,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, // lower left arm { - Bone* bone = human->bones + boneId_lowerLeftArm; - bone->parentIndex = boneId_upperLeftArm; + Bone* bone = human->bones + bone_lowerLeftArm; + bone->parentIndex = bone_upperLeftArm; bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.975f * s }, position ); bodyDef.linearDamping = 0.1f; @@ -410,8 +410,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, // upper right arm { - Bone* bone = human->bones + boneId_upperRightArm; - bone->parentIndex = boneId_torso; + Bone* bone = human->bones + bone_upperRightArm; + bone->parentIndex = bone_torso; bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 1.225f * s }, position ); bodyDef.linearDamping = 0.0f; @@ -447,8 +447,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, // lower right arm { - Bone* bone = human->bones + boneId_lowerRightArm; - bone->parentIndex = boneId_upperRightArm; + Bone* bone = human->bones + bone_lowerRightArm; + bone->parentIndex = bone_upperRightArm; bodyDef.position = b2Add( ( b2Vec2 ){ 0.0f, 0.975f * s }, position ); bodyDef.linearDamping = 0.1f; @@ -490,7 +490,7 @@ void DestroyHuman( Human* human ) { assert( human->isSpawned == true ); - for ( int i = 0; i < boneId_count; ++i ) + for ( int i = 0; i < bone_count; ++i ) { if ( B2_IS_NULL( human->bones[i].jointId ) ) { @@ -501,7 +501,7 @@ void DestroyHuman( Human* human ) human->bones[i].jointId = b2_nullJointId; } - for ( int i = 0; i < boneId_count; ++i ) + for ( int i = 0; i < bone_count; ++i ) { if ( B2_IS_NULL( human->bones[i].bodyId ) ) { @@ -517,7 +517,7 @@ void DestroyHuman( Human* human ) void Human_SetVelocity( Human* human, b2Vec2 velocity ) { - for ( int i = 0; i < boneId_count; ++i ) + for ( int i = 0; i < bone_count; ++i ) { b2BodyId bodyId = human->bones[i].bodyId; @@ -534,7 +534,7 @@ void Human_ApplyRandomAngularImpulse( Human* human, float magnitude ) { assert( human->isSpawned == true ); float impulse = RandomFloatRange( -magnitude, magnitude ); - b2Body_ApplyAngularImpulse( human->bones[boneId_torso].bodyId, impulse, true ); + b2Body_ApplyAngularImpulse( human->bones[bone_torso].bodyId, impulse, true ); } void Human_SetJointFrictionTorque( Human* human, float torque ) @@ -542,14 +542,14 @@ void Human_SetJointFrictionTorque( Human* human, float torque ) assert( human->isSpawned == true ); if ( torque == 0.0f ) { - for ( int i = 1; i < boneId_count; ++i ) + for ( int i = 1; i < bone_count; ++i ) { b2RevoluteJoint_EnableMotor( human->bones[i].jointId, false ); } } else { - for ( int i = 1; i < boneId_count; ++i ) + for ( int i = 1; i < bone_count; ++i ) { b2RevoluteJoint_EnableMotor( human->bones[i].jointId, true ); float scale = human->scale * human->bones[i].frictionScale; @@ -563,14 +563,14 @@ void Human_SetJointSpringHertz( Human* human, float hertz ) assert( human->isSpawned == true ); if ( hertz == 0.0f ) { - for ( int i = 1; i < boneId_count; ++i ) + for ( int i = 1; i < bone_count; ++i ) { b2RevoluteJoint_EnableSpring( human->bones[i].jointId, false ); } } else { - for ( int i = 1; i < boneId_count; ++i ) + for ( int i = 1; i < bone_count; ++i ) { b2RevoluteJoint_EnableSpring( human->bones[i].jointId, true ); b2RevoluteJoint_SetSpringHertz( human->bones[i].jointId, hertz ); @@ -581,7 +581,7 @@ void Human_SetJointSpringHertz( Human* human, float hertz ) void Human_SetJointDampingRatio( Human* human, float dampingRatio ) { assert( human->isSpawned == true ); - for ( int i = 1; i < boneId_count; ++i ) + for ( int i = 1; i < bone_count; ++i ) { b2RevoluteJoint_SetSpringDampingRatio( human->bones[i].jointId, dampingRatio ); } diff --git a/shared/human.h b/shared/human.h index 4a070eaa9..ebdc95461 100644 --- a/shared/human.h +++ b/shared/human.h @@ -7,18 +7,18 @@ typedef enum BoneId { - boneId_hip = 0, - boneId_torso = 1, - boneId_head = 2, - boneId_upperLeftLeg = 3, - boneId_lowerLeftLeg = 4, - boneId_upperRightLeg = 5, - boneId_lowerRightLeg = 6, - boneId_upperLeftArm = 7, - boneId_lowerLeftArm = 8, - boneId_upperRightArm = 9, - boneId_lowerRightArm = 10, - boneId_count = 11, + bone_hip = 0, + bone_torso = 1, + bone_head = 2, + bone_upperLeftLeg = 3, + bone_lowerLeftLeg = 4, + bone_upperRightLeg = 5, + bone_lowerRightLeg = 6, + bone_upperLeftArm = 7, + bone_lowerLeftArm = 8, + bone_upperRightArm = 9, + bone_lowerRightArm = 10, + bone_count = 11, } BoneId; typedef struct Bone @@ -31,7 +31,7 @@ typedef struct Bone typedef struct Human { - Bone bones[boneId_count]; + Bone bones[bone_count]; float scale; bool isSpawned; } Human; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cff1021f2..fd91b956c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -147,6 +147,10 @@ if (MSVC) target_compile_options(box2d PRIVATE /arch:AVX2) endif() + if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") + target_compile_options(box2d PRIVATE -Wmissing-prototypes) + endif() + elseif (MINGW) message(STATUS "Box2D on MinGW") if (BOX2D_AVX2) diff --git a/src/world.c b/src/world.c index 575e297c1..ef5d68d66 100644 --- a/src/world.c +++ b/src/world.c @@ -2073,14 +2073,15 @@ static bool TreeOverlapCallback( int proxyId, int shapeId, void* context ) b2DistanceInput input; input.proxyA = worldContext->proxy; input.proxyB = b2MakeShapeDistanceProxy( shape ); - input.transformA = worldContext->transform; - input.transformB = transform; + input.transformA = b2Transform_identity; + input.transformB = b2InvMulTransforms(worldContext->transform, transform); input.useRadii = true; b2SimplexCache cache = { 0 }; b2DistanceOutput output = b2ShapeDistance( &cache, &input, NULL, 0 ); - if ( output.distance > 0.0f ) + float tolerance = 0.1f * B2_LINEAR_SLOP; + if ( output.distance > tolerance ) { return true; }