Skip to content

Commit

Permalink
add the AaBox class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jun 29, 2024
1 parent 83d7e2a commit 7416f09
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/AaBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
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.
*/
package com.github.stephengold.joltjni;

/**
* An axis-aligned box.
*
* @author Stephen Gold [email protected]
*/
final public class AaBox extends JoltPhysicsObject {
// *************************************************************************
// constructors

/**
* Instantiate a box with min=(FLT_MAX,FLT_MAX,FLT_MAX) and
* max=(-FLT_MAX,-FLT_MAX,-FLT_MAX).
*/
public AaBox() {
long boxVa = createAaBox();
setVirtualAddress(boxVa, true);
}

/**
* Instantiate a box with the specified minimum and maximum coordinates.
*
* @param minimum the desired minimum coordinates (not null, unaffected)
* @param maximum the desired maximum coordinates (not null, unaffected)
*/
public AaBox(Vec3Arg minimum, Vec3Arg maximum) {
float minX = minimum.getX();
float minY = minimum.getY();
float minZ = minimum.getZ();
float maxX = maximum.getX();
float maxY = maximum.getY();
float maxZ = maximum.getZ();
long boxVa = createAaBox(minX, minY, minZ, maxX, maxY, maxZ);
setVirtualAddress(boxVa, true);
}
// *************************************************************************
// JoltPhysicsObject methods

@Override
public void close() {
assert ownsNativeObject();
long virtualAddress = va();
free(virtualAddress);

unassignNativeObject();
}
// *************************************************************************
// native private methods

native private static long createAaBox();

native private static long createAaBox(float minX, float minY, float minZ,
float maxX, float maxY, float maxZ);

native private static void free(long virtualAddress);
}
65 changes: 65 additions & 0 deletions src/main/native/glue/com_github_stephengold_joltjni_AaBox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
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/Geometry/AABox.h>
#include "auto/com_github_stephengold_joltjni_AaBox.h"

using namespace JPH;

/*
* Class: com_github_stephengold_joltjni_AaBox
* Method: createAaBox
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_AaBox_createAaBox
(JNIEnv *, jclass) {
AABox * const pBox = new AABox();
return reinterpret_cast<jlong> (pBox);
}

/*
* Class: com_github_stephengold_joltjni_AaBox
* Method: createAaBox
* Signature: (FFFFFF)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_AaBox_createAaBox__FFFFFF
(JNIEnv *, jclass, jfloat minX, jfloat minY, jfloat minZ, jfloat maxX, jfloat maxY, jfloat maxZ) {
Vec3 min(minX, minY, minZ);
Vec3 max(maxX, maxY, maxZ);
AABox * const pBox = new AABox(min, max);
return reinterpret_cast<jlong> (pBox);
}

/*
* Class: com_github_stephengold_joltjni_AaBox
* Method: free
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_AaBox_free
(JNIEnv *, jclass, jlong virtualAddress) {
AABox * const pBox = reinterpret_cast<AABox *> (virtualAddress);
delete pBox;
}

0 comments on commit 7416f09

Please sign in to comment.