Skip to content

Commit e73521b

Browse files
authored
Ability to drive hinge constraints with Ragdoll::DriveToPoseUsingMotors (jrouwe#1613)
Fixes jrouwe#1612
1 parent c99eeef commit e73521b

5 files changed

Lines changed: 46 additions & 0 deletions

File tree

Docs/ReleaseNotes.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
For breaking API changes see [this document](https://github.com/jrouwe/JoltPhysics/blob/master/Docs/APIChanges.md).
44

5+
## Unreleased Changes
6+
7+
### New functionality
8+
9+
* Added ability to drive hinge constraints with `Ragdoll::DriveToPoseUsingMotors`. This also adds `HingeConstraint::SetTargetOrientationBS` which sets the target angle in body space.
10+
* Added `JPH_USE_EXTERNAL_PROFILE` cmake option that allows overriding the behavior of the profile macros.
11+
12+
### Bug Fixes
13+
14+
* Fixed compiling in double precision and fixed issues with floating point contraction that caused unit test failures on LoongArch architecture.
15+
* Added an epsilon to the `CastRay` / `CastShape` early out condition to avoid dividing by a very small number and overflowing to INF. This can cause a float overflow exception.
16+
* Fixed Samples requiring Vulkan extension `VK_EXT_device_address_binding_report` without checking if it is available.
17+
518
## v5.3.0
619

720
### New functionality

Jolt/Physics/Constraints/HingeConstraint.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ float HingeConstraint::GetCurrentAngle() const
134134
return diff.GetRotationAngle(rotation1 * mLocalSpaceHingeAxis1);
135135
}
136136

137+
void HingeConstraint::SetTargetOrientationBS(QuatArg inOrientation)
138+
{
139+
// See: CalculateA1AndTheta
140+
//
141+
// The rotation between body 1 and 2 can be written as:
142+
//
143+
// q2 = q1 rh1 r0
144+
//
145+
// where rh1 is a rotation around local hinge axis 1, also:
146+
//
147+
// q2 = q1 inOrientation
148+
//
149+
// This means:
150+
//
151+
// rh1 r0 = inOrientation <=> rh1 = inOrientation * r0^-1
152+
Quat rh1 = inOrientation * mInvInitialOrientation;
153+
SetTargetAngle(rh1.GetRotationAngle(mLocalSpaceHingeAxis1));
154+
}
155+
137156
void HingeConstraint::SetLimits(float inLimitsMin, float inLimitsMax)
138157
{
139158
JPH_ASSERT(inLimitsMin <= 0.0f && inLimitsMin >= -JPH_PI);

Jolt/Physics/Constraints/HingeConstraint.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ class JPH_EXPORT HingeConstraint final : public TwoBodyConstraint
123123
void SetTargetAngle(float inAngle) { mTargetAngle = mHasLimits? Clamp(inAngle, mLimitsMin, mLimitsMax) : inAngle; } ///< rad
124124
float GetTargetAngle() const { return mTargetAngle; }
125125

126+
/// Set the target orientation in body space (R2 = R1 * inOrientation, where R1 and R2 are the world space rotations for body 1 and 2).
127+
/// Calculates the local space target angle and calls SetTargetAngle. Motor state must be EMotorState::Position for this to have any effect.
128+
/// May set the wrong angle if inOrientation contains large rotations around other axis than the hinge axis.
129+
void SetTargetOrientationBS(QuatArg inOrientation);
130+
126131
/// Update the rotation limits of the hinge, value in radians (see HingeConstraintSettings)
127132
void SetLimits(float inLimitsMin, float inLimitsMax);
128133
float GetLimitsMin() const { return mLimitsMin; }

Jolt/Physics/Ragdoll/Ragdoll.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <Jolt/Physics/Ragdoll/Ragdoll.h>
88
#include <Jolt/Physics/Constraints/SwingTwistConstraint.h>
9+
#include <Jolt/Physics/Constraints/HingeConstraint.h>
910
#include <Jolt/Physics/PhysicsSystem.h>
1011
#include <Jolt/Physics/Body/BodyLockMulti.h>
1112
#include <Jolt/Physics/Collision/GroupFilterTable.h>
@@ -635,6 +636,12 @@ void Ragdoll::DriveToPoseUsingMotors(const SkeletonPose &inPose)
635636
st_constraint->SetTwistMotorState(EMotorState::Position);
636637
st_constraint->SetTargetOrientationBS(joint_state.mRotation);
637638
}
639+
else if (sub_type == EConstraintSubType::Hinge)
640+
{
641+
HingeConstraint *h_constraint = static_cast<HingeConstraint *>(constraint);
642+
h_constraint->SetMotorState(EMotorState::Position);
643+
h_constraint->SetTargetOrientationBS(joint_state.mRotation);
644+
}
638645
else
639646
JPH_ASSERT(false, "Constraint type not implemented!");
640647
}

Samples/Utils/RagdollLoader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ RagdollSettings *RagdollLoader::sLoad(const char *inFileName, EMotionType inMoti
7070
settings->mLimitsMin = -original->mNormalHalfConeAngle;
7171
settings->mLimitsMax = original->mNormalHalfConeAngle;
7272
settings->mMaxFrictionTorque = original->mMaxFrictionTorque;
73+
settings->mMotorSettings = original->mSwingMotorSettings;
7374
p.mToParent = settings;
7475
break;
7576
}
@@ -83,6 +84,7 @@ RagdollSettings *RagdollLoader::sLoad(const char *inFileName, EMotionType inMoti
8384
settings->mLimitsMin = -1.0f;
8485
settings->mLimitsMax = 1.0f;
8586
settings->mMaxFrictionForce = original->mMaxFrictionTorque;
87+
settings->mMotorSettings = original->mSwingMotorSettings;
8688
p.mToParent = settings;
8789
break;
8890
}

0 commit comments

Comments
 (0)