Skip to content

Commit c69b42d

Browse files
committed
Fix total normal impulse (erincatto/box2d#1022)
Improved usefulness of total normal impulse on contact points Distance joint now solves motor before limit Code clean up and minor fixes Logging Update clang format Dynamic tree unit test b2FreeFcn now receives the allocation size Added check for a missed call to b2Body_ApplyMassFromShapes Calling b2CreateCapsuleShape with a very short capsule now returns b2_nullShapeId Calling b2Shape_SetCapsule with a very short capsule now returns with no change. Added b2ContactId to hit events. b2Body_SetTargetTransform now has a wake option. erincatto/box2d#1019 erincatto/box2d#1015 erincatto/box2d#1014 erincatto/box2d#1010 erincatto/box2d#1009 erincatto/box2d#1005
1 parent d5fad3e commit c69b42d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+451
-302
lines changed

src/Box2D.NET.Samples/SampleApp.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public int Run(string[] args)
6464

6565
SampleFactory.Shared.LoadSamples();
6666
SampleFactory.Shared.SortSamples();
67-
67+
6868
var currentCulture = CultureInfo.CurrentCulture;
6969
string bitness = Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit";
7070

@@ -98,7 +98,7 @@ public int Run(string[] args)
9898
_context.glfw.WindowHint(WindowHintInt.ContextVersionMinor, 3);
9999
_context.glfw.WindowHint(WindowHintBool.OpenGLForwardCompat, true);
100100
_context.glfw.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core);
101-
101+
102102
// MSAA
103103
_context.glfw.WindowHint(WindowHintInt.Samples, 4);
104104
options.Samples = 4;
@@ -176,7 +176,7 @@ private void OnWindowResize(Vector2D<int> resize)
176176
{
177177
var width = resize.X;
178178
var height = resize.Y;
179-
179+
180180
_context.camera.width = width;
181181
_context.camera.height = height;
182182
}
@@ -374,10 +374,10 @@ private void OnWindowRender(double dt)
374374
ImGui.End();
375375

376376
s_sample.ResetText();
377-
377+
378378
var title = SampleFactory.Shared.GetTitle(_context.sampleIndex);
379379
s_sample.DrawColoredTextLine(B2HexColor.b2_colorYellow, title);
380-
380+
381381
string buffer = $"{1000.0f * _frameTime:0.0} ms - step {s_sample.m_stepCount} - " +
382382
$"camera ({_context.camera.center.X:G}, {_context.camera.center.Y:G}, {_context.camera.zoom:G})";
383383
DrawScreenString(_context.draw, 5.0f, _context.camera.height - 18.0f, B2HexColor.b2_colorSeaGreen, buffer);
@@ -422,7 +422,7 @@ public byte[] AllocFcn(uint size, int alignment)
422422
return null;
423423
}
424424

425-
private void FreeFcn(byte[] mem)
425+
private void FreeFcn(byte[] mem, uint size)
426426
{
427427
// #if defined( _MSC_VER ) || defined( __MINGW32__ ) || defined( __MINGW64__ )
428428
// _aligned_free( mem );

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,21 @@ public BodyType(SampleContext context) : base(context)
186186
b2CreateCapsuleShape(m_touchingBodyId, ref shapeDef, ref capsule);
187187
}
188188

189+
// Create a separate body on the ground
190+
{
191+
B2BodyDef bodyDef = b2DefaultBodyDef();
192+
bodyDef.type = B2BodyType.b2_staticBody;
193+
bodyDef.isEnabled = m_isEnabled;
194+
bodyDef.position = new B2Vec2(8.5f, 0.2f);
195+
bodyDef.name = "debris";
196+
B2BodyId bodyId = b2CreateBody(m_worldId, bodyDef);
197+
198+
B2Capsule capsule = new B2Capsule(new B2Vec2(0.0f, 0.0f), new B2Vec2(1.0f, 0.0f), 0.5f);
199+
200+
B2ShapeDef shapeDef = b2DefaultShapeDef();
201+
b2CreateCapsuleShape(bodyId, shapeDef, capsule);
202+
}
203+
189204
// Create a separate floating body
190205
{
191206
B2BodyDef bodyDef = b2DefaultBodyDef();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public override void Draw()
8282
DrawLine(m_draw, point - 0.5f * axis, point + 0.5f * axis, B2HexColor.b2_colorPlum);
8383
DrawPoint(m_draw, point, 10.0f, B2HexColor.b2_colorPlum);
8484

85-
b2Body_SetTargetTransform(m_bodyId, new B2Transform(point, rotation), m_timeStep);
85+
bool wake = true;
86+
b2Body_SetTargetTransform(m_bodyId, new B2Transform(point, rotation), m_timeStep, wake);
8687
}
8788
}
88-
}
89+
}

