|
@@ -52,10 +52,10 @@ public:
|
|
inline Vec3 GetAngularVelocity() const { JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sVelocityAccess, BodyAccess::EAccess::Read)); return mAngularVelocity; }
|
|
inline Vec3 GetAngularVelocity() const { JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sVelocityAccess, BodyAccess::EAccess::Read)); return mAngularVelocity; }
|
|
|
|
|
|
/// Set world space angular velocity of the center of mass
|
|
/// Set world space angular velocity of the center of mass
|
|
- void SetAngularVelocity(Vec3Arg inAngularVelocity) { JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sVelocityAccess, BodyAccess::EAccess::ReadWrite)); JPH_ASSERT(inAngularVelocity.Length() <= mMaxAngularVelocity); mAngularVelocity = inAngularVelocity; }
|
|
|
|
|
|
+ void SetAngularVelocity(Vec3Arg inAngularVelocity) { JPH_ASSERT(BodyAccess::sCheckRights(BodyAccess::sVelocityAccess, BodyAccess::EAccess::ReadWrite)); JPH_ASSERT(inAngularVelocity.Length() <= mMaxAngularVelocity); mAngularVelocity = LockAngular(inAngularVelocity); }
|
|
|
|
|
|
/// Set world space angular velocity of the center of mass, will make sure the value is clamped against the maximum angular velocity
|
|
/// Set world space angular velocity of the center of mass, will make sure the value is clamped against the maximum angular velocity
|
|
- void SetAngularVelocityClamped(Vec3Arg inAngularVelocity) { mAngularVelocity = inAngularVelocity; ClampAngularVelocity(); }
|
|
|
|
|
|
+ void SetAngularVelocityClamped(Vec3Arg inAngularVelocity) { mAngularVelocity = LockAngular(inAngularVelocity); ClampAngularVelocity(); }
|
|
|
|
|
|
/// Set velocity of body such that it will be rotate/translate by inDeltaPosition/Rotation in inDeltaTime seconds.
|
|
/// Set velocity of body such that it will be rotate/translate by inDeltaPosition/Rotation in inDeltaTime seconds.
|
|
inline void MoveKinematic(Vec3Arg inDeltaPosition, QuatArg inDeltaRotation, float inDeltaTime);
|
|
inline void MoveKinematic(Vec3Arg inDeltaPosition, QuatArg inDeltaRotation, float inDeltaTime);
|
|
@@ -110,7 +110,7 @@ public:
|
|
/// Set the inverse inertia tensor in local space by setting the diagonal and the rotation: \f$I_{body}^{-1} = R \: D \: R^{-1}\f$.
|
|
/// Set the inverse inertia tensor in local space by setting the diagonal and the rotation: \f$I_{body}^{-1} = R \: D \: R^{-1}\f$.
|
|
/// Note that mass and inertia are linearly related (e.g. inertia of a sphere with mass m and radius r is \f$2/5 \: m \: r^2\f$).
|
|
/// Note that mass and inertia are linearly related (e.g. inertia of a sphere with mass m and radius r is \f$2/5 \: m \: r^2\f$).
|
|
/// If you change inertia, mass should probably change as well. See MassProperties::ScaleToMass.
|
|
/// If you change inertia, mass should probably change as well. See MassProperties::ScaleToMass.
|
|
- /// If you don't allow all rotational degrees of freedom, make sure that the corresponding diagonal elements are zero (see EAllowedDOFs).
|
|
|
|
|
|
+ /// If all your rotation degrees of freedom are restricted, make sure this is zero (see EAllowedDOFs).
|
|
void SetInverseInertia(Vec3Arg inDiagonal, QuatArg inRot) { mInvInertiaDiagonal = inDiagonal; mInertiaRotation = inRot; }
|
|
void SetInverseInertia(Vec3Arg inDiagonal, QuatArg inRot) { mInvInertiaDiagonal = inDiagonal; mInertiaRotation = inRot; }
|
|
|
|
|
|
/// Get inverse inertia matrix (\f$I_{body}^{-1}\f$). Will be a matrix of zeros for a static or kinematic object.
|
|
/// Get inverse inertia matrix (\f$I_{body}^{-1}\f$). Will be a matrix of zeros for a static or kinematic object.
|
|
@@ -140,21 +140,30 @@ public:
|
|
// Reset the total accumulated torque, not that this will be done automatically after every time step.
|
|
// Reset the total accumulated torque, not that this will be done automatically after every time step.
|
|
JPH_INLINE void ResetTorque() { mTorque = Float3(0, 0, 0); }
|
|
JPH_INLINE void ResetTorque() { mTorque = Float3(0, 0, 0); }
|
|
|
|
|
|
|
|
+ /// Returns a vector where the linear components that are not allowed by mAllowedDOFs are set to 0 and the rest to 0xffffffff
|
|
|
|
+ JPH_INLINE UVec4 GetLinearDOFsMask() const
|
|
|
|
+ {
|
|
|
|
+ UVec4 mask(uint32(EAllowedDOFs::TranslationX), uint32(EAllowedDOFs::TranslationY), uint32(EAllowedDOFs::TranslationZ), 0);
|
|
|
|
+ return UVec4::sEquals(UVec4::sAnd(UVec4::sReplicate(uint32(mAllowedDOFs)), mask), mask);
|
|
|
|
+ }
|
|
|
|
+
|
|
/// Takes a translation vector inV and returns a vector where the components that are not allowed by mAllowedDOFs are set to 0
|
|
/// Takes a translation vector inV and returns a vector where the components that are not allowed by mAllowedDOFs are set to 0
|
|
JPH_INLINE Vec3 LockTranslation(Vec3Arg inV) const
|
|
JPH_INLINE Vec3 LockTranslation(Vec3Arg inV) const
|
|
{
|
|
{
|
|
- uint32 allowed_dofs = uint32(mAllowedDOFs);
|
|
|
|
- UVec4 allowed_dofs_mask = UVec4(allowed_dofs << 31, allowed_dofs << 30, allowed_dofs << 29, 0).ArithmeticShiftRight<31>();
|
|
|
|
- return Vec3::sAnd(inV, Vec3(allowed_dofs_mask.ReinterpretAsFloat()));
|
|
|
|
|
|
+ return Vec3::sAnd(inV, Vec3(GetLinearDOFsMask().ReinterpretAsFloat()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// Returns a vector where the angular components that are not allowed by mAllowedDOFs are set to 0 and the rest to 0xffffffff
|
|
|
|
+ JPH_INLINE UVec4 GetAngularDOFsMask() const
|
|
|
|
+ {
|
|
|
|
+ UVec4 mask(uint32(EAllowedDOFs::RotationX), uint32(EAllowedDOFs::RotationY), uint32(EAllowedDOFs::RotationZ), 0);
|
|
|
|
+ return UVec4::sEquals(UVec4::sAnd(UVec4::sReplicate(uint32(mAllowedDOFs)), mask), mask);
|
|
}
|
|
}
|
|
|
|
|
|
/// Takes an angular velocity / torque vector inV and returns a vector where the components that are not allowed by mAllowedDOFs are set to 0
|
|
/// Takes an angular velocity / torque vector inV and returns a vector where the components that are not allowed by mAllowedDOFs are set to 0
|
|
- /// Interfaces like Body::AddTorque and Body::SetAngularVelocity don't automatically clear the components that are not allowed by mAllowedDOFs so this function can be used to do that.
|
|
|
|
JPH_INLINE Vec3 LockAngular(Vec3Arg inV) const
|
|
JPH_INLINE Vec3 LockAngular(Vec3Arg inV) const
|
|
{
|
|
{
|
|
- uint32 allowed_dofs = uint32(mAllowedDOFs);
|
|
|
|
- UVec4 allowed_dofs_mask = UVec4(allowed_dofs << 28, allowed_dofs << 27, allowed_dofs << 26, 0).ArithmeticShiftRight<31>();
|
|
|
|
- return Vec3::sAnd(inV, Vec3(allowed_dofs_mask.ReinterpretAsFloat()));
|
|
|
|
|
|
+ return Vec3::sAnd(inV, Vec3(GetAngularDOFsMask().ReinterpretAsFloat()));
|
|
}
|
|
}
|
|
|
|
|
|
/// Used only when this body is dynamic and colliding. Override for the number of solver velocity iterations to run, 0 means use the default in PhysicsSettings::mNumVelocitySteps. The number of iterations to use is the max of all contacts and constraints in the island.
|
|
/// Used only when this body is dynamic and colliding. Override for the number of solver velocity iterations to run, 0 means use the default in PhysicsSettings::mNumVelocitySteps. The number of iterations to use is the max of all contacts and constraints in the island.
|