Skip to content

Commit 052116c

Browse files
committed
Update Box2D to 2.4.2
1 parent 5903ad8 commit 052116c

25 files changed

+473
-196
lines changed

src/libraries/box2d/b2_body.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class B2_API b2Body
243243

244244
/// Get the mass data of the body.
245245
/// @return a struct containing the mass, inertia and center of the body.
246-
void GetMassData(b2MassData* data) const;
246+
b2MassData GetMassData() const;
247247

248248
/// Set the mass properties to override the mass properties of the fixtures.
249249
/// Note that this changes the center of mass position.
@@ -377,9 +377,7 @@ class B2_API b2Body
377377

378378
/// Get the user data pointer that was provided in the body definition.
379379
b2BodyUserData& GetUserData();
380-
381-
/// Set the user data. Use this to store your application specific data.
382-
void SetUserData(void* data);
380+
const b2BodyUserData& GetUserData() const;
383381

384382
/// Get the parent world of this body.
385383
b2World* GetWorld();
@@ -404,7 +402,6 @@ class B2_API b2Body
404402
friend class b2PrismaticJoint;
405403
friend class b2PulleyJoint;
406404
friend class b2RevoluteJoint;
407-
friend class b2RopeJoint;
408405
friend class b2WeldJoint;
409406
friend class b2WheelJoint;
410407

@@ -551,11 +548,13 @@ inline float b2Body::GetInertia() const
551548
return m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter);
552549
}
553550

554-
inline void b2Body::GetMassData(b2MassData* data) const
551+
inline b2MassData b2Body::GetMassData() const
555552
{
556-
data->mass = m_mass;
557-
data->I = m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter);
558-
data->center = m_sweep.localCenter;
553+
b2MassData data;
554+
data.mass = m_mass;
555+
data.I = m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter);
556+
data.center = m_sweep.localCenter;
557+
return data;
559558
}
560559

561560
inline b2Vec2 b2Body::GetWorldPoint(const b2Vec2& localPoint) const
@@ -736,6 +735,11 @@ inline b2BodyUserData& b2Body::GetUserData()
736735
return m_userData;
737736
}
738737

