Skip to content

Commit

Permalink
Fixed comments regarding joint rotation direction
Browse files Browse the repository at this point in the history
  • Loading branch information
mihe committed Dec 22, 2023
1 parent 41ca5aa commit bc07d40
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/joints/jolt_cone_twist_joint_impl_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ void JoltConeTwistJointImpl3D::_update_twist_motor_state() {

void JoltConeTwistJointImpl3D::_update_motor_velocity() {
if (auto* constraint = static_cast<JPH::SwingTwistConstraint*>(jolt_ref.GetPtr())) {
// HACK(mihe): For reasons I don't entirely understand we're forced to flip the directions
// of these for it to make sense with the direction of the joint's actual axes.
// NOTE(mihe): We flip the direction since Jolt is CCW but Godot is CW.
constraint->SetTargetAngularVelocityCS(
{(float)-twist_motor_target_speed,
(float)-swing_motor_target_speed_y,
Expand Down
7 changes: 3 additions & 4 deletions src/joints/jolt_generic_6dof_joint_impl_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ void JoltGeneric6DOFJointImpl3D::_update_motor_velocity(int32_t p_axis) {
(float)motor_speed[AXIS_LINEAR_Z]}
);
} else {
// HACK(mihe): We're forced to flip the direction of these to match Godot Physics.
// NOTE(mihe): We flip the direction since Jolt is CCW but Godot is CW.
constraint->SetTargetAngularVelocityCS(
{(float)-motor_speed[AXIS_ANGULAR_X],
(float)-motor_speed[AXIS_ANGULAR_Y],
Expand All @@ -580,9 +580,8 @@ void JoltGeneric6DOFJointImpl3D::_update_motor_limit(int32_t p_axis) {

JPH::MotorSettings& motor_settings = constraint->GetMotorSettings((JoltAxis)p_axis);

// HACK(mihe): We only apply the motor limit if we're actually using a velocity motor, since
// it would otherwise affect a position motor as well, which doesn't seem to be how this is
// applied in the Bullet implementation in Godot 3.
// NOTE(mihe): We only apply the motor limit if we're actually using a velocity motor, since it
// would otherwise affect a position motor as well.
const auto limit = motor_enabled[p_axis] ? (float)motor_limit[p_axis] : FLT_MAX;

if (p_axis >= AXIS_LINEAR_X && p_axis <= AXIS_LINEAR_Z) {
Expand Down
2 changes: 1 addition & 1 deletion src/joints/jolt_hinge_joint_impl_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ void JoltHingeJointImpl3D::_update_motor_velocity() {
QUIET_FAIL_COND(_is_fixed());

if (auto* constraint = static_cast<JPH::HingeConstraint*>(jolt_ref.GetPtr())) {
// HACK(mihe): We're forced to flip the direction of these to match Godot Physics.
// NOTE(mihe): We flip the direction since Jolt is CCW but Godot is CW.
constraint->SetTargetAngularVelocity((float)-motor_target_speed);
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/joints/jolt_joint_impl_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ void JoltJointImpl3D::_shift_reference_frames(
const Basis& basis_a = local_ref_a.basis;
const Basis& basis_b = local_ref_b.basis;

// HACK(mihe): Ideally we would add the linear shift here, not subtract it, but this is how
// Godot Physics seems to behave, so we emulate that. This does have the annoying side-effect of
// effectively making the upper limit instead be the lower limit and vice versa.

const Basis shifted_basis_a = basis_a * Basis::from_euler(p_angular_shift);
const Vector3 shifted_origin_a = origin_a - basis_a.xform(p_linear_shift);

Expand Down

0 comments on commit bc07d40

Please sign in to comment.