From 5e6b6133ca4d046f7513d57af00f7beeca54d049 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 27 Oct 2021 20:37:46 +0200 Subject: [PATCH] Add `Joint.SetJointLocation` for easier joints setup --- Source/Engine/Physics/Joints/Joint.cpp | 12 ++++++++++++ Source/Engine/Physics/Joints/Joint.h | 11 +++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Physics/Joints/Joint.cpp b/Source/Engine/Physics/Joints/Joint.cpp index d688041ff..f9808efc6 100644 --- a/Source/Engine/Physics/Joints/Joint.cpp +++ b/Source/Engine/Physics/Joints/Joint.cpp @@ -89,6 +89,18 @@ void Joint::SetTargetAnchorRotation(const Quaternion& value) } } +void Joint::SetJointLocation(const Vector3& location) +{ + if (GetParent()) + { + SetLocalPosition(GetParent()->GetTransform().WorldToLocal(location)); + } + if (Target) + { + SetTargetAnchor(Target->GetTransform().WorldToLocal(location)); + } +} + void Joint::GetCurrentForce(Vector3& linear, Vector3& angular) const { if (_joint && _joint->getConstraint()) diff --git a/Source/Engine/Physics/Joints/Joint.h b/Source/Engine/Physics/Joints/Joint.h index f2950874f..95d33c421 100644 --- a/Source/Engine/Physics/Joints/Joint.h +++ b/Source/Engine/Physics/Joints/Joint.h @@ -36,8 +36,6 @@ public: API_FIELD(Attributes="EditorOrder(0), DefaultValue(null), EditorDisplay(\"Joint\")") ScriptingObjectReference Target; -public: - /// /// Gets the break force. Determines the maximum force the joint can apply before breaking. Broken joints no longer participate in physics simulation. /// @@ -130,6 +128,13 @@ public: return _joint; } + /// + /// Sets the location of the joint by automatically computing local position and target anchor to place a joint at the given location (world-space). + /// + /// Use this utility to automatically place joint at the given location after setting up joint parent and target. + /// The joint location to set (world-space). + API_FUNCTION() void SetJointLocation(const Vector3& location); + /// /// Gets the current force applied by the solver to maintain all constraints. /// @@ -142,8 +147,6 @@ public: /// void Create(); -public: - /// /// Occurs when a joint gets broken during simulation. ///