-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the VehicleCollisionTester{/Ray/RayRef} classes
- Loading branch information
1 parent
87283df
commit 50e08d0
Showing
4 changed files
with
358 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/com/github/stephengold/joltjni/VehicleCollisionTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
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; | ||
|
||
/** | ||
* Detect collisions between vehicle wheels and the environment. | ||
* | ||
* @author Stephen Gold [email protected] | ||
*/ | ||
abstract public class VehicleCollisionTester extends NonCopyable { | ||
// ************************************************************************* | ||
// constructors | ||
|
||
/** | ||
* Instantiate a tester with no native object assigned. | ||
*/ | ||
VehicleCollisionTester() { | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
src/main/java/com/github/stephengold/joltjni/VehicleCollisionTesterRay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
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; | ||
|
||
import com.github.stephengold.joltjni.readonly.Vec3Arg; | ||
import com.github.stephengold.joltjni.template.RefTarget; | ||
|
||
/** | ||
* A {@code VehicleCollisionTester} that uses ray casts. | ||
* | ||
* @author Stephen Gold [email protected] | ||
*/ | ||
public class VehicleCollisionTesterRay | ||
extends VehicleCollisionTester | ||
implements RefTarget { | ||
// ************************************************************************* | ||
// constructors | ||
|
||
/** | ||
* Instantiate a tester for the specified layer. | ||
* | ||
* @param objectLayer the index of the desired object layer for collisions | ||
*/ | ||
public VehicleCollisionTesterRay(int objectLayer) { | ||
this(objectLayer, Vec3.sAxisY()); | ||
} | ||
|
||
/** | ||
* Instantiate a tester with the specified properties. | ||
* | ||
* @param objectLayer the index of the desired object layer for collisions | ||
* @param up the "up" direction (in system coordinates, not null, | ||
* unaffected, default=(0,1,0)) | ||
*/ | ||
public VehicleCollisionTesterRay(int objectLayer, Vec3Arg up) { | ||
this(objectLayer, up, Jolt.degreesToRadians(80.0f)); | ||
} | ||
|
||
/** | ||
* Instantiate a tester with the specified properties. | ||
* | ||
* @param objectLayer the index of the desired object layer for collisions | ||
* @param up the "up" direction (in system coordinates, not null, | ||
* unaffected, default=(0,1,0)) | ||
* @param maxSlopeAngle the maximum angle to consider for colliding wheels | ||
* (in radians, default=4*Pi/9) | ||
*/ | ||
public VehicleCollisionTesterRay( | ||
int objectLayer, Vec3Arg up, float maxSlopeAngle) { | ||
float ux = up.getX(); | ||
float uy = up.getY(); | ||
float uz = up.getZ(); | ||
long testerVa = createTester(objectLayer, ux, uy, uz, maxSlopeAngle); | ||
setVirtualAddress(testerVa, true); | ||
} | ||
|
||
/** | ||
* Instantiate a tester with the specified native object assigned but not | ||
* owned. | ||
* | ||
* @param testerVa the virtual address of the native object to assign (not | ||
* zero) | ||
*/ | ||
VehicleCollisionTesterRay(long testerVa) { | ||
setVirtualAddress(testerVa, null); | ||
} | ||
// ************************************************************************* | ||
// RefTarget methods | ||
|
||
/** | ||
* Count the active references to the native {@code VehicleCollisionTester}. | ||
* The tester is unaffected. | ||
* | ||
* @return the count (≥0) | ||
*/ | ||
@Override | ||
public int getRefCount() { | ||
long testerVa = va(); | ||
int result = getRefCount(testerVa); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Mark the native {@code VehicleCollisionTesterRay} as embedded. | ||
*/ | ||
@Override | ||
public void setEmbedded() { | ||
long testerVa = va(); | ||
setEmbedded(testerVa); | ||
} | ||
|
||
/** | ||
* Create a counted reference to the native | ||
* {@code VehicleCollisionTesterRay}. | ||
* | ||
* @return a new JVM object with a new native object assigned | ||
*/ | ||
@Override | ||
public VehicleCollisionTesterRayRef toRef() { | ||
long testerVa = va(); | ||
long refVa = toRef(testerVa); | ||
VehicleCollisionTesterRayRef result | ||
= new VehicleCollisionTesterRayRef(refVa, true); | ||
|
||
return result; | ||
} | ||
// ************************************************************************* | ||
// native private methods | ||
|
||
native private static long createTester( | ||
int objectLayer, float ux, float uy, float uz, float maxSlopeAngle); | ||
|
||
native private static int getRefCount(long settingsVa); | ||
|
||
native private static void setEmbedded(long settingsVa); | ||
|
||
native private static long toRef(long settingsVa); | ||
} |
89 changes: 89 additions & 0 deletions
89
src/main/java/com/github/stephengold/joltjni/VehicleCollisionTesterRayRef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
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; | ||
|
||
import com.github.stephengold.joltjni.template.Ref; | ||
|
||
/** | ||
* A counted reference to a {@code ShapeSettings}. (native type: | ||
* {@code Ref<ShapeSettings>}) | ||
* | ||
* @author Stephen Gold [email protected] | ||
*/ | ||
final public class VehicleCollisionTesterRayRef extends Ref { | ||
// ************************************************************************* | ||
// constructors | ||
|
||
/** | ||
* Instantiate a reference with the specified native object assigned. | ||
* | ||
* @param refVa the virtual address of the native object to assign (not | ||
* zero) | ||
* @param owner true → make the current object the owner, false → | ||
* the current object isn't the owner | ||
*/ | ||
VehicleCollisionTesterRayRef(long refVa, boolean owner) { | ||
Runnable freeingAction = owner ? () -> free(refVa) : null; | ||
setVirtualAddress(refVa, freeingAction); | ||
} | ||
// ************************************************************************* | ||
// Ref methods | ||
|
||
/** | ||
* Temporarily access the referenced {@code VehicleCollisionTesterRay}. | ||
* | ||
* @return a new JVM object that refers to the pre-existing native object | ||
*/ | ||
@Override | ||
public VehicleCollisionTesterRay getPtr() { | ||
long refVa = va(); | ||
long controllerVa = getPtr(refVa); | ||
VehicleCollisionTesterRay result | ||
= new VehicleCollisionTesterRay(controllerVa); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Create a counted reference to the native | ||
* {@code VehicleCollisionTesterRay}. | ||
* | ||
* @return a new JVM object with a new native object assigned | ||
*/ | ||
@Override | ||
public VehicleCollisionTesterRayRef toRef() { | ||
long refVa = va(); | ||
long copyVa = copy(refVa); | ||
VehicleCollisionTesterRayRef result | ||
= new VehicleCollisionTesterRayRef(copyVa, true); | ||
|
||
return result; | ||
} | ||
// ************************************************************************* | ||
// native private methods | ||
|
||
native private static long copy(long refVa); | ||
|
||
native private static void free(long refVa); | ||
|
||
native private static long getPtr(long refVa); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
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/Vehicle/VehicleCollisionTester.h" | ||
|
||
#include "auto/com_github_stephengold_joltjni_VehicleCollisionTesterRay.h" | ||
#include "auto/com_github_stephengold_joltjni_VehicleCollisionTesterRayRef.h" | ||
#include "glue/glue.h" | ||
|
||
using namespace JPH; | ||
|
||
IMPLEMENT_REF(VehicleCollisionTesterRay, | ||
Java_com_github_stephengold_joltjni_VehicleCollisionTesterRayRef_copy, | ||
Java_com_github_stephengold_joltjni_VehicleCollisionTesterRayRef_createEmpty, | ||
Java_com_github_stephengold_joltjni_VehicleCollisionTesterRayRef_free, | ||
Java_com_github_stephengold_joltjni_VehicleCollisionTesterRayRef_getPtr) | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_VehicleCollisionTesterRay | ||
* Method: createTester | ||
* Signature: (IFFFF)J | ||
*/ | ||
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_VehicleCollisionTesterRay_createTester | ||
(JNIEnv *, jclass, jint layer, jfloat ux, jfloat uy, jfloat uz, jfloat maxSlope) { | ||
const ObjectLayer objLayer = (ObjectLayer) layer; | ||
const Vec3 up(ux, uy, uz); | ||
VehicleCollisionTesterRay * const pTester | ||
= new VehicleCollisionTesterRay(objLayer, up, maxSlope); | ||
return reinterpret_cast<jlong> (pTester); | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_VehicleCollisionTesterRay | ||
* Method: getRefCount | ||
* Signature: (J)I | ||
*/ | ||
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_VehicleCollisionTesterRay_getRefCount | ||
(JNIEnv *, jclass, jlong testerVa) { | ||
const VehicleCollisionTesterRay * const pTester | ||
= reinterpret_cast<VehicleCollisionTesterRay *> (testerVa); | ||
const uint32 result = pTester->GetRefCount(); | ||
return result; | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_VehicleCollisionTesterRay | ||
* Method: setEmbedded | ||
* Signature: (J)V | ||
*/ | ||
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VehicleCollisionTesterRay_setEmbedded | ||
(JNIEnv *, jclass, jlong testerVa) { | ||
VehicleCollisionTesterRay * const pTester | ||
= reinterpret_cast<VehicleCollisionTesterRay *> (testerVa); | ||
pTester->SetEmbedded(); | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_VehicleCollisionTesterRay | ||
* Method: toRef | ||
* Signature: (J)J | ||
*/ | ||
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_VehicleCollisionTesterRay_toRef | ||
(JNIEnv *, jclass, jlong testerVa) { | ||
VehicleCollisionTesterRay * const pTester | ||
= reinterpret_cast<VehicleCollisionTesterRay *> (testerVa); | ||
Ref<VehicleCollisionTesterRay> * const pResult | ||
= new Ref<VehicleCollisionTesterRay>(pTester); | ||
TRACE_NEW("Ref<VehicleCollisionTesterRay>", pResult) | ||
return reinterpret_cast<jlong> (pResult); | ||
} |