Skip to content

Commit

Permalink
add the RayCastSettings class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 9, 2024
1 parent 25c0738 commit 69a4f4d
Show file tree
Hide file tree
Showing 2 changed files with 274 additions and 0 deletions.
141 changes: 141 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/RayCastSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
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.enumerate.EBackFaceMode;

/**
* Raycast configuration options.
*
* @author Stephen Gold [email protected]
*/
public class RayCastSettings extends JoltPhysicsObject {
// *************************************************************************
// constructors

/**
* Instantiate default settings.
*/
public RayCastSettings() {
long settingsVa = createDefaultSettings();
setVirtualAddress(settingsVa, () -> free(settingsVa));
}
// *************************************************************************
// new methods exposed

/**
* Return the policy for back-facing triangles in convex shapes. The
* settings are unaffected. (native field: mBackFaceModeConvex)
*
* @return the enum value (not null)
*/
public EBackFaceMode getBackFaceModeConvex() {
long settingsVa = va();
int ordinal = getBackFaceModeConvex(settingsVa);
EBackFaceMode result = EBackFaceMode.values()[ordinal];

return result;
}

/**
* Return the policy for back-facing triangles in non-convex shapes. The
* settings are unaffected. (native field: mBackFaceModeTriangles)
*
* @return the enum value (not null)
*/
public EBackFaceMode getBackFaceModeTriangles() {
long settingsVa = va();
int ordinal = getBackFaceModeTriangles(settingsVa);
EBackFaceMode result = EBackFaceMode.values()[ordinal];

return result;
}

/**
* Test whether convex shapes should be treated as solid. The settings are
* unaffected. (native field: mTreatConvexAsSolid)
*
* @return true if treated as solid, otherwise false
*/
public boolean getTreatConvexAsSolid() {
long settingsVa = va();
boolean result = getTreatConvexAsSolid(settingsVa);

return result;
}

/**
* Alter the policy for back-facing triangles in convex shapes. (native
* field: mBackFaceModeConvex)
*
* @param setting the enum value (not null, default=IgnoreBackFaces)
*/
public void setBackFaceModeConvex(EBackFaceMode setting) {
long settingsVa = va();
int ordinal = setting.ordinal();
setBackFaceModeConvex(settingsVa, ordinal);
}

/**
* Alter the policy for back-facing triangles in non-convex shapes. (native
* field: mBackFaceModeTriangles)
*
* @param setting the enum value (not null, default=IgnoreBackFaces)
*/
public void setBackFaceModeTriangles(EBackFaceMode setting) {
long settingsVa = va();
int ordinal = setting.ordinal();
setBackFaceModeTriangles(settingsVa, ordinal);
}

/**
* Alter whether convex shapes should be treated as solid. (native field:
* mTreatConvexAsSolid)
*
* @param setting true→solid, false→hollow (default=true)
*/
public void setTreatConvexAsSolid(boolean setting) {
long settingsVa = va();
setTreatConvexAsSolid(settingsVa, setting);
}
// *************************************************************************
// native private methods

native private static long createDefaultSettings();

native private static void free(long settingsVa);

native private static int getBackFaceModeConvex(long settingsVa);

native private static int getBackFaceModeTriangles(long settingsVa);

native private static boolean getTreatConvexAsSolid(long settingsVa);

native private static void setBackFaceModeConvex(
long settingsVa, int ordinal);

native private static void setBackFaceModeTriangles(
long settingsVa, int ordinal);

native private static void setTreatConvexAsSolid(
long settingsVa, boolean setting);
}
133 changes: 133 additions & 0 deletions src/main/native/glue/r/RayCastSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
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/RayCast.h>
#include "auto/com_github_stephengold_joltjni_RayCastSettings.h"
#include "glue/glue.h"

using namespace JPH;

/*
* Class: com_github_stephengold_joltjni_RayCastSettings
* Method: createDefaultSettings
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_RayCastSettings_createDefaultSettings
(JNIEnv *, jclass) {
RayCastSettings * const pResult = new RayCastSettings();
TRACE_NEW("RayCastSettings", pResult)
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_RayCastSettings
* Method: free
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_RayCastSettings_free
(JNIEnv *, jclass, jlong settingsVa) {
RayCastSettings * const pSettings
= reinterpret_cast<RayCastSettings *> (settingsVa);
TRACE_DELETE("RayCastSettings", pSettings);
delete pSettings;
}

/*
* Class: com_github_stephengold_joltjni_RayCastSettings
* Method: getBackFaceModeConvex
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_RayCastSettings_getBackFaceModeConvex
(JNIEnv *, jclass, jlong settingsVa) {
const RayCastSettings * const pSettings
= reinterpret_cast<RayCastSettings *> (settingsVa);
EBackFaceMode result = pSettings->mBackFaceModeConvex;
return (jint) result;
}

/*
* Class: com_github_stephengold_joltjni_RayCastSettings
* Method: getBackFaceModeTriangles
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_RayCastSettings_getBackFaceModeTriangles
(JNIEnv *, jclass, jlong settingsVa) {
const RayCastSettings * const pSettings
= reinterpret_cast<RayCastSettings *> (settingsVa);
EBackFaceMode result = pSettings->mBackFaceModeTriangles;
return (jint) result;
}

/*
* Class: com_github_stephengold_joltjni_RayCastSettings
* Method: getTreatConvexAsSolid
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_com_github_stephengold_joltjni_RayCastSettings_getTreatConvexAsSolid
(JNIEnv *, jclass, jlong settingsVa) {
const RayCastSettings * const pSettings
= reinterpret_cast<RayCastSettings *> (settingsVa);
bool result = pSettings->mTreatConvexAsSolid;
return result;
}

/*
* Class: com_github_stephengold_joltjni_RayCastSettings
* Method: setBackFaceModeConvex
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_RayCastSettings_setBackFaceModeConvex
(JNIEnv *, jclass, jlong settingsVa, jint ordinal) {
RayCastSettings * const pSettings
= reinterpret_cast<RayCastSettings *> (settingsVa);
EBackFaceMode mode = (EBackFaceMode) ordinal;
pSettings->mBackFaceModeConvex = mode;
}

/*
* Class: com_github_stephengold_joltjni_RayCastSettings
* Method: setBackFaceModeTriangles
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_RayCastSettings_setBackFaceModeTriangles
(JNIEnv *, jclass, jlong settingsVa, jint ordinal) {
RayCastSettings * const pSettings
= reinterpret_cast<RayCastSettings *> (settingsVa);
EBackFaceMode mode = (EBackFaceMode) ordinal;
pSettings->mBackFaceModeTriangles = mode;
}

/*
* Class: com_github_stephengold_joltjni_RayCastSettings
* Method: setTreatConvexAsSolid
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_RayCastSettings_setTreatConvexAsSolid
(JNIEnv *, jclass, jlong settingsVa, jboolean setting) {
RayCastSettings * const pSettings
= reinterpret_cast<RayCastSettings *> (settingsVa);
pSettings->mTreatConvexAsSolid = setting;
}

0 comments on commit 69a4f4d

Please sign in to comment.