Skip to content
Draft
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
22 changes: 13 additions & 9 deletions src/libraries/box2d/b2_body.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class B2_API b2Body

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

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

/// Get the user data pointer that was provided in the body definition.
b2BodyUserData& GetUserData();

/// Set the user data. Use this to store your application specific data.
void SetUserData(void* data);
const b2BodyUserData& GetUserData() const;

/// Get the parent world of this body.
b2World* GetWorld();
Expand All @@ -404,7 +402,6 @@ class B2_API b2Body
friend class b2PrismaticJoint;
friend class b2PulleyJoint;
friend class b2RevoluteJoint;
friend class b2RopeJoint;
friend class b2WeldJoint;
friend class b2WheelJoint;

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

inline void b2Body::GetMassData(b2MassData* data) const
inline b2MassData b2Body::GetMassData() const
{
data->mass = m_mass;
data->I = m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter);
data->center = m_sweep.localCenter;
b2MassData data;
data.mass = m_mass;
data.I = m_I + m_mass * b2Dot(m_sweep.localCenter, m_sweep.localCenter);
data.center = m_sweep.localCenter;
return data;
}

inline b2Vec2 b2Body::GetWorldPoint(const b2Vec2& localPoint) const
Expand Down Expand Up @@ -736,6 +735,11 @@ inline b2BodyUserData& b2Body::GetUserData()
return m_userData;
}

inline const b2BodyUserData& b2Body::GetUserData() const
{
return m_userData;
}

