-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ade8e51
commit 021e243
Showing
2 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
src/main/java/com/github/stephengold/joltjni/CollisionDispatch.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,128 @@ | ||
/* | ||
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.ConstShape; | ||
import com.github.stephengold.joltjni.readonly.Mat44Arg; | ||
import com.github.stephengold.joltjni.readonly.Vec3Arg; | ||
|
||
/** | ||
* Utilities to collect collisions between shapes. | ||
* | ||
* @author Stephen Gold [email protected] | ||
*/ | ||
final public class CollisionDispatch { | ||
// ************************************************************************* | ||
// constructors | ||
|
||
/** | ||
* A private constructor to inhibit instantiation of this class. | ||
*/ | ||
private CollisionDispatch() { | ||
} | ||
// ************************************************************************* | ||
// new methods exposed | ||
|
||
/** | ||
* Collide the specified shapes and pass collisions to the specified | ||
* collector. | ||
* | ||
* @param shape1 the first colliding shape (not null, unaffected) | ||
* @param shape2 the 2nd colliding shape (not null, unaffected) | ||
* @param scale1 the scale to be applied to {@code shape1} (not null, | ||
* unaffected) | ||
* @param scale2 the scale to be applied to {@code shape2} (not null, | ||
* unaffected) | ||
* @param comTransform1 from the center-of-mass of {@code shape1} to system | ||
* coordinates (not null, unaffected) | ||
* @param comTransform2 from the center-of-mass of {@code shape2} to system | ||
* coordinates (not null, unaffected) | ||
* @param creator1 to generate sub-shape IDs {@code shape1} (not null) | ||
* @param creator2 to generate sub-shape IDs {@code shape2} (not null) | ||
* @param collideShapeSettings options for the test (not null, unaffected) | ||
* @param collector to collect the results (not null, modified) | ||
*/ | ||
public static void sCollideShapeVsShape(ConstShape shape1, | ||
ConstShape shape2, Vec3Arg scale1, Vec3Arg scale2, | ||
Mat44Arg comTransform1, Mat44Arg comTransform2, | ||
SubShapeIdCreator creator1, SubShapeIdCreator creator2, | ||
CollideShapeSettings collideShapeSettings, | ||
CollideShapeCollector collector) { | ||
sCollideShapeVsShape(shape1, shape2, scale1, scale2, | ||
comTransform1, comTransform2, creator1, creator2, | ||
collideShapeSettings, collector, new ShapeFilter()); | ||
} | ||
|
||
/** | ||
* Collide the specified shapes and pass collisions to the specified | ||
* collector. | ||
* | ||
* @param shape1 the first colliding shape (not null, unaffected) | ||
* @param shape2 the 2nd colliding shape (not null, unaffected) | ||
* @param scale1 the scale to be applied to {@code shape1} (not null, | ||
* unaffected) | ||
* @param scale2 the scale to be applied to {@code shape2} (not null, | ||
* unaffected) | ||
* @param comTransform1 from the center-of-mass of {@code shape1} to system | ||
* coordinates (not null, unaffected) | ||
* @param comTransform2 from the center-of-mass of {@code shape2} to system | ||
* coordinates (not null, unaffected) | ||
* @param creator1 to generate sub-shape IDs {@code shape1} (not null) | ||
* @param creator2 to generate sub-shape IDs {@code shape2} (not null) | ||
* @param collideShapeSettings options for the test (not null, unaffected) | ||
* @param collector to collect the results (not null, modified) | ||
* @param filter to selectively ignore collisions (not null, unaffected) | ||
*/ | ||
public static void sCollideShapeVsShape(ConstShape shape1, | ||
ConstShape shape2, Vec3Arg scale1, Vec3Arg scale2, | ||
Mat44Arg comTransform1, Mat44Arg comTransform2, | ||
SubShapeIdCreator creator1, SubShapeIdCreator creator2, | ||
CollideShapeSettings collideShapeSettings, | ||
CollideShapeCollector collector, ShapeFilter filter) { | ||
long shape1Va = shape1.targetVa(); | ||
long shape2Va = shape2.targetVa(); | ||
float s1x = scale1.getX(); | ||
float s1y = scale1.getY(); | ||
float s1z = scale1.getZ(); | ||
float s2x = scale2.getX(); | ||
float s2y = scale2.getY(); | ||
float s2z = scale2.getZ(); | ||
long comTransform1Va = comTransform1.targetVa(); | ||
long comTransform2Va = comTransform2.targetVa(); | ||
long creator1Va = creator1.targetVa(); | ||
long creator2Va = creator2.targetVa(); | ||
long settingsVa = collideShapeSettings.targetVa(); | ||
long collectorVa = collector.targetVa(); | ||
long filterVa = filter.targetVa(); | ||
sCollideShapeVsShape(shape1Va, shape2Va, s1x, s1y, s1z, s2x, s2y, s2z, | ||
comTransform1Va, comTransform2Va, creator1Va, creator2Va, | ||
settingsVa, collectorVa, filterVa); | ||
} | ||
// ************************************************************************* | ||
// native private methods | ||
|
||
native private static void sCollideShapeVsShape(long shape1Va, | ||
long shape2Va, float s1x, float s1y, float s1z, float s2x, | ||
float s2y, float s2z, long comTransform1Va, long comTransform2Va, | ||
long creator1Va, long creator2Va, long settingsVa, | ||
long collectorVa, long filterVa); | ||
} |
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,63 @@ | ||
/* | ||
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/CollisionDispatch.h" | ||
#include "auto/com_github_stephengold_joltjni_CollisionDispatch.h" | ||
|
||
using namespace JPH; | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_CollisionDispatch | ||
* Method: sCollideShapeVsShape | ||
* Signature: (JJFFFFFFJJJJJJJ)V | ||
*/ | ||
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_CollisionDispatch_sCollideShapeVsShape | ||
(JNIEnv *, jclass, jlong shape1Va, jlong shape2Va, jfloat s1x, jfloat s1y, | ||
jfloat s1z, jfloat s2x, jfloat s2y, jfloat s2z, jlong comTransform1Va, | ||
jlong comTransform2Va, jlong creator1Va, jlong creator2Va, jlong settingsVa, | ||
jlong collectorVa, jlong filterVa) { | ||
const Shape * const pShape1 = reinterpret_cast<Shape *> (shape1Va); | ||
const Shape * const pShape2 = reinterpret_cast<Shape *> (shape2Va); | ||
const Vec3 scale1(s1x, s1y, s1z); | ||
const Vec3 scale2(s2x, s2y, s2z); | ||
const Mat44 * const pComTransform1 | ||
= reinterpret_cast<Mat44 *> (comTransform1Va); | ||
const Mat44 * const pComTransform2 | ||
= reinterpret_cast<Mat44 *> (comTransform2Va); | ||
const SubShapeIDCreator * const pCreator1 | ||
= reinterpret_cast<SubShapeIDCreator *> (creator1Va); | ||
const SubShapeIDCreator * const pCreator2 | ||
= reinterpret_cast<SubShapeIDCreator *> (creator2Va); | ||
const CollideShapeSettings * const pSettings | ||
= reinterpret_cast<CollideShapeSettings *> (settingsVa); | ||
CollideShapeCollector * const pCollector | ||
= reinterpret_cast<CollideShapeCollector *> (collectorVa); | ||
const ShapeFilter * const pFilter | ||
= reinterpret_cast<ShapeFilter *> (filterVa); | ||
CollisionDispatch::sCollideShapeVsShape(pShape1, pShape2, scale1, scale2, | ||
*pComTransform1, *pComTransform2, *pCreator1, *pCreator2, | ||
*pSettings, *pCollector, *pFilter); | ||
} |