move constraints checks to RigidBody
This commit is contained in:
@@ -300,6 +300,46 @@ void RigidBody::ClosestPoint(const Vector3& position, Vector3& result) const
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBody::AddMovement(const Vector3& translation, const Quaternion& rotation)
|
||||
{
|
||||
// filter rotation according to constraints
|
||||
Quaternion allowedRotation;
|
||||
if (static_cast<unsigned int>(GetConstraints()) & static_cast<unsigned int>(RigidbodyConstraints::LockRotation))
|
||||
allowedRotation = Quaternion::Identity;
|
||||
else
|
||||
{
|
||||
Float3 euler = rotation.GetEuler();
|
||||
const auto constraints = static_cast<unsigned int>(GetConstraints());
|
||||
if (constraints & static_cast<unsigned int>(RigidbodyConstraints::LockRotationX))
|
||||
euler.X = 0;
|
||||
if (constraints & static_cast<unsigned int>(RigidbodyConstraints::LockRotationY))
|
||||
euler.Y = 0;
|
||||
if (constraints & static_cast<unsigned int>(RigidbodyConstraints::LockRotationZ))
|
||||
euler.Z = 0;
|
||||
allowedRotation = Quaternion::Euler(euler);
|
||||
}
|
||||
|
||||
// filter translation according to the constraints
|
||||
auto allowedTranslation = translation;
|
||||
if (static_cast<unsigned int>(GetConstraints()) & static_cast<unsigned int>(RigidbodyConstraints::LockPosition))
|
||||
allowedTranslation = Vector3::Zero;
|
||||
else
|
||||
{
|
||||
const auto constraints = static_cast<unsigned int>(GetConstraints());
|
||||
if (constraints & static_cast<unsigned int>(RigidbodyConstraints::LockPositionX))
|
||||
allowedTranslation.X = 0;
|
||||
if (constraints & static_cast<unsigned int>(RigidbodyConstraints::LockPositionY))
|
||||
allowedTranslation.Y = 0;
|
||||
if (constraints & static_cast<unsigned int>(RigidbodyConstraints::LockPositionZ))
|
||||
allowedTranslation.Z = 0;
|
||||
}
|
||||
Transform t;
|
||||
t.Translation = _transform.Translation + allowedTranslation;
|
||||
t.Orientation = _transform.Orientation * allowedRotation;
|
||||
t.Scale = _transform.Scale;
|
||||
SetTransform(t);
|
||||
}
|
||||
|
||||
void RigidBody::OnCollisionEnter(const Collision& c)
|
||||
{
|
||||
CollisionEnter(c);
|
||||
|
||||
@@ -430,6 +430,12 @@ public:
|
||||
/// <param name="result">The result point on the rigidbody shape that is closest to the specified location.</param>
|
||||
API_FUNCTION() void ClosestPoint(const Vector3& position, API_PARAM(Out) Vector3& result) const;
|
||||
|
||||
/// <summary>
|
||||
/// Moves and rotates the rigidbody in world space within the limits of defined constraints.
|
||||
/// </summary>
|
||||
/// <param name="translation">The translation vector.</param>
|
||||
/// <param name="rotation">The rotation quaternion.</param>
|
||||
API_FUNCTION() void AddMovement(const Vector3& translation, const Quaternion& rotation) override;
|
||||
public:
|
||||
/// <summary>
|
||||
/// Occurs when a collision start gets registered for this rigidbody (it collides with something).
|
||||
|
||||
Reference in New Issue
Block a user