Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Box2D.NET.Samples/SampleApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,17 @@ private void OnWindowLoad()
}

{
Span<float> temp1 = stackalloc float[2];
_ctx.gl.GetFloat(GLEnum.AliasedLineWidthRange, temp1);

Span<float> temp2 = stackalloc float[2];
_ctx.gl.GetFloat(GLEnum.SmoothLineWidthRange, temp2);
// Span<float> temp1 = stackalloc float[2];
// _ctx.gl.GetFloat(GLEnum.AliasedLineWidthRange, temp1);
//
// Span<float> temp2 = stackalloc float[2];
// _ctx.gl.GetFloat(GLEnum.SmoothLineWidthRange, temp2);

string glVersionString = _ctx.gl.GetStringS(GLEnum.Version);
string glslVersionString = _ctx.gl.GetStringS(GLEnum.ShadingLanguageVersion);
Logger.Information($"OpenGL {glVersionString}, GLSL {glslVersionString}");
Logger.Information($"OpenGL aliased line width range : [{temp1[0]}, {temp1[1]}]");
Logger.Information($"OpenGL smooth line width range : [{temp2[0]}, {temp2[1]}]");
// Logger.Information($"OpenGL aliased line width range : [{temp1[0]}, {temp1[1]}]");
// Logger.Information($"OpenGL smooth line width range : [{temp2[0]}, {temp2[1]}]");
}

unsafe
Expand Down
10 changes: 3 additions & 7 deletions src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSpinner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ public BenchmarkSpinner(SampleAppContext ctx, Settings settings) : base(ctx, set
m_context.camera.m_zoom = 42.0f;
}

#if DEBUG
b2_toiCalls = 0;
b2_toiHitCount = 0;
#endif
// b2_toiCalls = 0;
// b2_toiHitCount = 0;

CreateSpinner(m_worldId);
}
Expand All @@ -49,8 +47,6 @@ public override void Draw(Settings settings)
{
base.Draw(settings);

#if DEBUG
DrawTextLine($"toi calls, hits = {b2_toiCalls}, {b2_toiHitCount}");
#endif
//DrawTextLine($"toi calls, hits = {b2_toiCalls}, {b2_toiHitCount}");
}
}
9 changes: 2 additions & 7 deletions src/Box2D.NET.Samples/Samples/Continuous/ChainSlide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public ChainSlide(SampleAppContext ctx, Settings settings) : base(ctx, settings)
m_context.camera.m_zoom = 15.0f;
}

#if DEBUG
b2_toiHitCount = 0;
#endif
// b2_toiHitCount = 0;

{
B2BodyDef bodyDef = b2DefaultBodyDef();
Expand Down Expand Up @@ -90,9 +88,6 @@ public override void Draw(Settings settings)
{
base.Draw(settings);

#if DEBUG
m_context.draw.DrawString(5, m_textLine, $"toi hits = {b2_toiHitCount}");
m_textLine += m_textIncrement;
#endif
// m_context.draw.DrawString(5, m_textLine, $"toi hits = {b2_toiHitCount}");
}
}
11 changes: 3 additions & 8 deletions src/Box2D.NET.Samples/Samples/Continuous/SegmentSlide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public SegmentSlide(SampleAppContext ctx, Settings settings) : base(ctx, setting
m_context.camera.m_zoom = 15.0f;
}

#if DEBUG
b2_toiHitCount = 0;
#endif
// b2_toiHitCount = 0;

{
B2BodyDef bodyDef = b2DefaultBodyDef();
Expand All @@ -50,7 +48,7 @@ public SegmentSlide(SampleAppContext ctx, Settings settings) : base(ctx, setting
B2BodyId bodyId = b2CreateBody(m_worldId, ref bodyDef);

B2ShapeDef shapeDef = b2DefaultShapeDef();
//shapeDef.friction = 0.0f;
// shapeDef.friction = 0.0f;
B2Circle circle = new B2Circle(new B2Vec2(0.0f, 0.0f), 0.5f);
b2CreateCircleShape(bodyId, ref shapeDef, ref circle);
}
Expand All @@ -60,9 +58,6 @@ public override void Draw(Settings settings)
{
base.Draw(settings);

#if DEBUG
m_context.draw.DrawString(5, m_textLine, $"toi hits = {b2_toiHitCount}");
m_textLine += m_textIncrement;
#endif
// DrawTextLine($"toi hits = {b2_toiHitCount}");
}
}
10 changes: 3 additions & 7 deletions src/Box2D.NET.Samples/Samples/Shapes/ChainShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,8 @@ void Launch()
m_shapeId = b2CreatePolygonShape(m_bodyId, ref shapeDef, ref box);
}