inline void b2Body::ApplyForce(const b2Vec2& force, const b2Vec2& point, bool wake)
{
if (m_type != b2_dynamicBody)
Expand Down
25 changes: 24 additions & 1 deletion src/libraries/box2d/b2_collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ B2_API void b2CollideEdgeAndCircle(b2Manifold* manifold,
/// Compute the collision manifold between an edge and a polygon.
B2_API void b2CollideEdgeAndPolygon(b2Manifold* manifold,
const b2EdgeShape* edgeA, const b2Transform& xfA,
const b2PolygonShape* circleB, const b2Transform& xfB);
const b2PolygonShape* polygonB, const b2Transform& xfB);

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

/// Convex hull used for polygon collision
struct b2Hull
{
b2Vec2 points[b2_maxPolygonVertices];
int32 count;
};

/// Compute the convex hull of a set of points. Returns an empty hull if it fails.
/// Some failure cases:
/// - all points very close together
/// - all points on a line
/// - less than 3 points
/// - more than b2_maxPolygonVertices points
/// This welds close points and removes collinear points.
b2Hull b2ComputeHull(const b2Vec2* points, int32 count);

/// This determines if a hull is valid. Checks for:
/// - convexity
/// - collinear points
/// This is expensive and should not be called at runtime.
bool b2ValidateHull(const b2Hull& hull);


// ---------------- Inline Functions ------------------------------------------

inline bool b2AABB::IsValid() const
Expand Down
6 changes: 6 additions & 0 deletions src/libraries/box2d/b2_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class B2_API b2Fixture
/// Get the user data that was assigned in the fixture definition. Use this to
/// store your application specific data.
b2FixtureUserData& GetUserData();
const b2FixtureUserData& GetUserData() const;

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

inline const b2FixtureUserData& b2Fixture::GetUserData() const
{
return m_userData;
}

inline b2Body* b2Fixture::GetBody()
{
return m_body;
Expand Down
1 change: 1 addition & 0 deletions src/libraries/box2d/b2_gear_joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class B2_API b2GearJoint : public b2Joint

float m_constant;
float m_ratio;
float m_tolerance;

float m_impulse;

Expand Down
7 changes: 6 additions & 1 deletion src/libraries/box2d/b2_joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ enum b2JointType
e_wheelJoint,
e_weldJoint,
e_frictionJoint,
e_ropeJoint,
e_motorJoint
};

Expand Down Expand Up @@ -138,6 +137,7 @@ class B2_API b2Joint

/// Get the user data pointer.
b2JointUserData& GetUserData();
const b2JointUserData& GetUserData() const;

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

inline const b2JointUserData& b2Joint::GetUserData() const
{
return m_userData;
}

inline bool b2Joint::GetCollideConnected() const
{
return m_collideConnected;
Expand Down
14 changes: 8 additions & 6 deletions src/libraries/box2d/b2_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ inline bool b2IsValid(float x)
struct B2_API b2Vec2
{
/// Default constructor does nothing (for performance).
b2Vec2() {}
b2Vec2() = default;

/// Construct using coordinates.
b2Vec2(float xIn, float yIn) : x(xIn), y(yIn) {}
Expand Down Expand Up @@ -133,7 +133,7 @@ struct B2_API b2Vec2
struct B2_API b2Vec3
{
/// Default constructor does nothing (for performance).
b2Vec3() {}
b2Vec3() = default;

/// Construct using coordinates.
b2Vec3(float xIn, float yIn, float zIn) : x(xIn), y(yIn), z(zIn) {}
Expand Down Expand Up @@ -172,7 +172,7 @@ struct B2_API b2Vec3
struct B2_API b2Mat22
{
/// The default constructor does nothing (for performance).
b2Mat22() {}
b2Mat22() = default;

/// Construct this matrix using columns.
b2Mat22(const b2Vec2& c1, const b2Vec2& c2)
Expand Down Expand Up @@ -246,7 +246,7 @@ struct B2_API b2Mat22
struct B2_API b2Mat33
{
/// The default constructor does nothing (for performance).
b2Mat33() {}
b2Mat33() = default;

/// Construct this matrix using columns.
b2Mat33(const b2Vec3& c1, const b2Vec3& c2, const b2Vec3& c3)
Expand Down Expand Up @@ -287,7 +287,7 @@ struct B2_API b2Mat33
/// Rotation
struct B2_API b2Rot
{
b2Rot() {}
b2Rot() = default;

/// Initialize from an angle in radians
explicit b2Rot(float angle)
Expand Down Expand Up @@ -339,7 +339,7 @@ struct B2_API b2Rot
struct B2_API b2Transform
{
/// The default constructor does nothing.
b2Transform() {}
b2Transform() = default;

/// Initialize using a position vector and a rotation.
b2Transform(const b2Vec2& position, const b2Rot& rotation) : p(position), q(rotation) {}
Expand Down Expand Up @@ -368,6 +368,8 @@ struct B2_API b2Transform
/// we must interpolate the center of mass position.
struct B2_API b2Sweep
{
b2Sweep() = default;

/// Get the interpolated transform at a specific time.
/// @param transform the output transform
/// @param beta is a factor in [0,1], where 0 indicates alpha0.
Expand Down
20 changes: 9 additions & 11 deletions src/libraries/box2d/b2_polygon_shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "b2_api.h"
#include "b2_shape.h"

struct b2Hull;

/// A solid convex polygon. It is assumed that the interior of the polygon is to
/// the left of each edge.
/// Polygons have a maximum number of vertices equal to b2_maxPolygonVertices.
Expand All @@ -43,9 +45,13 @@ class B2_API b2PolygonShape : public b2Shape
/// Create a convex hull from the given array of local points.
/// The count must be in the range [3, b2_maxPolygonVertices].
/// @warning the points may be re-ordered, even if they form a convex polygon
/// @warning collinear points are handled but not removed. Collinear points
/// may lead to poor stacking behavior.
void Set(const b2Vec2* points, int32 count);
/// @warning if this fails then the polygon is invalid
/// @returns true if valid
bool Set(const b2Vec2* points, int32 count);

/// Create a polygon from a given convex hull (see b2ComputeHull).
/// @warning the hull must be valid or this will crash or have unexpected behavior
void Set(const b2Hull& hull);

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

inline b2PolygonShape::b2PolygonShape()
{
m_type = e_polygon;
m_radius = b2_polygonRadius;
m_count = 0;
m_centroid.SetZero();
}

#endif
2 changes: 2 additions & 0 deletions src/libraries/box2d/b2_rope.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct B2_API b2RopeTuning
bendingModel = b2_pbdAngleBendingModel;
damping = 0.0f;
stretchStiffness = 1.0f;
stretchHertz = 1.0f;
stretchDamping = 0.0f;
bendStiffness = 0.5f;
bendHertz = 1.0f;
bendDamping = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/box2d/b2_weld_joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class B2_API b2WeldJoint : public b2Joint
float GetReferenceAngle() const { return m_referenceAngle; }

/// Set/get stiffness in N*m
void SetStiffness(float hz) { m_stiffness = hz; }
void SetStiffness(float stiffness) { m_stiffness = stiffness; }
float GetStiffness() const { return m_stiffness; }

/// Set/get damping in N*m*s
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/box2d/b2_world.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ class B2_API b2World
friend class b2ContactManager;
friend class b2Controller;

b2World(const b2World&) = delete;
void operator=(const b2World&) = delete;

void Solve(const b2TimeStep& step);
void SolveTOI(const b2TimeStep& step);

Expand Down
Loading
Loading