Update to box2d 2.4.1

This commit is contained in:
Garrett Brown
2020-10-17 22:15:18 -04:00
parent 7d24beab90
commit 77f238767f
58 changed files with 879 additions and 367 deletions
+50 -14
View File
@@ -23,14 +23,14 @@
#ifndef B2_DISTANCE_JOINT_H
#define B2_DISTANCE_JOINT_H
#include "b2_api.h"
#include "b2_joint.h"
/// Distance joint definition. This requires defining an anchor point on both
/// bodies and the non-zero length of the distance joint. The definition uses local anchor points
/// so that the initial configuration can violate the constraint
/// slightly. This helps when saving and loading a game.
/// @warning Do not use a zero or short length.
struct b2DistanceJointDef : public b2JointDef
/// bodies and the non-zero distance of the distance joint. The definition uses
/// local anchor points so that the initial configuration can violate the
/// constraint slightly. This helps when saving and loading a game.
struct B2_API b2DistanceJointDef : public b2JointDef
{
b2DistanceJointDef()
{
@@ -38,12 +38,14 @@ struct b2DistanceJointDef : public b2JointDef
localAnchorA.Set(0.0f, 0.0f);
localAnchorB.Set(0.0f, 0.0f);
length = 1.0f;
minLength = 0.0f;
maxLength = FLT_MAX;
stiffness = 0.0f;
damping = 0.0f;
}
/// Initialize the bodies, anchors, and length using the world
/// anchors.
/// Initialize the bodies, anchors, and rest length using world space anchors.
/// The minimum and maximum lengths are set to the rest length.
void Initialize(b2Body* bodyA, b2Body* bodyB,
const b2Vec2& anchorA, const b2Vec2& anchorB);
@@ -53,10 +55,16 @@ struct b2DistanceJointDef : public b2JointDef
/// The local anchor point relative to bodyB's origin.
b2Vec2 localAnchorB;
/// The natural length between the anchor points.
/// The rest length of this joint. Clamped to a stable minimum value.
float length;
/// The linear stiffness in N/m. A value of 0 disables softness.
/// Minimum length. Clamped to a stable minimum value.
float minLength;
/// Maximum length. Must be greater than or equal to the minimum length.
float maxLength;
/// The linear stiffness in N/m.
float stiffness;
/// The linear damping in N*s/m.
@@ -65,7 +73,7 @@ struct b2DistanceJointDef : public b2JointDef
/// A distance joint constrains two points on two bodies to remain at a fixed
/// distance from each other. You can view this as a massless, rigid rod.
class b2DistanceJoint : public b2Joint
class B2_API b2DistanceJoint : public b2Joint
{
public:
@@ -86,11 +94,30 @@ public:
/// The local anchor point relative to bodyB's origin.
const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
/// Set/get the natural length.
/// Manipulating the length can lead to non-physical behavior when the frequency is zero.
void SetLength(float length) { m_length = length; }
/// Get the rest length
float GetLength() const { return m_length; }
/// Set the rest length
/// @returns clamped rest length
float SetLength(float length);
/// Get the minimum length
float GetMinLength() const { return m_minLength; }
/// Set the minimum length
/// @returns the clamped minimum length
float SetMinLength(float minLength);
/// Get the maximum length
float GetMaxLength() const { return m_maxLength; }
/// Set the maximum length
/// @returns the clamped maximum length
float SetMaxLength(float maxLength);
/// Get the current length
float GetCurrentLength() const;
/// Set/get the linear stiffness in N/m
void SetStiffness(float stiffness) { m_stiffness = stiffness; }
float GetStiffness() const { return m_stiffness; }
@@ -102,6 +129,9 @@ public:
/// Dump joint to dmLog
void Dump() override;
///
void Draw(b2Draw* draw) const override;
protected:
friend class b2Joint;
@@ -114,13 +144,17 @@ protected:
float m_stiffness;
float m_damping;
float m_bias;
float m_length;
float m_minLength;
float m_maxLength;
// Solver shared
b2Vec2 m_localAnchorA;
b2Vec2 m_localAnchorB;
float m_gamma;
float m_impulse;
float m_length;
float m_lowerImpulse;
float m_upperImpulse;
// Solver temp
int32 m_indexA;
@@ -130,10 +164,12 @@ protected:
b2Vec2 m_rB;
b2Vec2 m_localCenterA;
b2Vec2 m_localCenterB;
float m_currentLength;
float m_invMassA;
float m_invMassB;
float m_invIA;
float m_invIB;
float m_softMass;
float m_mass;
};