From cd8ca27b65d481c33a61e45e45d394dbbf95279c Mon Sep 17 00:00:00 2001 From: stephengold Date: Thu, 26 Sep 2024 13:59:08 -0700 Subject: [PATCH] Body: add accessors for the collision group --- config/checkstyle/checkstyle.xml | 2 +- .../com/github/stephengold/joltjni/Body.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 3027e904..bd2770f4 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -33,7 +33,7 @@ - + diff --git a/src/main/java/com/github/stephengold/joltjni/Body.java b/src/main/java/com/github/stephengold/joltjni/Body.java index 5afdca31..ca601a1e 100644 --- a/src/main/java/com/github/stephengold/joltjni/Body.java +++ b/src/main/java/com/github/stephengold/joltjni/Body.java @@ -36,6 +36,13 @@ of this software and associated documentation files (the "Software"), to deal * @author Stephen Gold sgold@sonic.net */ public class Body extends NonCopyable implements ConstBody { + // ************************************************************************* + // fields + + /** + * protect the collision group from garbage collection + */ + private CollisionGroup group; // ************************************************************************* // constructors @@ -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. * @@ -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. * @@ -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);