Skip to content

Commit 8083840

Browse files
committed
add the CapsuleShape class
1 parent 3a03ad5 commit 8083840

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright (c) 2024 Stephen Gold
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
21+
*/
22+
package com.github.stephengold.joltjni;
23+
24+
/**
25+
* A {@code Shape} to represent a right circular cylinder capped by 2
26+
* hemispheres.
27+
*
28+
* @author Stephen Gold sgold@sonic.net
29+
*/
30+
public class CapsuleShape extends ConvexShape {
31+
// *************************************************************************
32+
// constructors
33+
34+
CapsuleShape(long virtualAddress) {
35+
super(virtualAddress);
36+
}
37+
38+
/**
39+
* Instantiate a shape with the specified radius.
40+
*
41+
* @param halfHeight half the desired height of the cylindrical portion
42+
* @param radius the desired radius
43+
*/
44+
public CapsuleShape(float halfHeight, float radius) {
45+
long shapeVa = createCapsuleShape(halfHeight, radius);
46+
setVirtualAddress(shapeVa, true);
47+
}
48+
// *************************************************************************
49+
// native private methods
50+
51+
native private static long createCapsuleShape(
52+
float halfHeight, float radius);
53+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright (c) 2024 Stephen Gold
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.
21+
*/
22+
23+
/*
24+
* Author: Stephen Gold
25+
*/
26+
#include <Jolt/Jolt.h>
27+
#include <Jolt/Physics/Collision/Shape/CapsuleShape.h>
28+
#include "auto/com_github_stephengold_joltjni_CapsuleShape.h"
29+
30+
using namespace JPH;
31+
32+
/*
33+
* Class: com_github_stephengold_joltjni_CapsuleShape
34+
* Method: createCapsuleShape
35+
* Signature: (FF)J
36+
*/
37+
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_CapsuleShape_createCapsuleShape
38+
(JNIEnv *, jclass, jfloat halfHeight, jfloat radius) {
39+
CapsuleShape * const pResult = new CapsuleShape(halfHeight, radius);
40+
return reinterpret_cast<jlong> (pResult);
41+
}

0 commit comments

Comments
 (0)