Skip to content

Commit 1cce234

Browse files
committed
3.1 release step 2
1 parent be7ea07 commit 1cce234

31 files changed

Lines changed: 471 additions & 384 deletions

src/Box2D.NET.Samples/SampleApp.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,18 +219,19 @@ private void OnWindowLoad()
219219
return;
220220
}
221221

222-
Span<float> temp1 = stackalloc float[2];
223-
_ctx.gl.GetFloat( GLEnum.AliasedLineWidthRange, temp1 );
224-
225-
Span<float> temp2 = stackalloc float[2];
226-
_ctx.gl.GetFloat( GLEnum.SmoothLineWidthRange, temp2 );
222+
{
223+
Span<float> temp1 = stackalloc float[2];
224+
_ctx.gl.GetFloat(GLEnum.AliasedLineWidthRange, temp1);
227225

228-
var glVersion = _ctx.gl.GetStringS(StringName.Version);
229-
Logger.Information($"GL {glVersion}");
230-
Logger.Information($"OpenGL {_ctx.gl.GetStringS(GLEnum.Version)}, GLSL {_ctx.gl.GetStringS(GLEnum.ShadingLanguageVersion)}");
231-
Logger.Information($"OpenGL aliased line width range : [{temp1[0]}, {temp1[1]}]");
232-
Logger.Information($"OpenGL smooth line width range : [{temp2[0]}, {temp2[1]}]");
226+
Span<float> temp2 = stackalloc float[2];
227+
_ctx.gl.GetFloat(GLEnum.SmoothLineWidthRange, temp2);
233228

229+
string glVersionString = _ctx.gl.GetStringS(GLEnum.Version);
230+
string glslVersionString = _ctx.gl.GetStringS(GLEnum.ShadingLanguageVersion);
231+
Logger.Information($"OpenGL {glVersionString}, GLSL {glslVersionString}");
232+
Logger.Information($"OpenGL aliased line width range : [{temp1[0]}, {temp1[1]}]");
233+
Logger.Information($"OpenGL smooth line width range : [{temp2[0]}, {temp2[1]}]");
234+
}
234235