738+
inline const b2BodyUserData& b2Body::GetUserData() const
739+
{
740+
return m_userData;
741+
}
742+
739743
inline void b2Body::ApplyForce(const b2Vec2& force, const b2Vec2& point, bool wake)
740744
{
741745
if (m_type != b2_dynamicBody)

src/libraries/box2d/b2_collision.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ B2_API void b2CollideEdgeAndCircle(b2Manifold* manifold,
244244
/// Compute the collision manifold between an edge and a polygon.
245245
B2_API void b2CollideEdgeAndPolygon(b2Manifold* manifold,
246246
const b2EdgeShape* edgeA, const b2Transform& xfA,
247-
const b2PolygonShape* circleB, const b2Transform& xfB);
247+
const b2PolygonShape* polygonB, const b2Transform& xfB);
248248

249249
/// Clipping for contact manifolds.
250250
B2_API int32 b2ClipSegmentToLine(b2ClipVertex vOut[2], const b2ClipVertex vIn[2],
@@ -255,6 +255,29 @@ B2_API bool b2TestOverlap( const b2Shape* shapeA, int32 indexA,
255255
const b2Shape* shapeB, int32 indexB,
256256
const b2Transform& xfA, const b2Transform& xfB);
257257

258+
/// Convex hull used for polygon collision
259+
struct b2Hull
260+
{
261+
b2Vec2 points[b2_maxPolygonVertices];
262+
int32 count;
263+
};
264+
265+
/// Compute the convex hull of a set of points. Returns an empty hull if it fails.
266+
/// Some failure cases:
267+
/// - all points very close together
268+
/// - all points on a line
269+
/// - less than 3 points
270+
/// - more than b2_maxPolygonVertices points
271+
/// This welds close points and removes collinear points.
272+
b2Hull b2ComputeHull(const b2Vec2* points, int32 count);
273+
274+
/// This determines if a hull is valid. Checks for:
275+
/// - convexity
276+
/// - collinear points
277+
/// This is expensive and should not be called at runtime.
278+
bool b2ValidateHull(const b2Hull& hull);
279+
280+
258281
// ---------------- Inline Functions ------------------------------------------
259282

260283
inline bool b2AABB::IsValid() const

src/libraries/box2d/b2_fixture.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class B2_API b2Fixture
157157
/// Get the user data that was assigned in the fixture definition. Use this to
158158
/// store your application specific data.
159159
b2FixtureUserData& GetUserData();
160+
const b2FixtureUserData& GetUserData() const;
160161

161162
/// Test a point for containment in this fixture.
162163
/// @param p a point in world coordinates.
@@ -280,6 +281,11 @@ inline b2FixtureUserData& b2Fixture::GetUserData()
280281
return m_userData;
281282
}
282283

284+
inline const b2FixtureUserData& b2Fixture::GetUserData() const
285+
{
286+
return m_userData;
287+
}
288+
283289
inline b2Body* b2Fixture::GetBody()
284290
{
285291
return m_body;

src/libraries/box2d/b2_gear_joint.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class B2_API b2GearJoint : public b2Joint
114114

115115
float m_constant;
116116
float m_ratio;
117+
float m_tolerance;
117118

118119
float m_impulse;
119120

src/libraries/box2d/b2_joint.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ enum b2JointType
4444
e_wheelJoint,
4545
e_weldJoint,
4646
e_frictionJoint,
47-
e_ropeJoint,
4847
e_motorJoint
4948
};
5049

@@ -138,6 +137,7 @@ class B2_API b2Joint
138137

139138
/// Get the user data pointer.
140139
b2JointUserData& GetUserData();
140+
const b2JointUserData& GetUserData() const;
141141

142142
/// Short-cut function to determine if either body is enabled.
143143
bool IsEnabled() const;
@@ -220,6 +220,11 @@ inline b2JointUserData& b2Joint::GetUserData()
220220
return m_userData;
221221
}
222222

