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
21 changes: 11 additions & 10 deletions src/Box2D.NET.Samples/SampleApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,19 @@ private void OnWindowLoad()
return;
}

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);

var glVersion = _ctx.gl.GetStringS(StringName.Version);
Logger.Information($"GL {glVersion}");
Logger.Information($"OpenGL {_ctx.gl.GetStringS(GLEnum.Version)}, GLSL {_ctx.gl.GetStringS(GLEnum.ShadingLanguageVersion)}");
Logger.Information($"OpenGL aliased line width range : [{temp1[0]}, {temp1[1]}]");
Logger.Information($"OpenGL smooth line width range : [{temp2[0]}, {temp2[1]}]");
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]}]");
}

unsafe
{
Expand Down
6 changes: 4 additions & 2 deletions src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using static Box2D.NET.B2Worlds;
using static Box2D.NET.Shared.RandomSupports;
using static Box2D.NET.B2Timers;
using static Box2D.NET.B2Distances;

namespace Box2D.NET.Samples.Samples.Benchmarks;

Expand All @@ -30,7 +31,7 @@
private float m_buildTime;

private int m_rowCount, m_columnCount;
private int m_updateType;

Check warning on line 34 in src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCast.cs

View workflow job for this annotation

GitHub Actions / test-macos-latest-8

The field 'BenchmarkCast.m_updateType' is never used
private int m_drawIndex;
private float m_radius;
private float m_fill;
Expand Down Expand Up @@ -242,11 +243,12 @@

for (int i = 0; i < sampleCount; ++i)
{
B2Circle circle = new B2Circle(m_origins[i], m_radius);
B2ShapeProxy proxy = b2MakeProxy( m_origins[i], 1, m_radius );

B2Vec2 translation = m_translations[i];

CastResult result = new CastResult();
B2TreeStats traversalResult = b2World_CastCircle(m_worldId, ref circle, translation, filter, CastCallback, result);
B2TreeStats traversalResult = b2World_CastShape(m_worldId, ref proxy, translation, filter, CastCallback, result);

if (i == m_drawIndex)
{
Expand Down
13 changes: 3 additions & 10 deletions src/Box2D.NET.Samples/Samples/Bodies/Kinematic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,9 @@ public Kinematic(SampleAppContext ctx, Settings settings) : base(ctx, settings)
public override void Step(Settings settings)
{
m_timeStep = settings.hertz > 0.0f ? 1.0f / settings.hertz : 0.0f;
if (settings.pause)
if (settings.pause && settings.singleStep == false)
{
if (settings.singleStep)
{
settings.singleStep = false;
}
else
{
m_timeStep = 0.0f;
}
m_timeStep = 0.0f;
}


Expand All @@ -84,7 +77,7 @@ public override void Draw(Settings settings)
m_context.draw.DrawSegment(point - 0.5f * axis, point + 0.5f * axis, B2HexColor.b2_colorPlum);
m_context.draw.DrawPoint(point, 10.0f, B2HexColor.b2_colorPlum);

b2Body_SetKinematicTarget(m_bodyId, new B2Transform(point, rotation), m_timeStep);
b2Body_SetTargetTransform(m_bodyId, new B2Transform(point, rotation), m_timeStep);
}
}
}
61 changes: 57 additions & 4 deletions src/Box2D.NET.Samples/Samples/Bodies/Sleep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class Sleep : Sample
private static readonly int SampleSleep = SampleFactory.Shared.RegisterSample("Bodies", "Sleep", Create);

private B2BodyId m_pendulumId;
private B2BodyId m_staticBodyId;
private B2ShapeId m_groundShapeId;
private B2ShapeId[] m_sensorIds = new B2ShapeId[2];
private bool[] m_sensorTouching = new bool[2];


private static Sample Create(SampleAppContext ctx, Settings settings)
{
return new Sleep(ctx, settings);
Expand All @@ -43,7 +43,7 @@ public Sleep(SampleAppContext ctx, Settings settings) : base(ctx, settings)
B2BodyDef bodyDef = b2DefaultBodyDef();
groundId = b2CreateBody(m_worldId, ref bodyDef);

B2Segment segment = new B2Segment(new B2Vec2(-20.0f, 0.0f), new B2Vec2(20.0f, 0.0f));
B2Segment segment = new B2Segment(new B2Vec2(-40.0f, 0.0f), new B2Vec2(40.0f, 0.0f));
B2ShapeDef shapeDef = b2DefaultShapeDef();
shapeDef.enableSensorEvents = true;
m_groundShapeId = b2CreateSegmentShape(groundId, ref shapeDef, ref segment);
Expand Down Expand Up @@ -133,12 +133,48 @@ public Sleep(SampleAppContext ctx, Settings settings) : base(ctx, settings)
jointDef.localAnchorB = b2Body_GetLocalPoint(jointDef.bodyIdB, pivot);
b2CreateRevoluteJoint(m_worldId, ref jointDef);
}

// A sleeping body to test waking on contact destroyed
{
B2BodyDef bodyDef = b2DefaultBodyDef();
bodyDef.type = B2BodyType.b2_dynamicBody;
bodyDef.position = new B2Vec2(-10.0f, 1.0f);
bodyDef.isAwake = false;
bodyDef.enableSleep = true;
B2BodyId bodyId = b2CreateBody(m_worldId, ref bodyDef);

B2Polygon box = b2MakeSquare(1.0f);
B2ShapeDef shapeDef = b2DefaultShapeDef();
b2CreatePolygonShape(bodyId, ref shapeDef, ref box);
}

m_staticBodyId = b2_nullBodyId;
}

void ToggleInvoker()
{
if (B2_IS_NULL(m_staticBodyId))
{
B2BodyDef bodyDef = b2DefaultBodyDef();
bodyDef.position = new B2Vec2(-10.5f, 3.0f);
m_staticBodyId = b2CreateBody(m_worldId, ref bodyDef);

B2Polygon box = b2MakeOffsetBox(2.0f, 0.1f, new B2Vec2(0.0f, 0.0f), b2MakeRot(0.25f * B2_PI));
B2ShapeDef shapeDef = b2DefaultShapeDef();
shapeDef.invokeContactCreation = true;
b2CreatePolygonShape(m_staticBodyId, ref shapeDef, ref box);
}
else
{
b2DestroyBody(m_staticBodyId);
m_staticBodyId = b2_nullBodyId;
}
}

public override void UpdateGui()
{
base.UpdateGui();
float height = 100.0f;
float height = 160.0f;
ImGui.SetNextWindowPos(new Vector2(10.0f, m_context.camera.m_height - height - 50.0f), ImGuiCond.Once);
ImGui.SetNextWindowSize(new Vector2(240.0f, height));
ImGui.Begin("Sleep", ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize);
Expand All @@ -162,6 +198,23 @@ public override void UpdateGui()

ImGui.PopItemWidth();

ImGui.Separator();

if (B2_IS_NULL(m_staticBodyId))
{
if (ImGui.Button("Create"))
{
ToggleInvoker();
}
}
else
{
if (ImGui.Button("Destroy"))
{
ToggleInvoker();
}
}

ImGui.End();
}

Expand Down Expand Up @@ -208,7 +261,7 @@ public override void Step(Settings settings)
public override void Draw(Settings settings)
{
base.Draw(settings);

for (int i = 0; i < 2; ++i)
{
m_context.draw.DrawString(5, m_textLine, $"sensor touch {i} = {m_sensorTouching[i]}");
Expand Down
Loading
Loading