Skip to content

Commit

Permalink
TaperedCapsuleShape: add 3 public getters
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 7, 2024
1 parent db624ac commit 2d68d95
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
69 changes: 69 additions & 0 deletions src/main/native/glue/t/TaperedCapsuleShape.cpp
Original file line number Diff line number Diff line change
@@ -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 <Jolt/Jolt.h>
#include <Jolt/Physics/Collision/Shape/TaperedCapsuleShape.h>
#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<TaperedCapsuleShape *> (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<TaperedCapsuleShape *> (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<TaperedCapsuleShape *> (shapeVa);
const float result = pShape->GetTopRadius();
return result;
}
3 changes: 3 additions & 0 deletions src/test/java/testjoltjni/junit/Test007.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit 2d68d95

Please sign in to comment.