Skip to content

Commit

Permalink
CharacterVirtual: add 2 public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 25, 2024
1 parent 8f61b4e commit 4d4a298
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/CharacterVirtual.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public class CharacterVirtual
extends CharacterBase
implements ConstCharacterVirtual, RefTarget {
// *************************************************************************
// fields

/**
* protect the char-vs-char collision interface (if any) from garbage
* collection
*/
private CharacterVsCharacterCollision cvcInterface;
// *************************************************************************
// constructors

/**
Expand Down Expand Up @@ -82,6 +90,64 @@ public CharacterVirtual(
// *************************************************************************
// new methods exposed

/**
* Apply a combination of Update, StickToFloor, and WalkStairs.
*
* @param deltaTime the time step to simulate
* @param gravity the gravity acceleration vector (in meters per second
* squared, not null, unaffected)
* @param settings settings to use (not null, unaffected)
* @param bpFilter to test whether the character collides with a broad-phase
* layer (not null, unaffected)
* @param olFilter to test whether the character collides with an object
* layer (not null, unaffected)
* @param bodyFilter to test whether the character collides with a body (not
* null, unaffected)
* @param shapeFilter to test whether the character collides with a shape
* (not null, unaffected)
* @param allocator for temporary allocations (not null)
*/
public void extendedUpdate(float deltaTime, Vec3Arg gravity,
ExtendedUpdateSettings settings, BroadPhaseLayerFilter bpFilter,
ObjectLayerFilter olFilter, BodyFilter bodyFilter,
ShapeFilter shapeFilter, TempAllocator allocator) {
long characterVa = va();
float gravityX = gravity.getX();
float gravityY = gravity.getY();
float gravityZ = gravity.getZ();
long settingsVa = settings.va();
long bpFilterVa = bpFilter.va();
long olFilterVa = olFilter.va();
long bodyFilterVa = bodyFilter.va();
long shapeFilterVa = shapeFilter.va();
long allocatorVa = allocator.va();
extendedUpdate(characterVa, deltaTime, gravityX, gravityY, gravityZ,
settingsVa, bpFilterVa, olFilterVa, bodyFilterVa, shapeFilterVa,
allocatorVa);
}

/**
* Access the char-vs-char collision interface.
*
* @return the pre-existing object, or {@code null} if none
*/
public CharacterVsCharacterCollision getCharacterVsCharacterCollision() {
return cvcInterface;
}

/**
* Replace the char-vs-char collision interface.
*
* @param cvcInterface the desired interface (not null)
*/
public void setCharacterVsCharacterCollision(
CharacterVsCharacterCollision cvcInterface) {
this.cvcInterface = cvcInterface;
long characterVa = va();
long interfaceVa = cvcInterface.va();
setCharacterVsCharacterCollision(characterVa, interfaceVa);
}

/**
* Enable or disable enhanced internal edge removal.
*
Expand Down Expand Up @@ -624,6 +690,11 @@ native private static long createCharacterVirtual(
long settingsVa, double locX, double locY, double locZ, float qx,
float qy, float qz, float qw, long userData, long systemVa);

native private static void extendedUpdate(long characterVa, float deltaTime,
float gravityX, float gravityY, float gravityZ, long settingsVa,
long bpFilterVa, long olFilterVa, long bodyFilterVa,
long shapeFilterVa, long allocatorVa);

native private static long getActiveContacts(long characterVa);

native private static double getCenterOfMassPositionX(long characterVa);
Expand Down Expand Up @@ -691,6 +762,9 @@ native private static boolean hasCollidedWithBody(
native private static boolean hasCollidedWithCharacter(
long characterVa, long otherVa);

native private static void setCharacterVsCharacterCollision(
long characterVa, long interfaceVa);

native private static void setEmbedded(long characterVa);

native private static void setEnhancedInternalEdgeRemoval(
Expand Down
42 changes: 42 additions & 0 deletions src/main/native/glue/c/CharacterVirtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,34 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_CharacterVirtual_cre
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_CharacterVirtual
* Method: extendedUpdate
* Signature: (JFFFFJJJJJJ)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_CharacterVirtual_extendedUpdate
(JNIEnv *, jclass, jlong characterVa, jfloat deltaTime, jfloat gravityX,
jfloat gravityY, jfloat gravityZ, jlong settingsVa, jlong bpFilterVa,
jlong olFilterVa, jlong bodyFilterVa, jlong shapeFilterVa, jlong allocatorVa) {
CharacterVirtual * const pCharacter
= reinterpret_cast<CharacterVirtual *> (characterVa);
const Vec3 gravity(gravityX, gravityY, gravityZ);
const CharacterVirtual::ExtendedUpdateSettings * const pSettings
= reinterpret_cast<CharacterVirtual::ExtendedUpdateSettings *> (settingsVa);
const BroadPhaseLayerFilter * const pBpFilter
= reinterpret_cast<BroadPhaseLayerFilter *> (bpFilterVa);
const ObjectLayerFilter * const pOlFilter
= reinterpret_cast<ObjectLayerFilter *> (olFilterVa);
const BodyFilter * const pBodyFilter
= reinterpret_cast<BodyFilter *> (bodyFilterVa);
const ShapeFilter * const pShapeFilter
= reinterpret_cast<ShapeFilter *> (shapeFilterVa);
TempAllocator * const pAllocator
= reinterpret_cast<TempAllocator *> (allocatorVa);
pCharacter->ExtendedUpdate(deltaTime, gravity, *pSettings, *pBpFilter,
*pOlFilter, *pBodyFilter, *pShapeFilter, *pAllocator);
}

/*
* Class: com_github_stephengold_joltjni_CharacterVirtual
* Method: getActiveContacts
Expand Down Expand Up @@ -517,6 +545,20 @@ JNIEXPORT jboolean JNICALL Java_com_github_stephengold_joltjni_CharacterVirtual_
return result;
}

/*
* Class: com_github_stephengold_joltjni_CharacterVirtual
* Method: setCharacterVsCharacterCollision
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_CharacterVirtual_setCharacterVsCharacterCollision
(JNIEnv *, jclass, jlong characterVa, jlong interfaceVa) {
CharacterVirtual * const pCharacter
= reinterpret_cast<CharacterVirtual *> (characterVa);
CharacterVsCharacterCollision * const pInterface
= reinterpret_cast<CharacterVsCharacterCollision *> (interfaceVa);
pCharacter->SetCharacterVsCharacterCollision(pInterface);
}

/*
* Class: com_github_stephengold_joltjni_CharacterVirtual
* Method: setEmbedded
Expand Down

0 comments on commit 4d4a298

Please sign in to comment.