Add Joint.SetJointOrientation utility

This commit is contained in:
Wojtek Figat
2021-11-03 12:24:41 +01:00
parent fc55f6c7e9
commit bd531aa6c2
2 changed files with 29 additions and 0 deletions

View File

@@ -101,6 +101,28 @@ void Joint::SetJointLocation(const Vector3& location)
}
}
FORCE_INLINE Quaternion WorldToLocal(const Quaternion& world, const Quaternion& orientation)
{
Quaternion rot;
const Quaternion invRotation = world.Conjugated();
Quaternion::Multiply(invRotation, orientation, rot);
rot.Normalize();
return rot;
}
void Joint::SetJointOrientation(const Quaternion& orientation)
{
if (GetParent())
{
SetLocalOrientation(WorldToLocal(GetParent()->GetOrientation(), orientation));
}
if (Target)
{
//SetTargetAnchor(Target->GetTransform().WorldToLocal(orientation));
SetTargetAnchorRotation(WorldToLocal(Target->GetOrientation(), orientation));
}
}
void Joint::GetCurrentForce(Vector3& linear, Vector3& angular) const
{
if (_joint && _joint->getConstraint())

View File

@@ -135,6 +135,13 @@ public:
/// <param name="location">The joint location to set (world-space).</param>
API_FUNCTION() void SetJointLocation(const Vector3& location);
/// <summary>
/// Sets the orientation of the joint by automatically computing local orientation and target anchor orientation to orient a joint at the given rotation (world-space).
/// </summary>
/// <remarks>Use this utility to automatically rotate joint at the given location after setting up joint parent and target.</remarks>
/// <param name="orientation">The joint orientation to set (world-space).</param>
API_FUNCTION() void SetJointOrientation(const Quaternion& orientation);
/// <summary>
/// Gets the current force applied by the solver to maintain all constraints.
/// </summary>