Skip to content

Commit 12627f3

Browse files
committed
Add ability to set coupled_axes in GenericConstraint
1 parent 17d29f5 commit 12627f3

4 files changed

Lines changed: 24 additions & 7 deletions

File tree

common/src/main/java/dev/ryanhcode/sable/api/physics/constraint/GenericConstraintConfiguration.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ public record GenericConstraintConfiguration(
2323
Vector3dc pos2,
2424
Quaterniondc orientation1,
2525
Quaterniondc orientation2,
26-
Set<ConstraintJointAxis> lockedAxes
26+
Set<ConstraintJointAxis> lockedAxes,
27+
Set<ConstraintJointAxis> coupledAxes
2728
) implements PhysicsConstraintConfiguration<GenericConstraintHandle> {
2829

30+
public GenericConstraintConfiguration(final Vector3dc pos1, final Vector3dc pos2, final Quaterniondc orientation1, final Quaterniondc orientation2, final Set<ConstraintJointAxis> lockedAxes) {
31+
this(pos1, pos2, orientation1, orientation2, lockedAxes, EnumSet.noneOf(ConstraintJointAxis.class));
32+
}
33+
2934
public GenericConstraintConfiguration(final Vector3dc pos1, final Vector3dc pos2, final Quaterniondc orientation1, final Quaterniondc orientation2) {
3035
this(pos1, pos2, orientation1, orientation2, EnumSet.noneOf(ConstraintJointAxis.class));
3136
}

sable_rapier/src/main/java/dev/ryanhcode/sable/physics/impl/rapier/Rapier3D.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ public static native long addFreeConstraint(final long sceneHandle,
415415
* @param localOrientationZB the local orientation Z of the second object
416416
* @param localOrientationWB the local orientation W of the second object
417417
* @param lockedAxesMask bit mask of locked axes; bit {@code n} corresponds to {@link dev.ryanhcode.sable.api.physics.constraint.ConstraintJointAxis#ordinal()}
418+
* @param coupledAxesMask bit mask of coupled axes; bit {@code n} corresponds to {@link dev.ryanhcode.sable.api.physics.constraint.ConstraintJointAxis#ordinal()}
418419
*/
419420
@ApiStatus.Internal
420421
public static native long addGenericConstraint(final long sceneHandle,
@@ -434,7 +435,8 @@ public static native long addGenericConstraint(final long sceneHandle,
434435
double localOrientationYB,
435436
double localOrientationZB,
436437
double localOrientationWB,
437-
int lockedAxesMask);
438+
int lockedAxesMask,
439+
int coupledAxesMask);
438440

439441
/**
440442
* Sets the local frame on one side of a constraint.

sable_rapier/src/main/java/dev/ryanhcode/sable/physics/impl/rapier/constraint/generic/RapierGenericConstraintHandle.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public class RapierGenericConstraintHandle extends RapierConstraintHandle implem
3232
lockedAxesMask |= 1 << axis.ordinal();
3333
}
3434

35+
int coupledAxesMask = 0;
36+
for (final ConstraintJointAxis axis : config.coupledAxes()) {
37+
coupledAxesMask |= 1 << axis.ordinal();
38+
}
39+
3540
final long handle = Rapier3D.addGenericConstraint(
3641
sceneHandle,
3742
bodyA == null ? -1 : Rapier3D.getID(bodyA),
@@ -50,7 +55,8 @@ public class RapierGenericConstraintHandle extends RapierConstraintHandle implem
5055
config.orientation2().y(),
5156
config.orientation2().z(),
5257
config.orientation2().w(),
53-
lockedAxesMask
58+
lockedAxesMask,
59+
coupledAxesMask
5460
);
5561

5662
return new RapierGenericConstraintHandle(sceneHandle, handle);

sable_rapier/src/main/rust/rapier/src/joints.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_add
594594
local_q_z_b: jdouble,
595595
local_q_w_b: jdouble,
596596
locked_axes_mask: jint,
597+
coupled_axes_mask: jint,
597598
) -> SableJointHandle {
598599
with_handle(handle, |scene| {
599600
let mut sable_data = scene.sable_data.write().unwrap();
@@ -612,6 +613,7 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_add
612613
};
613614

614615
let locked_axes = JointAxesMask::from_bits_truncate(locked_axes_mask as u8);
616+
let coupled_axes = JointAxesMask::from_bits_truncate(coupled_axes_mask as u8);
615617

616618
let rotation_a = Quat::from_xyzw(
617619
local_q_x_a as Real,
@@ -626,10 +628,12 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_add
626628
local_q_w_b as Real,
627629
);
628630

629-
let mut joint = GenericJointBuilder::new(locked_axes).softness(SpringCoefficients::new(
630-
JOINT_SPRING_FREQUENCY,
631-
JOINT_SPRING_DAMPING_RATIO,
632-
));
631+
let mut joint = GenericJointBuilder::new(locked_axes)
632+
.coupled_axes(coupled_axes)
633+
.softness(SpringCoefficients::new(
634+
JOINT_SPRING_FREQUENCY,
635+
JOINT_SPRING_DAMPING_RATIO,
636+
));
633637
joint.0.local_frame1.rotation = rotation_a;
634638
joint.0.local_frame2.rotation = rotation_b;
635639

0 commit comments

Comments
 (0)