Skip to content

Commit

Permalink
Body: add accessors for the collision group
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 26, 2024
1 parent 8a9391a commit cd8ca27
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<!-- Checks for size violations -->
<!-- See https://checkstyle.org/checks/sizes -->
<module name="FileLength">
<property name="max" value="900"/>
<property name="max" value="999"/>
</module>
<module name="LineLength">
<property name="fileExtensions" value="java"/>
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/Body.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ of this software and associated documentation files (the "Software"), to deal
* @author Stephen Gold [email protected]
*/
public class Body extends NonCopyable implements ConstBody {
// *************************************************************************
// fields

/**
* protect the collision group from garbage collection
*/
private CollisionGroup group;
// *************************************************************************
// constructors

Expand Down Expand Up @@ -146,6 +153,15 @@ public void addTorque(Vec3Arg torque) {
addTorque(bodyVa, x, y, z);
}

/**
* Access the body's collision group.
*
* @return the pre-existing group, or {@code null} if none
*/
public CollisionGroup getCollisionGroup() {
return group;
}

/**
* Access the body's motion properties.
*
Expand Down Expand Up @@ -235,6 +251,18 @@ public void setAngularVelocityClamped(Vec3Arg omega) {
setAngularVelocityClamped(bodyVa, wx, wy, wz);
}

/**
* Assign the body to the specified collision group.
*
* @param group the group to assign (not null, alias created)
*/
public void setCollisionGroup(CollisionGroup group) {
this.group = group;
long bodyVa = va();
long groupVa = group.va();
setCollisionGroup(bodyVa, groupVa);
}

/**
* Alter the body's friction ratio.
*
Expand Down Expand Up @@ -861,6 +889,8 @@ native private static void setAngularVelocity(
native private static void setAngularVelocityClamped(
long bodyVa, float wx, float wy, float wz);

native private static void setCollisionGroup(long bodyVa, long groupVa);

native private static void setFriction(long bodyVa, float friction);

native private static void setIsSensor(long bodyVa, boolean setting);
Expand Down

0 comments on commit cd8ca27

Please sign in to comment.