Skip to content

Commit

Permalink
add the PathConstraintPath class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Nov 6, 2024
1 parent 9693afa commit 4695096
Show file tree
Hide file tree
Showing 2 changed files with 353 additions and 0 deletions.
193 changes: 193 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/PathConstraintPath.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
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;

/**
* The path for a path constraint.
*
* @author Stephen Gold [email protected]
*/
public class PathConstraintPath
extends SerializableObject
implements RefTarget {
// *************************************************************************
// constructors

/**
* Instantiate a path with no native object assigned.
*/
PathConstraintPath() {
}

/**
* Instantiate a path with the specified native object assigned but not
* owned.
*
* @param pathVa the virtual address of the native object to assign (not
* zero)
*/
PathConstraintPath(long pathVa) {
super(pathVa);
}
// *************************************************************************
// new methods exposed

/**
* Return the path amount of the location on the path that's closest to the
* specified location. The path is uanffected.
*
* @param location the input location (in system coordinates, not null,
* unaffected)
* @param fractionHint where to start searching
* @return the path amount (≥0)
*/
public float getClosestPoint(Vec3Arg location, float fractionHint) {
long pathVa = va();
float x = location.getX();
float y = location.getY();
float z = location.getZ();
float result = getClosestPoint(pathVa, x, y, z, fractionHint);

return result;
}

/**
* Return the path amount of the end of the path. The path is unaffected.
*
* @return the path amount (≥0)
*/
public float getPathMaxFraction() {
long pathVa = va();
float result = getPathMaxFraction(pathVa);

return result;
}

/**
* Calculate the location, normal, and binormal of the location on the path
* with the specified path amount. The path is unaffected.
*
* @param amount the path amount (≥0)
* @param storeLocation storage for the location (in system coordinates)
* @param storeTangent storage for the tangent direction (in system
* coordinates)
* @param storeNormal storage for the normal direction (in system
* coordinates)
* @param storeBinormal storage for the binormal direction (in system
* coordinates)
*/
public void getPointOnPath(float amount, Vec3 storeLocation,
Vec3 storeTangent, Vec3 storeNormal, Vec3 storeBinormal) {
long pathVa = va();
float[] storeFloats = new float[12];
getPointOnPath(pathVa, amount, storeFloats);
storeLocation.set(storeFloats[0], storeFloats[1], storeFloats[2]);
storeTangent.set(storeFloats[3], storeFloats[4], storeFloats[5]);
storeNormal.set(storeFloats[6], storeFloats[7], storeFloats[8]);
storeBinormal.set(storeFloats[9], storeFloats[10], storeFloats[11]);
}

/**
* Test whether the path is looping. The path is unaffected.
*
* @return {@code true} if looping, otherwise {@code false}
*/
public boolean isLooping() {
long pathVa = va();
boolean result = isLooping(pathVa);

return result;
}

/**
* Alter whether the path is looping.
*
* @param setting {@code true} for looping, or {@code false} for no looping
* (default=false)
*/
public void setIsLooping(boolean setting) {
long pathVa = va();
setIsLooping(pathVa, setting);
}
// *************************************************************************
// RefTarget methods

/**
* Count the active references to the native {@code PathConstraintPath}. The
* path is unaffected.
*
* @return the count (≥0)
*/
@Override
public int getRefCount() {
long pathVa = va();
int result = getRefCount(pathVa);

return result;
}

/**
* Mark the native {@code PathConstraintPath} as embedded.
*/
@Override
public void setEmbedded() {
long pathVa = va();
setEmbedded(pathVa);
}

/**
* Create a counted reference to the native {@code PathConstraintPath}.
*
* @return a new JVM object with a new native object assigned
*/
@Override
public PathConstraintPathRef toRef() {
long pathVa = va();
long copyVa = toRef(pathVa);
PathConstraintPathRef result = new PathConstraintPathRef(copyVa, true);

return result;
}
// *************************************************************************
// native methods

native private static float getClosestPoint(
long pathVa, float x, float y, float z, float fractionHint);

native private static float getPathMaxFraction(long pathVa);

native private static void getPointOnPath(
long pathVa, float amount, float[] storeFloats);

native private static int getRefCount(long pathVa);

native private static boolean isLooping(long pathVa);

native private static void setEmbedded(long pathVa);

native private static void setIsLooping(long pathVa, boolean setting);

native private static long toRef(long materialVa);
}
160 changes: 160 additions & 0 deletions src/main/native/glue/p/PathConstraintPath.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
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/Constraints/PathConstraint.h"

#include "auto/com_github_stephengold_joltjni_PathConstraintPath.h"
#include "auto/com_github_stephengold_joltjni_PathConstraintPathRef.h"
#include "glue/glue.h"

using namespace JPH;

