Skip to content

Commit 7416f09

Browse files
committed
add the AaBox class
1 parent 83d7e2a commit 7416f09

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
* An axis-aligned box.
26+
*
27+
* @author Stephen Gold [email protected]
28+
*/
29+
final public class AaBox extends JoltPhysicsObject {
30+
// *************************************************************************
31+
// constructors
32+
33+
/**
34+
* Instantiate a box with min=(FLT_MAX,FLT_MAX,FLT_MAX) and
35+
* max=(-FLT_MAX,-FLT_MAX,-FLT_MAX).
36+
*/
37+
public AaBox() {
38+
long boxVa = createAaBox();
39+
setVirtualAddress(boxVa, true);
40+
}
41+
42+
/**
43+
* Instantiate a box with the specified minimum and maximum coordinates.
44+
*
45+
* @param minimum the desired minimum coordinates (not null, unaffected)
46+
* @param maximum the desired maximum coordinates (not null, unaffected)
47+
*/
48+
public AaBox(Vec3Arg minimum, Vec3Arg maximum) {
49+
float minX = minimum.getX();
50+
float minY = minimum.getY();
51+
float minZ = minimum.getZ();
52+
float maxX = maximum.getX();
53+
float maxY = maximum.getY();
54+
float maxZ = maximum.getZ();
55+
long boxVa = createAaBox(minX, minY, minZ, maxX, maxY, maxZ);
56+
setVirtualAddress(boxVa, true);
57+
}
58+
// *************************************************************************
59+
// JoltPhysicsObject methods
60+
61+
@Override
62+
public void close() {
63+
assert ownsNativeObject();
64+
long virtualAddress = va();
65+
free(virtualAddress);
66+
67+
unassignNativeObject();
68+
}
69+
// *************************************************************************
70+
// native private methods
71+
72+
native private static long createAaBox();
73+
74+
native private static long createAaBox(float minX, float minY, float minZ,
75+
float maxX, float maxY, float maxZ);
76+
77+
native private static void free(long virtualAddress);
78+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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/Geometry/AABox.h>
28+
#include "auto/com_github_stephengold_joltjni_AaBox.h"
29+
30+
using namespace JPH;
31+
32+
/*
33+
* Class: com_github_stephengold_joltjni_AaBox
34+
* Method: createAaBox
35+
* Signature: ()J
36+
*/
37+
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_AaBox_createAaBox
38+
(JNIEnv *, jclass) {
39+
AABox * const pBox = new AABox();
40+
return reinterpret_cast<jlong> (pBox);
41+
}
42+
43+
/*
44+
* Class: com_github_stephengold_joltjni_AaBox
45+
* Method: createAaBox
46+
* Signature: (FFFFFF)J
47+
*/
48+
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_AaBox_createAaBox__FFFFFF
49+
(JNIEnv *, jclass, jfloat minX, jfloat minY, jfloat minZ, jfloat maxX, jfloat maxY, jfloat maxZ) {
50+
Vec3 min(minX, minY, minZ);
51+
Vec3 max(maxX, maxY, maxZ);
52+
AABox * const pBox = new AABox(min, max);
53+
return reinterpret_cast<jlong> (pBox);
54+
}
55+
56+
/*
57+
* Class: com_github_stephengold_joltjni_AaBox
58+
* Method: free
59+
* Signature: (J)V
60+
*/
61+
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_AaBox_free
62+
(JNIEnv *, jclass, jlong virtualAddress) {
63+
AABox * const pBox = reinterpret_cast<AABox *> (virtualAddress);
64+
delete pBox;
65+
}

0 commit comments

Comments
 (0)