src/Box2D.NET.Samples/Samples/Characters/Mover.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,8 @@ public override void Step()
577577
point.X = m_elevatorBase.X;
578578
point.Y = m_elevatorAmplitude * MathF.Cos(1.0f * m_time + B2_PI) + m_elevatorBase.Y;
579579

580-
b2Body_SetTargetTransform(m_elevatorId, new B2Transform(point, b2Rot_identity), timeStep);
580+
bool wake = true;
581+
b2Body_SetTargetTransform(m_elevatorId, new B2Transform(point, b2Rot_identity), timeStep, true);
581582
}
582583

583584
m_time += timeStep;

src/Box2D.NET.Samples/Samples/Collisions/ShapeCast.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@ public ShapeCast(SampleContext context) : base(context)
9292
points[2].y = 0.350000024;
9393
points[3].x = -0.599999964;
9494
points[3].y = 0.350000024;
95-
b2Hull hull = b2ComputeHull( points, 4 );
95+
96+
points[0] = { 3.0, -0.5 };
97+
points[1] = { 3.0, 0.5 };
98+
points[2] = { -3.0, 0.5 };
99+
points[3] = { -3.0, -0.5 };
100+
b2Hull hull = b2ComputeHull( points, 4 );
101+
bool isValid = b2ValidateHull( &hull );
102+
assert( isValid );
103+
96104
m_triangle = b2MakePolygon( &hull, 0.0f );
97105
}
98106
#endif

src/Box2D.NET.Samples/Samples/Collisions/ShapeDistance.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public ShapeDistance(SampleContext context) : base(context)
101101

102102
m_cache = b2_emptySimplexCache;
103103
m_simplexCount = 0;
104+
m_simplexIndex = 0;
104105
m_startPoint = new B2Vec2(0.0f, 0.0f);
105106
m_basePosition = new B2Vec2(0.0f, 0.0f);
106107
m_baseAngle = 0.0f;
@@ -269,7 +270,7 @@ public override void UpdateGui()
269270
m_simplexIndex = 0;
270271
}
271272

272-
if (m_drawSimplex)
273+
if (m_drawSimplex && m_simplexCount > 0)
273274
{
274275
ImGui.SliderInt("index", ref m_simplexIndex, 0, m_simplexCount - 1);
275276
m_simplexIndex = b2ClampInt(m_simplexIndex, 0, m_simplexCount - 1);
@@ -366,7 +367,7 @@ public override void Step()
366367
input.proxyB = m_proxyB;
367368
input.transformA = b2Transform_identity;
368369
input.transformB = m_transform;
369-
input.useRadii = true || m_radiusA > 0.0f || m_radiusB > 0.0f;
370+
input.useRadii = m_radiusA > 0.0f || m_radiusB > 0.0f;
370371

371372
if (m_useCache == false)
372373
{

src/Box2D.NET.Samples/Samples/Events/BodyMove.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,16 @@ public override void Step()
138138
B2BodyEvents events = b2World_GetBodyEvents(m_worldId);
139139
for (int i = 0; i < events.moveCount; ++i)
140140
{
141+
ref readonly B2BodyMoveEvent @event = ref events.moveEvents[i];
142+
143+
144+
if (@event.userData == null)
145+
{
146+
// The mouse joint body has no user data
147+
continue;
148+
}
149+
141150
// draw the transform of every body that moved (not sleeping)
142-
ref B2BodyMoveEvent @event = ref events.moveEvents[i];
143151
DrawTransform(m_draw, @event.transform, 1.0f);
144152

145153
B2Transform transform = b2Body_GetTransform(@event.bodyId);

src/Box2D.NET.Samples/Samples/Joints/MotorJoint.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ public override void Step()
180180
float angularOffset = 2.0f * m_time;
181181
m_transform = new B2Transform(linearOffset, b2MakeRot(angularOffset));
182182

183-
b2Body_SetTargetTransform(m_targetId, m_transform, timeStep);
183+
bool wake = true;
184+
b2Body_SetTargetTransform(m_targetId, m_transform, timeStep, true);
184185
}
185186

186187
DrawTransform(m_draw, m_transform, 1.0f);

src/Box2D.NET.Samples/Samples/Sample.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ public virtual void Step()
416416

417417
if (B2_IS_NON_NULL(m_mouseBodyId) && timeStep > 0.0f)
418418
{
419-
b2Body_SetTargetTransform(m_mouseBodyId, new B2Transform(m_mousePoint, b2Rot_identity), timeStep);
419+
bool wake = true;
420+
b2Body_SetTargetTransform(m_mouseBodyId, new B2Transform(m_mousePoint, b2Rot_identity), timeStep, wake);
420421
}
421422

422423
b2World_EnableSleeping(m_worldId, m_context.enableSleep);

0 commit comments

Comments
 (0)