Repository: FlaxEngine/FlaxEngine
File: Source/Engine/Physics/Actors/RigidBody.cpp (C++)

Code before:
    {
        const auto collider = dynamic_cast<Collider*>(Children[i]);
        if (collider && collider->GetAttachedRigidBody() == this)
        {
            collider->ClosestPoint(position, tmp);
            const Real dstSqr = Vector3::DistanceSquared(position, tmp);
            if (dstSqr < minDistanceSqr)
            {
                minDistanceSqr = dstSqr;
                result = tmp;
            }
        }
    }
}

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;

Review comment (suggestion):
Use `EnumHasAnyFlags(GetConstraints(). RigidbodyConstraints::LockRotationX)` for readability (the same for Y/Z axes and translation axes too).

Code after:
    {
        const auto collider = dynamic_cast<Collider*>(Children[i]);
        if (collider && collider->GetAttachedRigidBody() == this)
        {
            collider->ClosestPoint(position, tmp);
            const Real dstSqr = Vector3::DistanceSquared(position, tmp);
            if (dstSqr < minDistanceSqr)
            {
                minDistanceSqr = dstSqr;
                result = tmp;
            }
        }
    }
}

void RigidBody::AddMovement(const Vector3& translation, const Quaternion& rotation)
{
    // filter rotation according to constraints
    Quaternion allowedRotation;
    if (EnumHasAllFlags(GetConstraints(), RigidbodyConstraints::LockRotation))
        allowedRotation = Quaternion::Identity;
    else
    {
        Float3 euler = rotation.GetEuler();
        if (EnumHasAnyFlags(GetConstraints(), RigidbodyConstraints::LockRotationX))
            euler.X = 0;
        if (EnumHasAnyFlags(GetConstraints(), RigidbodyConstraints::LockRotationY))
            euler.Y = 0;
        if (EnumHasAnyFlags(GetConstraints(), RigidbodyConstraints::LockRotationZ))
            euler.Z = 0;
        allowedRotation = Quaternion::Euler(euler);
    }

    // filter translation according to the constraints
    auto allowedTranslation = translation;
    if (EnumHasAllFlags(GetConstraints(), RigidbodyConstraints::LockPosition))
        allowedTranslation = Vector3::Zero;
    else
    {
        if (EnumHasAnyFlags(GetConstraints(), RigidbodyConstraints::LockPositionX))
            allowedTranslation.X = 0;
        if (EnumHasAnyFlags(GetConstraints(), RigidbodyConstraints::LockPositionY))
            allowedTranslation.Y = 0;
        if (EnumHasAnyFlags(GetConstraints(), RigidbodyConstraints::LockPositionZ))
            allowedTranslation.Z = 0;
    }
    Transform t;
    t.Translation = _transform.Translation + allowedTranslation;
    t.Orientation = _transform.Orientation * allowedRotation;
    t.Scale = _transform.Scale;
    SetTransform(t);