#if DEBUG
b2_toiCalls = 0;
b2_toiHitCount = 0;
#endif
// b2_toiCalls = 0;
// b2_toiHitCount = 0;

m_stepCount = 0;
}
Expand All @@ -189,9 +187,7 @@ public override void UpdateGui()
m_context.draw.DrawSegment(b2Vec2_zero, new B2Vec2(0.5f, 0.0f), B2HexColor.b2_colorRed);
m_context.draw.DrawSegment(b2Vec2_zero, new B2Vec2(0.0f, 0.5f), B2HexColor.b2_colorGreen);

#if DEBUG
DrawTextLine($"toi calls, hits = {b2_toiCalls}, {b2_toiHitCount}");
#endif
// DrawTextLine($"toi calls, hits = {b2_toiCalls}, {b2_toiHitCount}");

float height = 155.0f;
ImGui.SetNextWindowPos(new Vector2(10.0f, m_context.camera.m_height - height - 50.0f), ImGuiCond.Once);
Expand Down
21 changes: 21 additions & 0 deletions src/Box2D.NET.Shared/Humans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public static void CreateHuman(ref Human human, B2WorldId worldId, B2Vec2 positi

bodyDef.position = b2Add(new B2Vec2(0.0f, 0.95f * s), position);
bodyDef.linearDamping = 0.0f;
bodyDef.name = "hip";

bone.bodyId = b2CreateBody(worldId, ref bodyDef);

if (colorize)
Expand All @@ -98,6 +100,8 @@ public static void CreateHuman(ref Human human, B2WorldId worldId, B2Vec2 positi

bodyDef.position = b2Add(new B2Vec2(0.0f, 1.2f * s), position);
bodyDef.linearDamping = 0.0f;
bodyDef.name = "torso";

// bodyDef.type = b2_staticBody;
bone.bodyId = b2CreateBody(worldId, ref bodyDef);
bone.frictionScale = 0.5f;
Expand Down Expand Up @@ -137,6 +141,7 @@ public static void CreateHuman(ref Human human, B2WorldId worldId, B2Vec2 positi

bodyDef.position = b2Add(new B2Vec2(0.0f * s, 1.475f * s), position);
bodyDef.linearDamping = 0.1f;
bodyDef.name = "head";

bone.bodyId = b2CreateBody(worldId, ref bodyDef);
bone.frictionScale = 0.25f;
Expand Down Expand Up @@ -179,6 +184,8 @@ public static void CreateHuman(ref Human human, B2WorldId worldId, B2Vec2 positi

bodyDef.position = b2Add(new B2Vec2(0.0f, 0.775f * s), position);
bodyDef.linearDamping = 0.0f;
bodyDef.name = "upper_left_leg";

bone.bodyId = b2CreateBody(worldId, ref bodyDef);
bone.frictionScale = 1.0f;

Expand Down Expand Up @@ -225,6 +232,8 @@ public static void CreateHuman(ref Human human, B2WorldId worldId, B2Vec2 positi

bodyDef.position = b2Add(new B2Vec2(0.0f, 0.475f * s), position);
bodyDef.linearDamping = 0.0f;
bodyDef.name = "lower_left_leg";

bone.bodyId = b2CreateBody(worldId, ref bodyDef);
bone.frictionScale = 0.5f;

Expand Down Expand Up @@ -270,6 +279,8 @@ public static void CreateHuman(ref Human human, B2WorldId worldId, B2Vec2 positi

bodyDef.position = b2Add(new B2Vec2(0.0f, 0.775f * s), position);
bodyDef.linearDamping = 0.0f;
bodyDef.name = "upper_right_leg";

bone.bodyId = b2CreateBody(worldId, ref bodyDef);
bone.frictionScale = 1.0f;

Expand Down Expand Up @@ -307,6 +318,8 @@ public static void CreateHuman(ref Human human, B2WorldId worldId, B2Vec2 positi

bodyDef.position = b2Add(new B2Vec2(0.0f, 0.475f * s), position);
bodyDef.linearDamping = 0.0f;
bodyDef.name = "lower_right_leg";

bone.bodyId = b2CreateBody(worldId, ref bodyDef);
bone.frictionScale = 0.5f;

Expand Down Expand Up @@ -353,6 +366,8 @@ public static void CreateHuman(ref Human human, B2WorldId worldId, B2Vec2 positi

bodyDef.position = b2Add(new B2Vec2(0.0f, 1.225f * s), position);
bodyDef.linearDamping = 0.0f;
bodyDef.name = "lower_left_leg";

bone.bodyId = b2CreateBody(worldId, ref bodyDef);

if (colorize)
Expand Down Expand Up @@ -389,6 +404,8 @@ public static void CreateHuman(ref Human human, B2WorldId worldId, B2Vec2 positi

bodyDef.position = b2Add(new B2Vec2(0.0f, 0.975f * s), position);
bodyDef.linearDamping = 0.1f;
bodyDef.name = "lower_left_arm";

bone.bodyId = b2CreateBody(worldId, ref bodyDef);
bone.frictionScale = 0.1f;

Expand Down Expand Up @@ -427,6 +444,8 @@ public static void CreateHuman(ref Human human, B2WorldId worldId, B2Vec2 positi

bodyDef.position = b2Add(new B2Vec2(0.0f, 1.225f * s), position);
bodyDef.linearDamping = 0.0f;
bodyDef.name = "upper_right_arm";

bone.bodyId = b2CreateBody(worldId, ref bodyDef);
bone.frictionScale = 0.5f;

Expand Down Expand Up @@ -464,6 +483,8 @@ public static void CreateHuman(ref Human human, B2WorldId worldId, B2Vec2 positi

bodyDef.position = b2Add(new B2Vec2(0.0f, 0.975f * s), position);
bodyDef.linearDamping = 0.1f;
bodyDef.name = "lower_right_arm";

bone.bodyId = b2CreateBody(worldId, ref bodyDef);
bone.frictionScale = 0.1f;

Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET/B2Bodies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public static B2BodyId b2CreateBody(B2WorldId worldId, ref B2BodyDef def)
}
else
{
body.name = "";
body.name = string.Empty;
}

body.userData = def.userData;
Expand Down
4 changes: 4 additions & 0 deletions src/Box2D.NET/B2Joints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ public static B2JointId b2CreateRevoluteJoint(B2WorldId worldId, ref B2RevoluteJ
public static B2JointId b2CreatePrismaticJoint(B2WorldId worldId, B2PrismaticJointDef def)
{
B2_CHECK_DEF(ref def);
Debug.Assert(def.lowerTranslation <= def.upperTranslation);

B2World world = b2GetWorldFromId(worldId);

Debug.Assert(world.locked == false);
Expand Down Expand Up @@ -672,6 +674,8 @@ public static B2JointId b2CreateWeldJoint(B2WorldId worldId, ref B2WeldJointDef
public static B2JointId b2CreateWheelJoint(B2WorldId worldId, ref B2WheelJointDef def)
{
B2_CHECK_DEF(ref def);
Debug.Assert(def.lowerTranslation <= def.upperTranslation);

B2World world = b2GetWorldFromId(worldId);

Debug.Assert(world.locked == false);
Expand Down
4 changes: 2 additions & 2 deletions src/Box2D.NET/B2Movers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public static B2PlaneSolverResult b2SolvePlanes(B2Vec2 position, Span<B2Collisio
return new B2PlaneSolverResult(b2Add(delta, position), iteration);
}

/// Clips the velocity against the given collision planes. Planes with clipVelocity set to
/// true are skipped.
/// Clips the velocity against the given collision planes. Planes with zero push or clipVelocity
/// set to false are skipped.
public static B2Vec2 b2ClipVector(B2Vec2 vector, Span<B2CollisionPlane> planes, int count)
{
B2Vec2 v = vector;
Expand Down
2 changes: 2 additions & 0 deletions src/Box2D.NET/B2PrismaticJoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public static float b2PrismaticJoint_GetUpperLimit(B2JointId jointId)

public static void b2PrismaticJoint_SetLimits(B2JointId jointId, float lower, float upper)
{
Debug.Assert(lower <= upper);

B2JointSim joint = b2GetJointSimCheckType(jointId, B2JointType.b2_prismaticJoint);
// TODO: @ikpil, check epsilon
if (lower != joint.uj.prismaticJoint.lowerTranslation || upper != joint.uj.prismaticJoint.upperTranslation)
Expand Down
6 changes: 6 additions & 0 deletions src/Box2D.NET/B2RevoluteJoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ public static float b2RevoluteJoint_GetUpperLimit(B2JointId jointId)
return joint.uj.revoluteJoint.upperAngle;
}

/// Set the revolute joint limits in radians. It is expected that lower <= upper
/// and that -0.95 * B2_PI <= lower && upper <= -0.95 * B2_PI.
public static void b2RevoluteJoint_SetLimits(B2JointId jointId, float lower, float upper)
{
Debug.Assert(lower <= upper);
Debug.Assert(lower >= -0.95f * B2_PI);
Debug.Assert(upper <= 0.95f * B2_PI);

B2JointSim joint = b2GetJointSimCheckType(jointId, B2JointType.b2_revoluteJoint);
if (lower != joint.uj.revoluteJoint.lowerAngle || upper != joint.uj.revoluteJoint.upperAngle)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Box2D.NET/B2WheelJoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public static float b2WheelJoint_GetUpperLimit(B2JointId jointId)

public static void b2WheelJoint_SetLimits(B2JointId jointId, float lower, float upper)
{
Debug.Assert(lower <= upper);

B2JointSim joint = b2GetJointSimCheckType(jointId, B2JointType.b2_wheelJoint);
if (lower != joint.uj.wheelJoint.lowerTranslation || upper != joint.uj.wheelJoint.upperTranslation)
{
Expand Down Expand Up @@ -551,4 +553,4 @@ public static void b2DrawWheelJoint(B2DebugDraw draw, B2JointSim @base, B2Transf
draw.DrawPointFcn(pB, 5.0f, c4, draw.context);
}
}
}
}
24 changes: 11 additions & 13 deletions src/Box2D.NET/B2Worlds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,10 +1036,7 @@ public static void b2DrawWithBounds(B2World world, B2DebugDraw draw)
B2BodySim bodySim = b2GetBodySim(world, body);

B2Transform transform = new B2Transform(bodySim.center, bodySim.transform.q);
draw.DrawTransformFcn(transform, draw.context);

B2Vec2 p = b2TransformPoint(ref transform, offset);

draw.DrawStringFcn(p, body.name, B2HexColor.b2_colorBlueViolet, draw.context);
}

Expand Down Expand Up @@ -1332,7 +1329,7 @@ public static void b2World_Draw(B2WorldId worldId, B2DebugDraw draw)

if (draw.drawBodyNames)
{
B2Vec2 offset = new B2Vec2(0.1f, 0.2f);
B2Vec2 offset = new B2Vec2(0.05f, 0.05f);
int count = world.bodies.count;
for (int i = 0; i < count; ++i)
{
Expand All @@ -1347,9 +1344,10 @@ public static void b2World_Draw(B2WorldId worldId, B2DebugDraw draw)
continue;
}

B2Transform transform = b2GetBodyTransformQuick(world, body);
B2BodySim bodySim = b2GetBodySim(world, body);

B2Transform transform = new B2Transform(bodySim.center, bodySim.transform.q);
B2Vec2 p = b2TransformPoint(ref transform, offset);

draw.DrawStringFcn(p, body.name, B2HexColor.b2_colorBlueViolet, draw.context);
}
}
Expand Down Expand Up @@ -2179,26 +2177,26 @@ public static bool TreeOverlapCallback(int proxyId, ulong userData, ref B2WorldO
}

/// Overlap test for all shapes that overlap the provided shape proxy.
public static B2TreeStats b2World_OverlapShape( B2WorldId worldId, ref B2ShapeProxy proxy, B2QueryFilter filter, b2OverlapResultFcn fcn, object context )
public static B2TreeStats b2World_OverlapShape(B2WorldId worldId, ref B2ShapeProxy proxy, B2QueryFilter filter, b2OverlapResultFcn fcn, object context)
{
B2TreeStats treeStats = new B2TreeStats();

B2World world = b2GetWorldFromId( worldId );
Debug.Assert( world.locked == false );
if ( world.locked )
B2World world = b2GetWorldFromId(worldId);
Debug.Assert(world.locked == false);
if (world.locked)
{
return treeStats;
}

B2AABB aabb = b2MakeAABB( proxy.points.AsSpan(), proxy.count, proxy.radius );
B2AABB aabb = b2MakeAABB(proxy.points.AsSpan(), proxy.count, proxy.radius);
B2WorldOverlapContext worldContext = new B2WorldOverlapContext(
world, fcn, filter, proxy, context
);

for ( int i = 0; i < (int)B2BodyType.b2_bodyTypeCount; ++i )
for (int i = 0; i < (int)B2BodyType.b2_bodyTypeCount; ++i)
{
B2TreeStats treeResult =
b2DynamicTree_Query( world.broadPhase.trees[i], aabb, filter.maskBits, TreeOverlapCallback, ref worldContext );
b2DynamicTree_Query(world.broadPhase.trees[i], aabb, filter.maskBits, TreeOverlapCallback, ref worldContext);

treeStats.nodeVisits += treeResult.nodeVisits;
treeStats.leafVisits += treeResult.leafVisits;
Expand Down
Loading