Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ public record GenericConstraintConfiguration(
Vector3dc pos2,
Quaterniondc orientation1,
Quaterniondc orientation2,
Set<ConstraintJointAxis> lockedAxes
Set<ConstraintJointAxis> lockedAxes,
Set<ConstraintJointAxis> coupledAxes
) implements PhysicsConstraintConfiguration<GenericConstraintHandle> {

public GenericConstraintConfiguration(final Vector3dc pos1, final Vector3dc pos2, final Quaterniondc orientation1, final Quaterniondc orientation2, final Set<ConstraintJointAxis> lockedAxes) {
this(pos1, pos2, orientation1, orientation2, lockedAxes, EnumSet.noneOf(ConstraintJointAxis.class));
}

public GenericConstraintConfiguration(final Vector3dc pos1, final Vector3dc pos2, final Quaterniondc orientation1, final Quaterniondc orientation2) {
this(pos1, pos2, orientation1, orientation2, EnumSet.noneOf(ConstraintJointAxis.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ public static native long addFreeConstraint(final int dimensionID,
* @param localOrientationZB the local orientation Z of the second object
* @param localOrientationWB the local orientation W of the second object
* @param lockedAxesMask bit mask of locked axes; bit {@code n} corresponds to {@link dev.ryanhcode.sable.api.physics.constraint.ConstraintJointAxis#ordinal()}
* @param coupledAxesMask bit mask of coupled axes; bit {@code n} corresponds to {@link dev.ryanhcode.sable.api.physics.constraint.ConstraintJointAxis#ordinal()}
*/
@ApiStatus.Internal
public static native long addGenericConstraint(final int dimensionID,
Expand All @@ -441,7 +442,8 @@ public static native long addGenericConstraint(final int dimensionID,
double localOrientationYB,
double localOrientationZB,
double localOrientationWB,
int lockedAxesMask);
int lockedAxesMask,
int coupledAxesMask);

/**
* Sets the local frame on one side of a constraint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public static RapierGenericConstraintHandle create(final ServerLevel serverLevel
lockedAxesMask |= 1 << axis.ordinal();
}

int coupledAxesMask = 0;
for (final ConstraintJointAxis axis : config.coupledAxes()) {
coupledAxesMask |= 1 << axis.ordinal();
}

final long handle = Rapier3D.addGenericConstraint(
sceneID,
sublevelA == null ? -1 : Rapier3D.getID(sublevelA),
Expand All @@ -47,7 +52,8 @@ public static RapierGenericConstraintHandle create(final ServerLevel serverLevel
config.orientation2().y(),
config.orientation2().z(),
config.orientation2().w(),
lockedAxesMask
lockedAxesMask,
coupledAxesMask
);

return new RapierGenericConstraintHandle(sceneID, handle);
Expand Down
12 changes: 8 additions & 4 deletions common/src/main/rust/rapier/src/joints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_add
local_q_z_b: jdouble,
local_q_w_b: jdouble,
locked_axes_mask: jint,
coupled_axes_mask: jint,
) -> SableJointHandle {
let scene = get_scene_mut_ref(scene_id);

Expand All @@ -534,6 +535,7 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_add
};

let locked_axes = JointAxesMask::from_bits_truncate(locked_axes_mask as u8);
let coupled_axes = JointAxesMask::from_bits_truncate(coupled_axes_mask as u8);

let rotation_a = Quat::from_xyzw(
local_q_x_a as Real,
Expand All @@ -548,10 +550,12 @@ pub extern "system" fn Java_dev_ryanhcode_sable_physics_impl_rapier_Rapier3D_add
local_q_w_b as Real,
);

let mut joint = GenericJointBuilder::new(locked_axes).softness(SpringCoefficients::new(
JOINT_SPRING_FREQUENCY,
JOINT_SPRING_DAMPING_RATIO,
));
let mut joint = GenericJointBuilder::new(locked_axes)
.coupled_axes(coupled_axes)
.softness(SpringCoefficients::new(
JOINT_SPRING_FREQUENCY,
JOINT_SPRING_DAMPING_RATIO,
));
joint.0.local_frame1.rotation = rotation_a;
joint.0.local_frame2.rotation = rotation_b;

Expand Down