java.lang.Object
com.github.stephengold.joltjni.MiscUtil

public final class MiscUtil extends Object
Seldom-used utility methods. Most of these relate to character IDs, collision estimation, hashing, and ray intersections.
  • Method Details

    • 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. (see Physics/Collision/EstimateCollisionResponse.cpp)
      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 bodies
      combinedRestitution - 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. (see Physics/Collision/EstimateCollisionResponse.cpp)
      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 bodies
      combinedRestitution - the combined restitution of the 2 bodies
      minVelocity - 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. (see Physics/Collision/EstimateCollisionResponse.cpp)
      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 bodies
      combinedRestitution - the combined restitution of the 2 bodies
      minVelocity - 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)
    • hashBytes

      public static long hashBytes(long dataVa, int inSize)
      Return a hash code for the specified data bytes. (see Jolt/Core/HashCombine.h)
      Parameters:
      dataVa - the virtual address of the data, or 0 for no data
      inSize - the number of data bytes, or 0 for no data
      Returns:
      the hash code
    • hashBytes

      public static long hashBytes(QuatArg quaternion, long oldHash)
      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

      public static long hashBytes(RVec3Arg vector, long oldHash)
      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. (see Jolt/Core/HashCombine.h)
      Parameters:
      oldHash - the old hash code
      iValue - 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 code
      lValue - the integer value to combine
      Returns:
      the new hash code
    • hashCombine

      public static long hashCombine(long oldHash, RVec3Arg vector)
      Combine the specified location vector with the specified hash code.
      Parameters:
      oldHash - the old hash code
      vector - the vector to combine (not null, unaffected)
      Returns:
      the new hash code
    • hashCombine

      public static long hashCombine(long oldHash, Vec3Arg vector)
      Combine the specified vector with the specified hash code.
      Parameters:
      oldHash - the old hash code
      vector - the vector to combine (not null, unaffected)
      Returns:
      the new hash code
    • listClasses

      public static Set<Class<?>> listClasses(String packageName)
      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
    • perlinNoise3

      public static float perlinNoise3(float x, float y, float z, int xWrap, int yWrap, int zWrap)
      Generate 3-D Perlin noise. (see TestFramework/External/Perlin.cpp)
      Parameters:
      x - the X coordinate
      y - the Y coordinate
      z - the Z coordinate
      xWrap - the wraparound interval for the X coordinate (power of 2) or 0 for don't care
      yWrap - the wraparound interval for the Y coordinate (power of 2) or 0 for don't care
      zWrap - the wraparound interval for the Z coordinate (power of 2) or 0 for don't care
      Returns:
      a sample value
    • rayAaBox

      public static float rayAaBox(Vec3Arg rayOrigin, RayInvDirection invDirection, Vec3Arg minimum, Vec3Arg maximum)
      Intersect the specified axis-aligned box with the specified ray. (see Jolt/Geometry/RayAABox.h)
      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_MAX if 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. (see Jolt/Geometry/RayAABox.h)
      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:
      true if there is a hit, otherwise false
    • rayCapsule

      public static float rayCapsule(Vec3Arg rayOrigin, Vec3Arg rayDirection, float capsuleHalfHeight, float capsuleRadius)
      Intersect the specified capsule with the specified ray. (see Jolt/Geometry/RayCapsule.h)
      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 capsule
      capsuleRadius - the radius of the capsule
      Returns:
      the minimum distance along ray, or FLT_MAX if the ray misses the capsule
    • rayCylinder

      public static float rayCylinder(Vec3Arg rayOrigin, Vec3Arg rayDirection, float cylinderRadius)
      Intersect the specified infinite cylinder with the specified ray. (see Jolt/Geometry/RayCylinder.h)
      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_MAX if 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. (see Jolt/Geometry/RayCylinder.h)
      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 cylinder
      cylinderRadius - the radius of the cylinder
      Returns:
      the minimum distance along ray, or FLT_MAX if 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. (see Jolt/Geometry/RaySphere.h)
      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_MAX if 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. (see Jolt/Geometry/RayTriangle.h)
      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_MAX if the ray misses the triangle
    • sSetNextCharacterId

      public static void sSetNextCharacterId()
      Set the next available character ID to 1. (see Jolt/Physics/Character/CharacterID.h)
    • 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