223+
inline const b2JointUserData& b2Joint::GetUserData() const
224+
{
225+
return m_userData;
226+
}
227+
223228
inline bool b2Joint::GetCollideConnected() const
224229
{
225230
return m_collideConnected;

src/libraries/box2d/b2_math.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ inline bool b2IsValid(float x)
4242
struct B2_API b2Vec2
4343
{
4444
/// Default constructor does nothing (for performance).
45-
b2Vec2() {}
45+
b2Vec2() = default;
4646

4747
/// Construct using coordinates.
4848
b2Vec2(float xIn, float yIn) : x(xIn), y(yIn) {}
@@ -133,7 +133,7 @@ struct B2_API b2Vec2
133133
struct B2_API b2Vec3
134134
{
135135
/// Default constructor does nothing (for performance).
136-
b2Vec3() {}
136+
b2Vec3() = default;
137137

138138
/// Construct using coordinates.
139139
b2Vec3(float xIn, float yIn, float zIn) : x(xIn), y(yIn), z(zIn) {}
@@ -172,7 +172,7 @@ struct B2_API b2Vec3
172172
struct B2_API b2Mat22
173173
{
174174
/// The default constructor does nothing (for performance).
175-
b2Mat22() {}
175+
b2Mat22() = default;
176176

177177
/// Construct this matrix using columns.
178178
b2Mat22(const b2Vec2& c1, const b2Vec2& c2)
@@ -246,7 +246,7 @@ struct B2_API b2Mat22
246246
struct B2_API b2Mat33
247247
{
248248
/// The default constructor does nothing (for performance).
249-
b2Mat33() {}
249+
b2Mat33() = default;
250250

251251
/// Construct this matrix using columns.
252252
b2Mat33(const b2Vec3& c1, const b2Vec3& c2, const b2Vec3& c3)
@@ -287,7 +287,7 @@ struct B2_API b2Mat33
287287
/// Rotation
288288
struct B2_API b2Rot
289289
{
290-
b2Rot() {}
290+
b2Rot() = default;
291291

292292
/// Initialize from an angle in radians
293293
explicit b2Rot(float angle)
@@ -339,7 +339,7 @@ struct B2_API b2Rot
339339
struct B2_API b2Transform
340340
{
341341
/// The default constructor does nothing.
342-
b2Transform() {}
342+
b2Transform() = default;
343343

344344
/// Initialize using a position vector and a rotation.
345345
b2Transform(const b2Vec2& position, const b2Rot& rotation) : p(position), q(rotation) {}
@@ -368,6 +368,8 @@ struct B2_API b2Transform
368368
/// we must interpolate the center of mass position.
369369
struct B2_API b2Sweep
370370
{
371+
b2Sweep() = default;
372+
371373
/// Get the interpolated transform at a specific time.
372374
/// @param transform the output transform
373375
/// @param beta is a factor in [0,1], where 0 indicates alpha0.

src/libraries/box2d/b2_polygon_shape.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "b2_api.h"
2626
#include "b2_shape.h"
2727

28+
struct b2Hull;
29+
2830
/// A solid convex polygon. It is assumed that the interior of the polygon is to
2931
/// the left of each edge.
3032
/// Polygons have a maximum number of vertices equal to b2_maxPolygonVertices.
@@ -43,9 +45,13 @@ class B2_API b2PolygonShape : public b2Shape
4345
/// Create a convex hull from the given array of local points.
4446
/// The count must be in the range [3, b2_maxPolygonVertices].
4547
/// @warning the points may be re-ordered, even if they form a convex polygon
46-
/// @warning collinear points are handled but not removed. Collinear points
47-
/// may lead to poor stacking behavior.
48-
void Set(const b2Vec2* points, int32 count);
48+
/// @warning if this fails then the polygon is invalid
49+
/// @returns true if valid
50+
bool Set(const b2Vec2* points, int32 count);
51+
52+
/// Create a polygon from a given convex hull (see b2ComputeHull).
53+
/// @warning the hull must be valid or this will crash or have unexpected behavior
54+
void Set(const b2Hull& hull);
4955

5056
/// Build vertices to represent an axis-aligned box centered on the local origin.
5157
/// @param hx the half-width.
@@ -84,12 +90,4 @@ class B2_API b2PolygonShape : public b2Shape
8490
int32 m_count;
8591
};
8692

87-
inline b2PolygonShape::b2PolygonShape()
88-
{
89-
m_type = e_polygon;
90-
m_radius = b2_polygonRadius;
91-
m_count = 0;
92-
m_centroid.SetZero();
93-
}
94-
9593
#endif

src/libraries/box2d/b2_rope.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ struct B2_API b2RopeTuning
5555
bendingModel = b2_pbdAngleBendingModel;
5656
damping = 0.0f;
5757
stretchStiffness = 1.0f;
58+
stretchHertz = 1.0f;
59+
stretchDamping = 0.0f;
5860
bendStiffness = 0.5f;
5961
bendHertz = 1.0f;
6062
bendDamping = 0.0f;

src/libraries/box2d/b2_weld_joint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class B2_API b2WeldJoint : public b2Joint
8585
float GetReferenceAngle() const { return m_referenceAngle; }
8686

8787
/// Set/get stiffness in N*m
88-
void SetStiffness(float hz) { m_stiffness = hz; }
88+
void SetStiffness(float stiffness) { m_stiffness = stiffness; }
8989
float GetStiffness() const { return m_stiffness; }
9090

9191
/// Set/get damping in N*m*s

src/libraries/box2d/b2_world.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ class B2_API b2World
221221
friend class b2ContactManager;
222222
friend class b2Controller;
223223

224+
b2World(const b2World&) = delete;
225+
void operator=(const b2World&) = delete;
226+
224227
void Solve(const b2TimeStep& step);
225228
void SolveTOI(const b2TimeStep& step);
226229

0 commit comments

Comments
 (0)