|
@@ -7,35 +7,73 @@
|
|
|
|
|
|
|
|
namespace BansheeEngine
|
|
namespace BansheeEngine
|
|
|
{
|
|
{
|
|
|
|
|
+ /** @addtogroup Physics
|
|
|
|
|
+ * @{
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Base class for all Joint types. Joints constrain how two rigidbodies move relative to one another (e.g. a door
|
|
|
|
|
+ * hinge). One of the bodies in the joint must always be movable (i.e. non-kinematic).
|
|
|
|
|
+ */
|
|
|
class BS_CORE_EXPORT Joint
|
|
class BS_CORE_EXPORT Joint
|
|
|
{
|
|
{
|
|
|
public:
|
|
public:
|
|
|
virtual ~Joint() { }
|
|
virtual ~Joint() { }
|
|
|
|
|
|
|
|
|
|
+ /** @copydoc FJoint::getBody */
|
|
|
inline Rigidbody* getBody(JointBody body) const;
|
|
inline Rigidbody* getBody(JointBody body) const;
|
|
|
|
|
+
|
|
|
|
|
+ /** @copydoc FJoint::setBody */
|
|
|
inline void setBody(JointBody body, Rigidbody* value);
|
|
inline void setBody(JointBody body, Rigidbody* value);
|
|
|
|
|
|
|
|
|
|
+ /** @copydoc FJoint::getPosition */
|
|
|
inline Vector3 getPosition(JointBody body) const;
|
|
inline Vector3 getPosition(JointBody body) const;
|
|
|
|
|
+
|
|
|
|
|
+ /** @copydoc FJoint::getRotation */
|
|
|
inline Quaternion getRotation(JointBody body) const;
|
|
inline Quaternion getRotation(JointBody body) const;
|
|
|
|
|
+
|
|
|
|
|
+ /** @copydoc FJoint::setTransform */
|
|
|
inline void setTransform(JointBody body, const Vector3& position, const Quaternion& rotation);
|
|
inline void setTransform(JointBody body, const Vector3& position, const Quaternion& rotation);
|
|
|
|
|
|
|
|
|
|
+ /** @copydoc FJoint::getBreakForce */
|
|
|
inline float getBreakForce() const;
|
|
inline float getBreakForce() const;
|
|
|
|
|
+
|
|
|
|
|
+ /** @copydoc FJoint::setBreakForce */
|
|
|
inline void setBreakForce(float force);
|
|
inline void setBreakForce(float force);
|
|
|
|
|
|
|
|
|
|
+ /** @copydoc FJoint::getBreakTorque */
|
|
|
inline float getBreakTorque() const;
|
|
inline float getBreakTorque() const;
|
|
|
|
|
+
|
|
|
|
|
+ /** @copydoc FJoint::setBreakTorque */
|
|
|
inline void setBreakTorque(float torque);
|
|
inline void setBreakTorque(float torque);
|
|
|
|
|
|
|
|
|
|
+ /** @copydoc FJoint::getEnableCollision */
|
|
|
inline bool getEnableCollision() const;
|
|
inline bool getEnableCollision() const;
|
|
|
|
|
+
|
|
|
|
|
+ /** @copydoc FJoint::setEnableCollision */
|
|
|
inline void setEnableCollision(bool value);
|
|
inline void setEnableCollision(bool value);
|
|
|
|
|
|
|
|
|
|
+ /** Triggered when the joint's break force or torque is exceeded. */
|
|
|
Event<void()> onJointBreak;
|
|
Event<void()> onJointBreak;
|
|
|
protected:
|
|
protected:
|
|
|
FJoint* mInternal = nullptr;
|
|
FJoint* mInternal = nullptr;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Controls spring parameters for a physics joint limits. If a limit is soft (body bounces back due to restition when
|
|
|
|
|
+ * the limit is reached) the spring will pull the body back towards the limit using the specified parameters.
|
|
|
|
|
+ */
|
|
|
struct Spring
|
|
struct Spring
|
|
|
{
|
|
{
|
|
|
|
|
+ /** Constructs a spring with no force. */
|
|
|
Spring() { }
|
|
Spring() { }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Constructs a spring.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param stiffness Spring strength. Force proportional to the position error.
|
|
|
|
|
+ * @param damping Damping strength. Force propertional to the velocity error.
|
|
|
|
|
+ */
|
|
|
Spring(float stiffness, float damping)
|
|
Spring(float stiffness, float damping)
|
|
|
:stiffness(stiffness), damping(damping)
|
|
:stiffness(stiffness), damping(damping)
|
|
|
{ }
|
|
{ }
|
|
@@ -45,21 +83,72 @@ namespace BansheeEngine
|
|
|
return stiffness == other.stiffness && damping == other.damping;
|
|
return stiffness == other.stiffness && damping == other.damping;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** Spring strength. Force proportional to the position error. */
|
|
|
float stiffness = 0.0f;
|
|
float stiffness = 0.0f;
|
|
|
|
|
+
|
|
|
|
|
+ /** Damping strength. Force propertional to the velocity error. */
|
|
|
float damping = 0.0f;
|
|
float damping = 0.0f;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- struct LimitLinearRange
|
|
|
|
|
|
|
+ /** Contains common values used by all Joint limit types. */
|
|
|
|
|
+ struct LimitCommon
|
|
|
{
|
|
{
|
|
|
|
|
+ LimitCommon(float contactDist = -1.0f)
|
|
|
|
|
+ :contactDist(contactDist)
|
|
|
|
|
+ { }
|
|
|
|
|
+
|
|
|
|
|
+ LimitCommon(const Spring& spring, float restitution = 0.0f)
|
|
|
|
|
+ :spring(spring), restitution(restitution)
|
|
|
|
|
+ { }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Distance from the limit at which it becomes active. Allows the solver to activate earlier than the limit is
|
|
|
|
|
+ * reached to avoid breaking the limit.
|
|
|
|
|
+ */
|
|
|
|
|
+ float contactDist = -1.0f;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Controls how do objects react when the limit is reached, values closer to zero specify non-ellastic collision,
|
|
|
|
|
+ * while those closer to one specify more ellastic (i.e bouncy) collision. Must be in [0, 1] range.
|
|
|
|
|
+ */
|
|
|
|
|
+ float restitution = 0.0f;
|
|
|
|
|
+
|
|
|
|
|
+ /** Spring that controls how are the bodies pulled back towards the limit when they breach it. */
|
|
|
|
|
+ Spring spring;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ /** Represents a joint limit between two distance values. Lower value must be less than the upper value. */
|
|
|
|
|
+ struct LimitLinearRange : LimitCommon
|
|
|
|
|
+ {
|
|
|
|
|
+ /** Constructs an empty limit. */
|
|
|
LimitLinearRange()
|
|
LimitLinearRange()
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param lower Lower distance of the limit. Must be less than @p upper.
|
|
|
|
|
+ * @param upper Upper distance of the limit. Must be more than @p lower.
|
|
|
|
|
+ * @param contactDist Distance from the limit at which it becomes active. Allows the solver to activate earlier
|
|
|
|
|
+ * than the limit is reached to avoid breaking the limit. Specify -1 for the default.
|
|
|
|
|
+ */
|
|
|
LimitLinearRange(float lower, float upper, float contactDist = -1.0f)
|
|
LimitLinearRange(float lower, float upper, float contactDist = -1.0f)
|
|
|
- :lower(lower), upper(upper), contactDist(contactDist)
|
|
|
|
|
|
|
+ :LimitCommon(contactDist), lower(lower), upper(upper)
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
- LimitLinearRange(float lower, float upper, const Spring& spring)
|
|
|
|
|
- :lower(lower), upper(upper), spring(spring)
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
|
|
|
|
|
+ * parameter and will be pulled back towards the limit by the provided spring.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param lower Lower distance of the limit. Must be less than @p upper.
|
|
|
|
|
+ * @param upper Upper distance of the limit. Must be more than @p lower.
|
|
|
|
|
+ * @param spring Spring that controls how are the bodies pulled back towards the limit when they breach it.
|
|
|
|
|
+ * @param resitution Controls how do objects react when the limit is reached, values closer to zero specify
|
|
|
|
|
+ * non-ellastic collision, while those closer to one specify more ellastic (i.e bouncy)
|
|
|
|
|
+ * collision. Must be in [0, 1] range.
|
|
|
|
|
+ */
|
|
|
|
|
+ LimitLinearRange(float lower, float upper, const Spring& spring, float restitution = 0.0f)
|
|
|
|
|
+ :LimitCommon(spring, restitution), lower(lower), upper(upper)
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
bool operator==(const LimitLinearRange& other) const
|
|
bool operator==(const LimitLinearRange& other) const
|
|
@@ -68,24 +157,43 @@ namespace BansheeEngine
|
|
|
restitution == other.restitution && spring == other.spring;
|
|
restitution == other.restitution && spring == other.spring;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- float lower = 0.0f;
|
|
|
|
|
|
|
+ /** Lower distance of the limit. Must be less than #upper. */
|
|
|
|
|
+ float lower = 0.0f;
|
|
|
|
|
+
|
|
|
|
|
+ /** Upper distance of the limit. Must be more than #lower. */
|
|
|
float upper = 0.0f;
|
|
float upper = 0.0f;
|
|
|
- float contactDist = -1.0f;
|
|
|
|
|
- float restitution = 0.0f;
|
|
|
|
|
- Spring spring;
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- struct LimitLinear
|
|
|
|
|
|
|
+ /** Represents a joint limit between zero a single distance value. */
|
|
|
|
|
+ struct LimitLinear : LimitCommon
|
|
|
{
|
|
{
|
|
|
|
|
+ /** Constructs an empty limit. */
|
|
|
LimitLinear()
|
|
LimitLinear()
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param extent Distance at which the limit becomes active.
|
|
|
|
|
+ * @param contactDist Distance from the limit at which it becomes active. Allows the solver to activate earlier
|
|
|
|
|
+ * than the limit is reached to avoid breaking the limit. Specify -1 for the default.
|
|
|
|
|
+ */
|
|
|
LimitLinear(float extent, float contactDist = -1.0f)
|
|
LimitLinear(float extent, float contactDist = -1.0f)
|
|
|
- :extent(extent), contactDist(contactDist)
|
|
|
|
|
|
|
+ :LimitCommon(contactDist), extent(extent)
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
- LimitLinear(float extent,const Spring& spring)
|
|
|
|
|
- :extent(extent), spring(spring)
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
|
|
|
|
|
+ * parameter and will be pulled back towards the limit by the provided spring.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param extent Distance at which the limit becomes active.
|
|
|
|
|
+ * @param spring Spring that controls how are the bodies pulled back towards the limit when they breach it.
|
|
|
|
|
+ * @param resitution Controls how do objects react when the limit is reached, values closer to zero specify
|
|
|
|
|
+ * non-ellastic collision, while those closer to one specify more ellastic (i.e bouncy)
|
|
|
|
|
+ * collision. Must be in [0, 1] range.
|
|
|
|
|
+ */
|
|
|
|
|
+ LimitLinear(float extent, const Spring& spring, float restitution = 0.0f)
|
|
|
|
|
+ :LimitCommon(spring, restitution), extent(extent)
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
bool operator==(const LimitLinear& other) const
|
|
bool operator==(const LimitLinear& other) const
|
|
@@ -94,23 +202,42 @@ namespace BansheeEngine
|
|
|
spring == other.spring;
|
|
spring == other.spring;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** Distance at which the limit becomes active. */
|
|
|
float extent = 0.0f;
|
|
float extent = 0.0f;
|
|
|
- float contactDist = -1.0f;
|
|
|
|
|
- float restitution = 0.0f;
|
|
|
|
|
- Spring spring;
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- struct LimitAngularRange
|
|
|
|
|
|
|
+ /** Represents a joint limit between two angles. */
|
|
|
|
|
+ struct LimitAngularRange : LimitCommon
|
|
|
{
|
|
{
|
|
|
|
|
+ /** Constructs an empty limit. */
|
|
|
LimitAngularRange()
|
|
LimitAngularRange()
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param lower Lower angle of the limit. Must be less than @p upper.
|
|
|
|
|
+ * @param upper Upper angle of the limit. Must be more than @p lower.
|
|
|
|
|
+ * @param contactDist Distance from the limit at which it becomes active. Allows the solver to activate earlier
|
|
|
|
|
+ * than the limit is reached to avoid breaking the limit. Specify -1 for the default.
|
|
|
|
|
+ */
|
|
|
LimitAngularRange(Radian lower, Radian upper, float contactDist = -1.0f)
|
|
LimitAngularRange(Radian lower, Radian upper, float contactDist = -1.0f)
|
|
|
- :lower(lower), upper(upper), contactDist(contactDist)
|
|
|
|
|
|
|
+ :LimitCommon(contactDist), lower(lower), upper(upper)
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
- LimitAngularRange(Radian lower, Radian upper, const Spring& spring)
|
|
|
|
|
- :lower(lower), upper(upper), spring(spring)
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
|
|
|
|
|
+ * parameter and will be pulled back towards the limit by the provided spring.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param lower Lower angle of the limit. Must be less than @p upper.
|
|
|
|
|
+ * @param upper Upper angle of the limit. Must be more than @p lower.
|
|
|
|
|
+ * @param spring Spring that controls how are the bodies pulled back towards the limit when they breach it.
|
|
|
|
|
+ * @param resitution Controls how do objects react when the limit is reached, values closer to zero specify
|
|
|
|
|
+ * non-ellastic collision, while those closer to one specify more ellastic (i.e bouncy)
|
|
|
|
|
+ * collision. Must be in [0, 1] range.
|
|
|
|
|
+ */
|
|
|
|
|
+ LimitAngularRange(Radian lower, Radian upper, const Spring& spring, float restitution = 0.0f)
|
|
|
|
|
+ :LimitCommon(spring, restitution), lower(lower), upper(upper)
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
bool operator==(const LimitAngularRange& other) const
|
|
bool operator==(const LimitAngularRange& other) const
|
|
@@ -119,24 +246,46 @@ namespace BansheeEngine
|
|
|
restitution == other.restitution && spring == other.spring;
|
|
restitution == other.restitution && spring == other.spring;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** Lower angle of the limit. Must be less than #upper. */
|
|
|
Radian lower = Radian(0.0f);
|
|
Radian lower = Radian(0.0f);
|
|
|
|
|
+
|
|
|
|
|
+ /** Upper angle of the limit. Must be less than #lower. */
|
|
|
Radian upper = Radian(0.0f);
|
|
Radian upper = Radian(0.0f);
|
|
|
- float contactDist = -1.0f;
|
|
|
|
|
- float restitution = 0.0f;
|
|
|
|
|
- Spring spring;
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- struct LimitConeRange
|
|
|
|
|
|
|
+ /** Represents a joint limit that contraints movement to within an elliptical cone. */
|
|
|
|
|
+ struct LimitConeRange : LimitCommon
|
|
|
{
|
|
{
|
|
|
|
|
+ /** Constructs a limit with a 45 degree cone. */
|
|
|
LimitConeRange()
|
|
LimitConeRange()
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Constructs a hard limit. Once the limit is reached the movement of the attached bodies will come to a stop.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param yLimitAngle Y angle of the cone. Movement is constrainted between 0 and this angle on the Y axis.
|
|
|
|
|
+ * @param zLimitAngle Z angle of the cone. Movement is constrainted between 0 and this angle on the Z axis.
|
|
|
|
|
+ * @param contactDist Distance from the limit at which it becomes active. Allows the solver to activate
|
|
|
|
|
+ * earlier than the limit is reached to avoid breaking the limit. Specify -1 for the
|
|
|
|
|
+ * default.
|
|
|
|
|
+ */
|
|
|
LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, float contactDist = -1.0f)
|
|
LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, float contactDist = -1.0f)
|
|
|
- :yLimitAngle(yLimitAngle), zLimitAngle(zLimitAngle), contactDist(contactDist)
|
|
|
|
|
|
|
+ :LimitCommon(contactDist), yLimitAngle(yLimitAngle), zLimitAngle(zLimitAngle)
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
- LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, const Spring& spring)
|
|
|
|
|
- :yLimitAngle(yLimitAngle), zLimitAngle(zLimitAngle), spring(spring)
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Constructs a soft limit. Once the limit is reached the bodies will bounce back according to the resitution
|
|
|
|
|
+ * parameter and will be pulled back towards the limit by the provided spring.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param yLimitAngle Y angle of the cone. Movement is constrainted between 0 and this angle on the Y axis.
|
|
|
|
|
+ * @param zLimitAngle Z angle of the cone. Movement is constrainted between 0 and this angle on the Z axis.
|
|
|
|
|
+ * @param spring Spring that controls how are the bodies pulled back towards the limit when they breach it.
|
|
|
|
|
+ * @param resitution Controls how do objects react when the limit is reached, values closer to zero specify
|
|
|
|
|
+ * non-ellastic collision, while those closer to one specify more ellastic (i.e bouncy)
|
|
|
|
|
+ * collision. Must be in [0, 1] range.
|
|
|
|
|
+ */
|
|
|
|
|
+ LimitConeRange(Radian yLimitAngle, Radian zLimitAngle, const Spring& spring, float restitution = 0.0f)
|
|
|
|
|
+ :LimitCommon(spring, restitution), yLimitAngle(yLimitAngle), zLimitAngle(zLimitAngle)
|
|
|
{ }
|
|
{ }
|
|
|
|
|
|
|
|
bool operator==(const LimitConeRange& other) const
|
|
bool operator==(const LimitConeRange& other) const
|
|
@@ -145,10 +294,12 @@ namespace BansheeEngine
|
|
|
contactDist == other.contactDist && restitution == other.restitution && spring == other.spring;
|
|
contactDist == other.contactDist && restitution == other.restitution && spring == other.spring;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** Y angle of the cone. Movement is constrainted between 0 and this angle on the Y axis. */
|
|
|
Radian yLimitAngle = Radian(Math::PI * 0.5f);
|
|
Radian yLimitAngle = Radian(Math::PI * 0.5f);
|
|
|
|
|
+
|
|
|
|
|
+ /** Z angle of the cone. Movement is constrainted between 0 and this angle on the Z axis. */
|
|
|
Radian zLimitAngle = Radian(Math::PI * 0.5f);
|
|
Radian zLimitAngle = Radian(Math::PI * 0.5f);
|
|
|
- float contactDist = -1.0f;
|
|
|
|
|
- float restitution = 0.0f;
|
|
|
|
|
- Spring spring;
|
|
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+ /** @} */
|
|
|
}
|
|
}
|