java.lang.Object
com.github.stephengold.joltjni.Jolt
Utility methods providing JNI access to Jolt Physics.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatdefault rounding of corners in convex shapes (in meters)static final intempty sub-shape IDstatic final intinvalid body IDstatic final intstandard 2nd argument to theJobSystemThreadPoolconstructorstatic final intstandard first argument to theJobSystemThreadPoolconstructorstatic final floatsingle-precision value of Pistatic final Objectgeneric null pointer (to expedite porting of C++ code)static final intindex of the X component, for swizzlingstatic final intindex of the Y component, for swizzlingstatic final intindex of the Z component, for swizzling -
Method Summary
Modifier and TypeMethodDescriptionstatic floataCos(float ratio) Return the inverse cosine of the specified single-precision ratio.static floataTan(float ratio) Return the inverse tangent of the specified single-precision ratio.static floataTan2(float opposite, float adjacent) Return the angle of the specified single-precision right triangle.static StringReturn the Jolt-JNI build-type string that's hard-coded in the native library.static floatcos(float angle) Return the cosine of the specified single-precision angle.static intReturn the cumulative number ofdeleteoperations in glue code, in Debug native libraries.static intReturn the cumulative number ofnewoperations in glue code, in Debug native libraries, excluding ref targets.static floatdegreesToRadians(float degrees) Convert the specified angle from degrees to radians.static voidDestroy the factory for deserialization of saved data.static voidAppend a message to the determinism log.static voidestimateCollisionResponse(ConstBody body1, ConstBody body2, ConstContactManifold manifold, CollisionEstimationResult storeResult, float combinedFriction, float combinedRestitution) Estimate the contact impulses and body velocity changes resulting from a collision.static voidestimateCollisionResponse(ConstBody body1, ConstBody body2, ConstContactManifold manifold, CollisionEstimationResult storeResult, float combinedFriction, float combinedRestitution, float minVelocity) Estimate the contact impulses and body velocity changes resulting from a collision.static voidestimateCollisionResponse(ConstBody body1, ConstBody body2, ConstContactManifold manifold, CollisionEstimationResult storeResult, float combinedFriction, float combinedRestitution, float minVelocity, int numIterations) Estimate the contact impulses and body velocity changes resulting from a collision.static StringReturn a string containing important configuration settings.static longhashBytes(long dataVa, int inSize) Return a hash code for the specified data bytes.static longCombine the specified quaternion with the specified hash code.static longCombine the specified vector with the specified hash code.static longhashCombine(long oldHash, int iValue) Combine the specified 32-bit integer with the specified hash code.static longhashCombine(long oldHash, long lValue) Combine the specified 64-bit integer with the specified hash code.static longhashCombine(long oldHash, RVec3Arg vector) Combine the specified location vector with the specified hash code.static longhashCombine(long oldHash, Vec3Arg vector) Combine the specified vector with the specified hash code.static booleanTest whether the native library implements debug rendering.static booleanTest whether the native library implements extra logging to help debug determinism issues.static voidInstall an alternative trace callback that usescerr.static voidInstall the default assert callback.static voidInstall the default trace callback, which usescout.static voidinstallJavaTraceCallback(PrintStream stream) Install a trace callback that uses aPrintStream.static booleanTest whether the native library uses double-precision location vectors.listClasses(String packageName) List all classes in the specified Jolt-JNI package.static ByteBuffernewDirectByteBuffer(int numBytes) Create a directByteBufferwith the specified capacity.static DoubleBuffernewDirectDoubleBuffer(int numDoubles) Create a directDoubleBufferwith native byte order and the specified capacity.static FloatBuffernewDirectFloatBuffer(int numFloats) Create a directFloatBufferwith native byte order and the specified capacity.static IntBuffernewDirectIntBuffer(int numInts) Create a directIntBufferwith native byte order and the specified capacity.static ShortBuffernewDirectShortBuffer(int numShorts) Create a directShortBufferwith native byte order and the specified capacity.static booleanCreate a factory for deserialization of saved data.static floatperlinNoise3(float x, float y, float z, int xWrap, int yWrap, int zWrap) Generate 3-D Perlin noise.static voidprofileDump(String message) Dump profiler data.static voidTerminate the profiler.static voidIncrement the profiler's frame counter.static voidprofileStart(String name) Start an instrumented code section.static floatradiansToDegrees(float radians) Convert the specified angle from radians to degrees.static floatrayAaBox(Vec3Arg rayOrigin, RayInvDirection invDirection, Vec3Arg minimum, Vec3Arg maximum) Intersect the specified axis-aligned box with the specified ray.static booleanrayAaBoxHits(Vec3Arg startLocation, Vec3Arg offset, Vec3Arg minimum, Vec3Arg maximum) Intersect the specified axis-aligned box with the specified ray.static floatrayCapsule(Vec3Arg rayOrigin, Vec3Arg rayDirection, float capsuleHalfHeight, float capsuleRadius) Intersect the specified capsule with the specified ray.static floatrayCylinder(Vec3Arg rayOrigin, Vec3Arg rayDirection, float cylinderRadius) Intersect the specified infinite cylinder with the specified ray.static floatrayCylinder(Vec3Arg rayOrigin, Vec3Arg rayDirection, float cylinderHalfHeight, float cylinderRadius) Intersect the specified finite cylinder with the specified ray.static floatIntersect the specified sphere with the specified ray.static floatIntersect the specified triangle with the specified ray.static voidregisterCustomAllocator(long allocateVa, long reallocateVa, long freeVa, long alignedAllocateVa, long alignedFreeVa) Register the allocation hook to use the specified functions.static voidRegister the allocation hook to use malloc/free.static voidRegister all physics types with the factory and install their collision handlers.static voidsetTraceAllocations(boolean setting) Enable or disable allocation tracing in Debug native libraries.static floatsign(float input) Return the (binary) sign of the specified single-precision value.static floatsin(float angle) Return the sine of the specified single-precision angle.static floatsquare(float value) Return the square of the specified single-precision value.static intsquare(int value) Return the square of the specified integer value.static voidSet the next available character ID to 1.static voidsSetNextCharacterId(int nextValue) Set the next available character ID to the specified value.static booleanTest whether the native library supports the ObjectStream format.static floattan(float angle) Return the tangent ratio of the specified single-precision angle.static voidExecute a test written in native code.static voidUnregister all physics types with the factory.static StringReturn the Jolt-JNI version string that's hard-coded into the native library.
-
Field Details
-
cDefaultConvexRadius
public static final float cDefaultConvexRadiusdefault rounding of corners in convex shapes (in meters)value should match Jolt/Physics/PhysicsSettings.h
- See Also:
-
JPH_PI
public static final float JPH_PIsingle-precision value of Pi- See Also:
-
cEmptySubShapeId
public static final int cEmptySubShapeIdempty sub-shape IDvalue should match Jolt/Physics/Collision/Shape/SubShapeID.h
- See Also:
-
cInvalidBodyId
public static final int cInvalidBodyIdinvalid body IDvalue should match Jolt/Physics/Body/BodyID.h
- See Also:
-
cMaxPhysicsBarriers
public static final int cMaxPhysicsBarriersstandard 2nd argument to theJobSystemThreadPoolconstructorvalue should match Jolt/Physics/PhysicsSettings.h
- See Also:
-
cMaxPhysicsJobs
public static final int cMaxPhysicsJobsstandard first argument to theJobSystemThreadPoolconstructorvalue should match Jolt/Physics/PhysicsSettings.h
- See Also:
-
SWIZZLE_X
public static final int SWIZZLE_Xindex of the X component, for swizzling- See Also:
-
SWIZZLE_Y
public static final int SWIZZLE_Yindex of the Y component, for swizzling- See Also:
-
SWIZZLE_Z
public static final int SWIZZLE_Zindex of the Z component, for swizzling- See Also:
-
nullptr
generic null pointer (to expedite porting of C++ code)
-
-
Method Details
-
aCos
public static float aCos(float ratio) Return the inverse cosine of the specified single-precision ratio.- Parameters:
ratio- the input cosine ratio (≥-1, ≤1)- Returns:
- the angle (in radians)
-
aTan
public static float aTan(float ratio) Return the inverse tangent of the specified single-precision ratio.- Parameters:
ratio- the input tangent ratio- Returns:
- the angle (in radians)
-
aTan2
public static float aTan2(float opposite, float adjacent) Return the angle of the specified single-precision right triangle.- Parameters:
opposite- the signed length of the opposite sideadjacent- the signed length of the adjacent side- Returns:
- the angle (in radians)
-
buildType
Return the Jolt-JNI build-type string that's hard-coded in the native library.- Returns:
- either "Debug" or "Release"
-
cos
public static float cos(float angle) Return the cosine of the specified single-precision angle.- Parameters:
angle- the input angle (in radians)- Returns:
- the cosine ratio
-
countDeletes
public static int countDeletes()Return the cumulative number ofdeleteoperations in glue code, in Debug native libraries.- Returns:
- the count (≥0)
-
countNews
public static int countNews()Return the cumulative number ofnewoperations in glue code, in Debug native libraries, excluding ref targets.- Returns:
- the count (≥0)
-
degreesToRadians
public static float degreesToRadians(float degrees) Convert the specified angle from degrees to radians.- Parameters:
degrees- the angle to convert (in degrees)- Returns:
- the converted angle (in radians)
-
destroyFactory
public static void destroyFactory()Destroy the factory for deserialization of saved data.- See Also:
-
detLog
Append a message to the determinism log. (native macro: JPH_DET_LOG)- Parameters:
message- (not null)
-
estimateCollisionResponse
public static void estimateCollisionResponse(ConstBody body1, ConstBody body2, ConstContactManifold manifold, CollisionEstimationResult storeResult, float combinedFriction, float combinedRestitution) Estimate the contact impulses and body velocity changes resulting from a collision.- Parameters:
body1- the first colliding body (not null, unaffected)body2- the 2nd colliding body (not null, unaffected)manifold- the collision manifold (not null, unaffected)storeResult- storage for impulses and velocities (not null, modified)combinedFriction- the combined friction of the 2 bodiescombinedRestitution- the combined restitution of the 2 bodies
-
estimateCollisionResponse
public static void estimateCollisionResponse(ConstBody body1, ConstBody body2, ConstContactManifold manifold, CollisionEstimationResult storeResult, float combinedFriction, float combinedRestitution, float minVelocity) Estimate the contact impulses and body velocity changes resulting from a collision.- Parameters:
body1- the first colliding body (not null, unaffected)body2- the 2nd colliding body (not null, unaffected)manifold- the collision manifold (not null, unaffected)storeResult- storage for impulses and velocities (not null, modified)combinedFriction- the combined friction of the 2 bodiescombinedRestitution- the combined restitution of the 2 bodiesminVelocity- the minimum speed for restitution to be applied (in meters per second, default=1)
-
estimateCollisionResponse
public static void estimateCollisionResponse(ConstBody body1, ConstBody body2, ConstContactManifold manifold, CollisionEstimationResult storeResult, float combinedFriction, float combinedRestitution, float minVelocity, int numIterations) Estimate the contact impulses and body velocity changes resulting from a collision.- Parameters:
body1- the first colliding body (not null, unaffected)body2- the 2nd colliding body (not null, unaffected)manifold- the collision manifold (not null, unaffected)storeResult- storage for impulses and velocities (not null, modified)combinedFriction- the combined friction of the 2 bodiescombinedRestitution- the combined restitution of the 2 bodiesminVelocity- the minimum speed for restitution to be applied (in meters per second, default=1)numIterations- the number of iterations the impulse solver to use (default=10)
-
getConfigurationString
Return a string containing important configuration settings.- Returns:
- the string value
-
hashBytes
public static long hashBytes(long dataVa, int inSize) Return a hash code for the specified data bytes.- Parameters:
dataVa- the virtual address of the data, or 0 for no datainSize- the number of data bytes, or 0 for no data- Returns:
- the hash code
-
hashBytes
Combine the specified quaternion with the specified hash code.- Parameters:
quaternion- the quaternion to combine (not null, unaffected)oldHash- the old hash code- Returns:
- the new hash code
-
hashBytes
Combine the specified vector with the specified hash code.- Parameters:
vector- the vector to combine (not null, unaffected)oldHash- the old hash code- Returns:
- the new hash code
-
hashCombine
public static long hashCombine(long oldHash, int iValue) Combine the specified 32-bit integer with the specified hash code.- Parameters:
oldHash- the old hash codeiValue- the integer value to combine- Returns:
- the new hash code
-
hashCombine
public static long hashCombine(long oldHash, long lValue) Combine the specified 64-bit integer with the specified hash code.- Parameters:
oldHash- the old hash codelValue- the integer value to combine- Returns:
- the new hash code
-
hashCombine
Combine the specified location vector with the specified hash code.- Parameters:
oldHash- the old hash codevector- the vector to combine (not null, unaffected)- Returns:
- the new hash code
-
hashCombine
Combine the specified vector with the specified hash code.- Parameters:
oldHash- the old hash codevector- the vector to combine (not null, unaffected)- Returns:
- the new hash code
-
implementsDebugRendering
public static boolean implementsDebugRendering()Test whether the native library implements debug rendering. (native macro: JPH_DEBUG_RENDERER)- Returns:
trueif implemented, otherwisefalse
-
implementsDeterminismLog
public static boolean implementsDeterminismLog()Test whether the native library implements extra logging to help debug determinism issues. (native macro: JPH_DET_LOG)- Returns:
trueif implemented, otherwisefalse
-
installCerrTraceCallback
public static void installCerrTraceCallback()Install an alternative trace callback that usescerr. -
installDefaultAssertCallback
public static void installDefaultAssertCallback()Install the default assert callback. -
installDefaultTraceCallback
public static void installDefaultTraceCallback()Install the default trace callback, which usescout. -
installJavaTraceCallback
Install a trace callback that uses aPrintStream.- Parameters:
stream- where to send trace output (not null)
-
isDoublePrecision
public static boolean isDoublePrecision()Test whether the native library uses double-precision location vectors. (native macro: JPH_DOUBLE_PRECISION)- Returns:
trueif double-precision, otherwisefalse
-
listClasses
List all classes in the specified Jolt-JNI package.- Parameters:
packageName- the name of the package (must start with "com.github.stephengold.joltjni")- Returns:
- a new collection
-
newDirectByteBuffer
Create a directByteBufferwith the specified capacity.- Parameters:
numBytes- the desired capacity (in bytes)- Returns:
- a new direct buffer, zeroed and rewound but not flipped
-
newDirectDoubleBuffer
Create a directDoubleBufferwith native byte order and the specified capacity.- Parameters:
numDoubles- the desired capacity (in doubles)- Returns:
- a new direct buffer, zeroed and rewound but not flipped
-
newDirectFloatBuffer
Create a directFloatBufferwith native byte order and the specified capacity.- Parameters:
numFloats- the desired capacity (in floats)- Returns:
- a new direct buffer, zeroed and rewound but not flipped
-
newDirectIntBuffer
Create a directIntBufferwith native byte order and the specified capacity.- Parameters:
numInts- the desired capacity (in ints)- Returns:
- a new direct buffer, zeroed and rewound but not flipped
-
newDirectShortBuffer
Create a directShortBufferwith native byte order and the specified capacity.- Parameters:
numShorts- the desired capacity (in ints)- Returns:
- a new direct buffer, zeroed and rewound but not flipped
-
newFactory
public static boolean newFactory()Create a factory for deserialization of saved data.- Returns:
trueif successful, otherwisefalse- See Also:
-
perlinNoise3
public static float perlinNoise3(float x, float y, float z, int xWrap, int yWrap, int zWrap) Generate 3-D Perlin noise.- Parameters:
x- the X coordinatey- the Y coordinatez- the Z coordinatexWrap- the wraparound interval for the X coordinate (power of 2) or 0 for don't careyWrap- the wraparound interval for the Y coordinate (power of 2) or 0 for don't carezWrap- the wraparound interval for the Z coordinate (power of 2) or 0 for don't care- Returns:
- a sample value
-
profileDump
Dump profiler data. (native macro: JPH_PROFILE_DUMP)- Parameters:
message- (not null)
-
profileEnd
public static void profileEnd()Terminate the profiler. (native macro: JPH_PROFILE_END) -
profileNextFrame
public static void profileNextFrame()Increment the profiler's frame counter. (native macro: JPH_PROFILE_NEXTFRAME) -
profileStart
Start an instrumented code section. (native macro: JPH_PROFILE_START)- Parameters:
name- the section name (not null)
-
radiansToDegrees
public static float radiansToDegrees(float radians) Convert the specified angle from radians to degrees.- Parameters:
radians- the angle to convert (in radians)- Returns:
- the converted angle (in degrees)
-
rayAaBox
public static float rayAaBox(Vec3Arg rayOrigin, RayInvDirection invDirection, Vec3Arg minimum, Vec3Arg maximum) Intersect the specified axis-aligned box with the specified ray.- Parameters:
rayOrigin- the origin of the ray (not null, unaffected)invDirection- the inverse direction of the ray (not null, unaffected)minimum- the minimum coordinates of the box (not null, unaffected)maximum- the maximum coordinates of the box (not null, unaffected)- Returns:
- the minimum distance along ray, or
FLT_MAXif the ray misses the box
-
rayAaBoxHits
public static boolean rayAaBoxHits(Vec3Arg startLocation, Vec3Arg offset, Vec3Arg minimum, Vec3Arg maximum) Intersect the specified axis-aligned box with the specified ray.- Parameters:
startLocation- the desired start location of the ray (not null, unaffected)offset- the desired end offset from the start location (not null, unaffected)minimum- the minimum coordinates of the box (not null, unaffected)maximum- the maximum coordinates of the box (not null, unaffected)- Returns:
trueif there is a hit, otherwisefalse
-
rayCapsule
public static float rayCapsule(Vec3Arg rayOrigin, Vec3Arg rayDirection, float capsuleHalfHeight, float capsuleRadius) Intersect the specified capsule with the specified ray.- Parameters:
rayOrigin- the origin of the ray (not null, unaffected)rayDirection- the direction of the ray (not null, unaffected)capsuleHalfHeight- half the height of the capsulecapsuleRadius- the radius of the capsule- Returns:
- the minimum distance along ray, or
FLT_MAXif the ray misses the capsule
-
rayCylinder
Intersect the specified infinite cylinder with the specified ray.- Parameters:
rayOrigin- the origin of the ray (not null, unaffected)rayDirection- the direction of the ray (not null, unaffected)cylinderRadius- the radius of the cylinder- Returns:
- the minimum distance along ray, or
FLT_MAXif the ray misses the cylinder
-
rayCylinder
public static float rayCylinder(Vec3Arg rayOrigin, Vec3Arg rayDirection, float cylinderHalfHeight, float cylinderRadius) Intersect the specified finite cylinder with the specified ray.- Parameters:
rayOrigin- the origin of the ray (not null, unaffected)rayDirection- the direction of the ray (not null, unaffected)cylinderHalfHeight- half of the height of the cylindercylinderRadius- the radius of the cylinder- Returns:
- the minimum distance along ray, or
FLT_MAXif the ray misses the cylinder
-
raySphere
public static float raySphere(Vec3Arg rayOrigin, Vec3Arg rayDirection, Vec3Arg sphereCenter, float sphereRadius) Intersect the specified sphere with the specified ray.- Parameters:
rayOrigin- the origin of the ray (not null, unaffected)rayDirection- the direction of the ray (not null, unaffected)sphereCenter- the center of the sphere (not null, unaffected)sphereRadius- the radius of the sphere- Returns:
- the minimum distance along ray, or
FLT_MAXif the ray misses the sphere
-
rayTriangle
public static float rayTriangle(Vec3Arg rayOrigin, Vec3Arg rayDirection, Vec3Arg v0, Vec3Arg v1, Vec3Arg v2) Intersect the specified triangle with the specified ray.- Parameters:
rayOrigin- the origin of the ray (not null, unaffected)rayDirection- the direction of the ray (not null, unaffected)v0- the first vertex of the triangle (not null, unaffected)v1- the 2nd vertex of the triangle (not null, unaffected)v2- the 3rd vertex of the triangle (not null, unaffected)- Returns:
- the minimum distance along ray, or
FLT_MAXif the ray misses the triangle
-
registerCustomAllocator
public static void registerCustomAllocator(long allocateVa, long reallocateVa, long freeVa, long alignedAllocateVa, long alignedFreeVa) Register the allocation hook to use the specified functions. This must be done before any other Jolt function is called.- Parameters:
allocateVa- the virtual address of the desired Allocate functionreallocateVa- the virtual address of the desired Reallocate functionfreeVa- the virtual address of the desired Free functionalignedAllocateVa- the virtual address of the desired AlignedAllocate functionalignedFreeVa- the virtual address of the desired AlignedFree function
-
registerDefaultAllocator
public static void registerDefaultAllocator()Register the allocation hook to use malloc/free. This must be done before any other Jolt function is called. -
registerTypes
public static void registerTypes()Register all physics types with the factory and install their collision handlers.- See Also:
-
setTraceAllocations
public static void setTraceAllocations(boolean setting) Enable or disable allocation tracing in Debug native libraries.- Parameters:
setting-trueto enable tracing,falseto disable it (default=false)
-
sign
public static float sign(float input) Return the (binary) sign of the specified single-precision value.- Parameters:
input- the input value- Returns:
- -1 if the input is negative, otherwise +1
-
sin
public static float sin(float angle) Return the sine of the specified single-precision angle.- Parameters:
angle- the input angle (in radians)- Returns:
- the sine ratio
-
square
public static float square(float value) Return the square of the specified single-precision value.- Parameters:
value- the input value- Returns:
- the square
-
square
public static int square(int value) Return the square of the specified integer value.- Parameters:
value- the input value- Returns:
- the square
-
sSetNextCharacterId
public static void sSetNextCharacterId()Set the next available character ID to 1. -
sSetNextCharacterId
public static void sSetNextCharacterId(int nextValue) Set the next available character ID to the specified value. (native function:CharacterID::sSetNextCharacterID)- Parameters:
nextValue- the desired next ID
-
supportsObjectStream
public static boolean supportsObjectStream()Test whether the native library supports the ObjectStream format. (native macro: JPH_OBJECT_STREAM)- Returns:
trueif supported, otherwisefalse
-
tan
public static float tan(float angle) Return the tangent ratio of the specified single-precision angle.- Parameters:
angle- the input angle (in radians)- Returns:
- the tangent ratio
-
test000
Execute a test written in native code. Intended for testing only.- Parameters:
args- command-line arguments
-
unregisterTypes
public static void unregisterTypes()Unregister all physics types with the factory.- See Also:
-
versionString
Return the Jolt-JNI version string that's hard-coded into the native library.- Returns:
- the version string (not null, not empty)
-