|
@@ -26,6 +26,9 @@ public:
|
|
/// Maximum force with which the character can push other bodies (N).
|
|
/// Maximum force with which the character can push other bodies (N).
|
|
float mMaxStrength = 100.0f;
|
|
float mMaxStrength = 100.0f;
|
|
|
|
|
|
|
|
+ /// An extra offset applied to the shape in local space. This allows applying an extra offset to the shape in local space.
|
|
|
|
+ Vec3 mShapeOffset = Vec3::sZero();
|
|
|
|
+
|
|
///@name Movement settings
|
|
///@name Movement settings
|
|
float mPredictiveContactDistance = 0.1f; ///< How far to scan outside of the shape for predictive contacts
|
|
float mPredictiveContactDistance = 0.1f; ///< How far to scan outside of the shape for predictive contacts
|
|
uint mMaxCollisionIterations = 5; ///< Max amount of collision loops
|
|
uint mMaxCollisionIterations = 5; ///< Max amount of collision loops
|
|
@@ -49,8 +52,6 @@ public:
|
|
class CharacterContactListener
|
|
class CharacterContactListener
|
|
{
|
|
{
|
|
public:
|
|
public:
|
|
- JPH_OVERRIDE_NEW_DELETE
|
|
|
|
-
|
|
|
|
/// Destructor
|
|
/// Destructor
|
|
virtual ~CharacterContactListener() = default;
|
|
virtual ~CharacterContactListener() = default;
|
|
|
|
|
|
@@ -121,14 +122,28 @@ public:
|
|
RMat44 GetCenterOfMassTransform() const { return GetCenterOfMassTransform(mPosition, mRotation, mShape); }
|
|
RMat44 GetCenterOfMassTransform() const { return GetCenterOfMassTransform(mPosition, mRotation, mShape); }
|
|
|
|
|
|
/// Character mass (kg)
|
|
/// Character mass (kg)
|
|
|
|
+ float GetMass() const { return mMass; }
|
|
void SetMass(float inMass) { mMass = inMass; }
|
|
void SetMass(float inMass) { mMass = inMass; }
|
|
|
|
|
|
/// Maximum force with which the character can push other bodies (N)
|
|
/// Maximum force with which the character can push other bodies (N)
|
|
|
|
+ float GetMaxStrength() const { return mMaxStrength; }
|
|
void SetMaxStrength(float inMaxStrength) { mMaxStrength = inMaxStrength; }
|
|
void SetMaxStrength(float inMaxStrength) { mMaxStrength = inMaxStrength; }
|
|
|
|
|
|
|
|
+ /// This value governs how fast a penetration will be resolved, 0 = nothing is resolved, 1 = everything in one update
|
|
|
|
+ float GetPenetrationRecoverySpeed() const { return mPenetrationRecoverySpeed; }
|
|
|
|
+ void SetPenetrationRecoverySpeed(float inSpeed) { mPenetrationRecoverySpeed = inSpeed; }
|
|
|
|
+
|
|
/// Character padding
|
|
/// Character padding
|
|
float GetCharacterPadding() const { return mCharacterPadding; }
|
|
float GetCharacterPadding() const { return mCharacterPadding; }
|
|
|
|
|
|
|
|
+ /// Max num hits to collect in order to avoid excess of contact points collection
|
|
|
|
+ uint GetMaxNumHits() const { return mMaxNumHits; }
|
|
|
|
+ void SetMaxNumHits(uint inMaxHits) { mMaxNumHits = inMaxHits; }
|
|
|
|
+
|
|
|
|
+ /// An extra offset applied to the shape in local space. This allows applying an extra offset to the shape in local space. Note that setting it on the fly can cause the shape to teleport into collision.
|
|
|
|
+ Vec3 GetShapeOffset() const { return mShapeOffset; }
|
|
|
|
+ void SetShapeOffset(Vec3Arg inShapeOffset) { mShapeOffset = inShapeOffset; }
|
|
|
|
+
|
|
/// This function can be called prior to calling Update() to convert a desired velocity into a velocity that won't make the character move further onto steep slopes.
|
|
/// This function can be called prior to calling Update() to convert a desired velocity into a velocity that won't make the character move further onto steep slopes.
|
|
/// This velocity can then be set on the character using SetLinearVelocity()
|
|
/// This velocity can then be set on the character using SetLinearVelocity()
|
|
/// @param inDesiredVelocity Velocity to clamp against steep walls
|
|
/// @param inDesiredVelocity Velocity to clamp against steep walls
|
|
@@ -235,7 +250,6 @@ public:
|
|
static inline bool sDrawStickToFloor = false; ///< Draw the state of the stick to floor algorithm
|
|
static inline bool sDrawStickToFloor = false; ///< Draw the state of the stick to floor algorithm
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-private:
|
|
|
|
// Encapsulates a collision contact
|
|
// Encapsulates a collision contact
|
|
struct Contact
|
|
struct Contact
|
|
{
|
|
{
|
|
@@ -258,6 +272,10 @@ private:
|
|
using TempContactList = std::vector<Contact, STLTempAllocator<Contact>>;
|
|
using TempContactList = std::vector<Contact, STLTempAllocator<Contact>>;
|
|
using ContactList = Array<Contact>;
|
|
using ContactList = Array<Contact>;
|
|
|
|
|
|
|
|
+ /// Access to the internal list of contacts that the character has found.
|
|
|
|
+ const ContactList & GetActiveContacts() const { return mActiveContacts; }
|
|
|
|
+
|
|
|
|
+private:
|
|
// A contact that needs to be ignored
|
|
// A contact that needs to be ignored
|
|
struct IgnoredContact
|
|
struct IgnoredContact
|
|
{
|
|
{
|
|
@@ -362,7 +380,7 @@ private:
|
|
// This function returns the actual center of mass of the shape, not corrected for the character padding
|
|
// This function returns the actual center of mass of the shape, not corrected for the character padding
|
|
inline RMat44 GetCenterOfMassTransform(RVec3Arg inPosition, QuatArg inRotation, const Shape *inShape) const
|
|
inline RMat44 GetCenterOfMassTransform(RVec3Arg inPosition, QuatArg inRotation, const Shape *inShape) const
|
|
{
|
|
{
|
|
- return RMat44::sRotationTranslation(inRotation, inPosition).PreTranslated(inShape->GetCenterOfMass()).PostTranslated(mCharacterPadding * mUp);
|
|
|
|
|
|
+ return RMat44::sRotationTranslation(inRotation, inPosition).PreTranslated(mShapeOffset + inShape->GetCenterOfMass()).PostTranslated(mCharacterPadding * mUp);
|
|
}
|
|
}
|
|
|
|
|
|
// Our main listener for contacts
|
|
// Our main listener for contacts
|
|
@@ -384,6 +402,9 @@ private:
|
|
// Maximum force with which the character can push other bodies (N)
|
|
// Maximum force with which the character can push other bodies (N)
|
|
float mMaxStrength;
|
|
float mMaxStrength;
|
|
|
|
|
|
|
|
+ // An extra offset applied to the shape in local space. This allows applying an extra offset to the shape in local space.
|
|
|
|
+ Vec3 mShapeOffset = Vec3::sZero();
|
|
|
|
+
|
|
// Current position (of the base, not the center of mass)
|
|
// Current position (of the base, not the center of mass)
|
|
RVec3 mPosition = RVec3::sZero();
|
|
RVec3 mPosition = RVec3::sZero();
|
|
|
|
|