diff --git a/src/main/java/com/github/stephengold/joltjni/TaperedCapsuleShape.java b/src/main/java/com/github/stephengold/joltjni/TaperedCapsuleShape.java index c987f599..61f23879 100644 --- a/src/main/java/com/github/stephengold/joltjni/TaperedCapsuleShape.java +++ b/src/main/java/com/github/stephengold/joltjni/TaperedCapsuleShape.java @@ -41,4 +41,51 @@ public class TaperedCapsuleShape extends ConvexShape { TaperedCapsuleShape(long shapeVa) { super(shapeVa); } + // ************************************************************************* + // new methods exposed + + /** + * Return the bottom radius. The shape is unaffected. + * + * @return the bottom radius of the tapered cylinder (≥0) + */ + public float getBottomRadius() { + long shapeVa = va(); + float result = getBottomRadius(shapeVa); + + return result; + } + + /** + * Return the half height. The shape is unaffected. + * + * @return half the height + */ + public float getHalfHeight() { + long shapeVa = va(); + float result = getHalfHeight(shapeVa); + + return result; + } + + /** + * Return the top radius. The shape is unaffected. (native field: + * mTopRadius) + * + * @return the top radius (≥0) + */ + public float getTopRadius() { + long shapeVa = va(); + float result = getTopRadius(shapeVa); + + return result; + } + // ************************************************************************* + // native private methods + + native private static float getBottomRadius(long shapeVa); + + native private static float getHalfHeight(long shapeVa); + + native private static float getTopRadius(long shapeVa); } diff --git a/src/main/native/glue/t/TaperedCapsuleShape.cpp b/src/main/native/glue/t/TaperedCapsuleShape.cpp new file mode 100644 index 00000000..5d4f208c --- /dev/null +++ b/src/main/native/glue/t/TaperedCapsuleShape.cpp @@ -0,0 +1,69 @@ +/* +Copyright (c) 2024 Stephen Gold + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ + +/* + * Author: Stephen Gold + */ +#include +#include +#include "auto/com_github_stephengold_joltjni_TaperedCapsuleShape.h" + +using namespace JPH; + +/* + * Class: com_github_stephengold_joltjni_TaperedCapsuleShape + * Method: getBottomRadius + * Signature: (J)F + */ +JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_TaperedCapsuleShape_getBottomRadius + (JNIEnv *, jclass, jlong shapeVa) { + const TaperedCapsuleShape * const pShape + = reinterpret_cast (shapeVa); + const float result = pShape->GetBottomRadius(); + return result; +} + +/* + * Class: com_github_stephengold_joltjni_TaperedCapsuleShape + * Method: getHalfHeight + * Signature: (J)F + */ +JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_TaperedCapsuleShape_getHalfHeight + (JNIEnv *, jclass, jlong shapeVa) { + const TaperedCapsuleShape * const pShape + = reinterpret_cast (shapeVa); + const float result = pShape->GetHalfHeight(); + return result; +} + +/* + * Class: com_github_stephengold_joltjni_TaperedCapsuleShape + * Method: getTopRadius + * Signature: (J)F + */ +JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_TaperedCapsuleShape_getTopRadius + (JNIEnv *, jclass, jlong shapeVa) { + const TaperedCapsuleShape * const pShape + = reinterpret_cast (shapeVa); + const float result = pShape->GetTopRadius(); + return result; +} \ No newline at end of file diff --git a/src/test/java/testjoltjni/junit/Test007.java b/src/test/java/testjoltjni/junit/Test007.java index 9ad424b8..f9e93458 100644 --- a/src/test/java/testjoltjni/junit/Test007.java +++ b/src/test/java/testjoltjni/junit/Test007.java @@ -383,8 +383,11 @@ private static void doTaperedCapsuleShape() { ShapeRefC ref = result.get(); TaperedCapsuleShape shape = (TaperedCapsuleShape) ref.getPtr(); + Assert.assertEquals(1f, shape.getBottomRadius(), 0f); + Assert.assertEquals(1f, shape.getHalfHeight(), 0f); Assert.assertEquals(1f, shape.getInnerRadius(), 0f); Assert.assertEquals(EShapeSubType.TaperedCapsule, shape.getSubType()); + Assert.assertEquals(2f, shape.getTopRadius(), 0f); Assert.assertEquals(EShapeType.Convex, shape.getType()); Assert.assertEquals(0L, shape.getUserData());