235236
unsafe
236237
{

src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCast.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using static Box2D.NET.B2Worlds;
1616
using static Box2D.NET.Shared.RandomSupports;
1717
using static Box2D.NET.B2Timers;
18+
using static Box2D.NET.B2Distances;
1819

1920
namespace Box2D.NET.Samples.Samples.Benchmarks;
2021

@@ -242,11 +243,12 @@ public override void Step(Settings settings)
242243

243244
for (int i = 0; i < sampleCount; ++i)
244245
{
245-
B2Circle circle = new B2Circle(m_origins[i], m_radius);
246+
B2ShapeProxy proxy = b2MakeProxy( m_origins[i], 1, m_radius );
247+
246248
B2Vec2 translation = m_translations[i];
247249

248250
CastResult result = new CastResult();
249-
B2TreeStats traversalResult = b2World_CastCircle(m_worldId, ref circle, translation, filter, CastCallback, result);
251+
B2TreeStats traversalResult = b2World_CastShape(m_worldId, ref proxy, translation, filter, CastCallback, result);
250252

251253
if (i == m_drawIndex)
252254
{

src/Box2D.NET.Samples/Samples/Bodies/Kinematic.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,9 @@ public Kinematic(SampleAppContext ctx, Settings settings) : base(ctx, settings)
5151
public override void Step(Settings settings)
5252
{
5353
m_timeStep = settings.hertz > 0.0f ? 1.0f / settings.hertz : 0.0f;
54-
if (settings.pause)
54+
if (settings.pause && settings.singleStep == false)
5555
{
56-
if (settings.singleStep)
57-
{
58-
settings.singleStep = false;
59-
}
60-
else
61-
{
62-
m_timeStep = 0.0f;
63-
}
56+
m_timeStep = 0.0f;
6457
}
6558

6659

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

87-
b2Body_SetKinematicTarget(m_bodyId, new B2Transform(point, rotation), m_timeStep);
80+
b2Body_SetTargetTransform(m_bodyId, new B2Transform(point, rotation), m_timeStep);
8881
}
8982
}
9083
}

src/Box2D.NET.Samples/Samples/Bodies/Sleep.cs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public class Sleep : Sample
2020
private static readonly int SampleSleep = SampleFactory.Shared.RegisterSample("Bodies", "Sleep", Create);
2121

2222
private B2BodyId m_pendulumId;
23+
private B2BodyId m_staticBodyId;
2324
private B2ShapeId m_groundShapeId;
2425
private B2ShapeId[] m_sensorIds = new B2ShapeId[2];
2526
private bool[] m_sensorTouching = new bool[2];
2627

27-
2828
private static Sample Create(SampleAppContext ctx, Settings settings)
2929
{
3030
return new Sleep(ctx, settings);
@@ -43,7 +43,7 @@ public Sleep(SampleAppContext ctx, Settings settings) : base(ctx, settings)
4343
B2BodyDef bodyDef = b2DefaultBodyDef();
4444
groundId = b2CreateBody(m_worldId, ref bodyDef);
4545

46-
B2Segment segment = new B2Segment(new B2Vec2(-20.0f, 0.0f), new B2Vec2(20.0f, 0.0f));
46+
B2Segment segment = new B2Segment(new B2Vec2(-40.0f, 0.0f), new B2Vec2(40.0f, 0.0f));
4747
B2ShapeDef shapeDef = b2DefaultShapeDef();
4848
shapeDef.enableSensorEvents = true;
4949
m_groundShapeId = b2CreateSegmentShape(groundId, ref shapeDef, ref segment);
@@ -133,12 +133,48 @@ public Sleep(SampleAppContext ctx, Settings settings) : base(ctx, settings)
133133
jointDef.localAnchorB = b2Body_GetLocalPoint(jointDef.bodyIdB, pivot);
134134
b2CreateRevoluteJoint(m_worldId, ref jointDef);
135135
}
136+
137+
// A sleeping body to test waking on contact destroyed
138+
{
139+
B2BodyDef bodyDef = b2DefaultBodyDef();
140+
bodyDef.type = B2BodyType.b2_dynamicBody;
141+
bodyDef.position = new B2Vec2(-10.0f, 1.0f);
142+
bodyDef.isAwake = false;
143+
bodyDef.enableSleep = true;
144+
B2BodyId bodyId = b2CreateBody(m_worldId, ref bodyDef);
145+
146+
B2Polygon box = b2MakeSquare(1.0f);
147+
B2ShapeDef shapeDef = b2DefaultShapeDef();
148+
b2CreatePolygonShape(bodyId, ref shapeDef, ref box);
149+
}
150+
151+
m_staticBodyId = b2_nullBodyId;
152+
}
153+
154+
void ToggleInvoker()
155+
{
156+
if (B2_IS_NULL(m_staticBodyId))
157+
{
158+
B2BodyDef bodyDef = b2DefaultBodyDef();
159+
bodyDef.position = new B2Vec2(-10.5f, 3.0f);
160+
m_staticBodyId = b2CreateBody(m_worldId, ref bodyDef);
161+
162+
B2Polygon box = b2MakeOffsetBox(2.0f, 0.1f, new B2Vec2(0.0f, 0.0f), b2MakeRot(0.25f * B2_PI));
163+
B2ShapeDef shapeDef = b2DefaultShapeDef();
164+
shapeDef.invokeContactCreation = true;
165+
b2CreatePolygonShape(m_staticBodyId, ref shapeDef, ref box);
166+
}
167+
else
168+
{
169+
b2DestroyBody(m_staticBodyId);
170+
m_staticBodyId = b2_nullBodyId;
171+
}
136172
}
137173

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

163199
ImGui.PopItemWidth();
164200

201+
ImGui.Separator();
202+
203+
if (B2_IS_NULL(m_staticBodyId))
204+
{
205+
if (ImGui.Button("Create"))
206+
{
207+
ToggleInvoker();
208+
}
209+
}
210+
else
211+
{
212+
if (ImGui.Button("Destroy"))
213+
{
214+
ToggleInvoker();
215+
}
216+
}
217+
165218
ImGui.End();
166219
}
167220

@@ -208,7 +261,7 @@ public override void Step(Settings settings)
208261
public override void Draw(Settings settings)
209262
{
210263
base.Draw(settings);
211-
264+
212265
for (int i = 0; i < 2; ++i)
213266
{
214267
m_context.draw.DrawString(5, m_textLine, $"sensor touch {i} = {m_sensorTouching[i]}");

0 commit comments

Comments
 (0)