The Jolt-jni Project provides JVM bindings for Jolt Physics, to facilitate physics simulation in JVM languages such as Java and Kotlin.
Source code is provided under an MIT license.
There’s close correspondence between the class/method names of Jolt Physics and jolt-jni. For example:
- The
Body
class in jolt-jni will (eventually) provide all the functionality of theBody
class in Jolt Physics. - The
ConstBody
interface will include all theconst
methods of the Jolt PhysicsBody
class, such as itsGetPosition()
method, which in jolt-jni is calledgetPosition()
.
Things become slightly more interesting when C++ templates and public member data are involved. For instance:
- An array of body IDs is
Array<BodyID>
in Jolt Physics; in jolt-jni it’s called aBodyIdVector
. - The
mConvexRadius
member of the Jolt PhysicsBoxShapeSettings
class is accessed usinggetConvexRadius()
andsetConvexRadius()
in jolt-jni.
For a couple well-known Jolt Physics examples, line-for-line translations into Java are provided.
Jolt-jni comes pre-built as a platform-independent JVM library plus a set of native libraries, all downloadable from Maven Central.
Current jolt-jni releases provide the JVM library under 6 distinct names (artifact IDs). They also provide 24 native libraries, each specific to a particular platform, build type, and build flavor.
Your runtime classpath should include a JVM library plus 1-to-6 native libraries: a native library for each platform on which the code will run.
Add to the project’s "build.gradle" or "build.gradle.kts" file:
repositories {
mavenCentral()
}
dependencies {
implementation("com.github.stephengold:jolt-jni-Linux64:0.9.0") // JVM library
runtimeOnly("com.github.stephengold:jolt-jni-Linux64:0.9.0:DebugSp") // native library for Linux
// (Native libraries for other platforms could go here.)
}
- The "Linux64" platform name may be replaced by "Linux_ARM32hf", "Linux_ARM64", "MacOSX64", "MacOSX_ARM64", or "Windows64".
- The "DebugSp" classifier may be replaced by "DebugDp", "ReleaseSp", or "ReleaseDp".
- Install a Java Development Kit (JDK), if you don't already have one.
- Point the
JAVA_HOME
environment variable to your JDK installation: (In other words, set it to the path of a directory/folder containing a "bin" that contains a Java executable. That path might look something like "C:\Program Files\Eclipse Adoptium\jdk-17.0.3.7-hotspot" or "/usr/lib/jvm/java-17-openjdk-amd64/" or "/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home" .)
- using Bash or Zsh:
export JAVA_HOME="
path to installation"
- using Fish:
set -g JAVA_HOME "
path to installation"
- using Windows Command Prompt:
set JAVA_HOME="
path to installation"
- using PowerShell:
$env:JAVA_HOME = '
path to installation'
- Download and extract the jolt-jni source code from GitHub:
- using Git:
git clone https://github.com/stephengold/jolt-jni.git
cd jolt-jni
git checkout -b latest 0.9.0
- using a web browser:
- browse to the latest release
- follow the "Source code (zip)" link at the bottom of the page
- save the ZIP file
- extract the contents of the saved ZIP file
cd
to the extracted directory/folder
- (optional) Edit the "gradle.properties" file to configure the build.
- Run the Gradle wrapper:
- using Bash or Fish or PowerShell or Zsh:
./gradlew build
- using Windows Command Prompt:
.\gradlew build
After a successful build, artifacts will be found in "build/libs".
You can run the "hello world" example app:
- using Bash or Fish or PowerShell or Zsh:
./gradlew runHelloWorld
- using Windows Command Prompt:
.\gradlew runHelloWorld
You can run various scenes in the "performance test" example app:
- the ConvexVsMesh scene:
- using Bash or Fish or PowerShell or Zsh:
./gradlew runConvexVsMesh
- using Windows Command Prompt:
.\gradlew runConvexVsMesh
- using Bash or Fish or PowerShell or Zsh:
- the Pyramid scene:
- using Bash or Fish or PowerShell or Zsh:
./gradlew runPyramid
- using Windows Command Prompt:
.\gradlew runPyramid
- using Bash or Fish or PowerShell or Zsh:
- the Ragdoll scene:
- using Bash or Fish or PowerShell or Zsh:
./gradlew runRagdoll
- using Windows Command Prompt:
.\gradlew runRagdoll
- using Bash or Fish or PowerShell or Zsh:
You can restore the project to a pristine state:
- using Bash or Fish or PowerShell or Zsh:
./gradlew cleanAll
- using Windows Command Prompt:
.\gradlew cleanAll