IMPLEMENT_REF(PathConstraintPath,
Java_com_github_stephengold_joltjni_PathConstraintPathRef_copy,
Java_com_github_stephengold_joltjni_PathConstraintPathRef_createEmpty,
Java_com_github_stephengold_joltjni_PathConstraintPathRef_free,
Java_com_github_stephengold_joltjni_PathConstraintPathRef_getPtr)

/*
* Class: com_github_stephengold_joltjni_PathConstraintPath
* Method: getClosestPoint
* Signature: (JFFFF)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_PathConstraintPath_getClosestPoint
(JNIEnv *, jclass, jlong pathVa, jfloat x, jfloat y, jfloat z, jfloat fractionHint) {
const PathConstraintPath * const pPath
= reinterpret_cast<PathConstraintPath *> (pathVa);
const Vec3 location(x, y, z);
const float result = pPath->GetClosestPoint(location, fractionHint);
return result;
}

/*
* Class: com_github_stephengold_joltjni_PathConstraintPath
* Method: getPathMaxFraction
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_PathConstraintPath_getPathMaxFraction
(JNIEnv *, jclass, jlong pathVa) {
const PathConstraintPath * const pPath
= reinterpret_cast<PathConstraintPath *> (pathVa);
const float result = pPath->GetPathMaxFraction();
return result;
}

/*
* Class: com_github_stephengold_joltjni_PathConstraintPath
* Method: getPointOnPath
* Signature: (JF[F)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_PathConstraintPath_getPointOnPath
(JNIEnv *pEnv, jclass, jlong pathVa, jfloat amount, jfloatArray storeFloats) {
const PathConstraintPath * const pPath
= reinterpret_cast<PathConstraintPath *> (pathVa);
Vec3 location, tangent, normal, binormal;
pPath->GetPointOnPath(amount, location, tangent, normal, binormal);
jboolean isCopy;
jfloat * const pStoreFloats
= pEnv->GetFloatArrayElements(storeFloats, &isCopy);
pStoreFloats[0] = location.GetX();
pStoreFloats[1] = location.GetY();
pStoreFloats[2] = location.GetZ();
pStoreFloats[3] = tangent.GetX();
pStoreFloats[4] = tangent.GetY();
pStoreFloats[5] = tangent.GetZ();
pStoreFloats[6] = normal.GetX();
pStoreFloats[7] = normal.GetY();
pStoreFloats[8] = normal.GetZ();
pStoreFloats[9] = binormal.GetX();
pStoreFloats[10] = binormal.GetY();
pStoreFloats[11] = binormal.GetZ();
pEnv->ReleaseFloatArrayElements(storeFloats, pStoreFloats, 0);
}

/*
* Class: com_github_stephengold_joltjni_PathConstraintPath
* Method: getRefCount
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_PathConstraintPath_getRefCount
(JNIEnv *, jclass, jlong pathVa) {
const PathConstraintPath * const pPath
= reinterpret_cast<PathConstraintPath *> (pathVa);
const uint32 result = pPath->GetRefCount();
return result;
}

/*
* Class: com_github_stephengold_joltjni_PathConstraintPath
* Method: isLooping
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_com_github_stephengold_joltjni_PathConstraintPath_isLooping
(JNIEnv *, jclass, jlong pathVa) {
const PathConstraintPath * const pPath
= reinterpret_cast<PathConstraintPath *> (pathVa);
const bool result = pPath->IsLooping();
return result;
}

/*
* Class: com_github_stephengold_joltjni_PathConstraintPath
* Method: setEmbedded
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_PathConstraintPath_setEmbedded
(JNIEnv *, jclass, jlong pathVa) {
PathConstraintPath * const pPath
= reinterpret_cast<PathConstraintPath *> (pathVa);
pPath->SetEmbedded();
}

/*
* Class: com_github_stephengold_joltjni_PathConstraintPath
* Method: setIsLooping
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_PathConstraintPath_setIsLooping
(JNIEnv *, jclass, jlong pathVa, jboolean setting) {
PathConstraintPath * const pPath
= reinterpret_cast<PathConstraintPath *> (pathVa);
pPath->SetIsLooping(setting);
}

/*
* Class: com_github_stephengold_joltjni_PathConstraintPath
* Method: toRef
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_PathConstraintPath_toRef
(JNIEnv *, jclass, jlong pathVa) {
PathConstraintPath * const pPath
= reinterpret_cast<PathConstraintPath *> (pathVa);
Ref<PathConstraintPath> * const pResult
= new Ref<PathConstraintPath>(pPath);
TRACE_NEW("Ref<PathConstraintPath>", pResult)
return reinterpret_cast<jlong> (pResult);
}

0 comments on commit 4695096

Please sign in to comment.