Odin foreign function bindings for Jolt Physics via joltc, a C wrapper for the Jolt Physics engine.
joltc.odin— 1:1 raw foreign bindings to thejoltc.hC API (all types, enums, callbacks, and ~400+ functions)physics.odin— Ergonomic Odin wrapper (Physics_Worldstruct, shape factories, body helpers)
- Odin (latest)
- CMake 3.15+
- C++17 compiler (GCC, Clang, or MSVC)
# Clone the bindings
git clone https://github.com/ronneljamesbote/joltphysics-odin-bindings.git
cd joltphysics-odin-binding
# Clone joltc (the C wrapper) into vendor/
git clone https://github.com/amerkoleci/joltc.git vendor/joltc
# Build joltc as a static library
./build_joltc.sh staticThis compiles both joltc and the full Jolt Physics engine. Output goes to vendor/joltc/build/static/lib/:
libjoltc.a— the C bridgelibJolt.a— Jolt Physics itself
Add the repo to your project, then import:
import physics "./joltphysics-odin"Build with the required linker flags:
odin build src/main.odin \
-extra-linker-flags:"-Lpath/to/joltphysics-odin/vendor/joltc/build/static/lib -ljoltc -lJolt -lstdc++ -lm -lpthread"On macOS, use -lc++ instead of -lstdc++.
package main
import "core:fmt"
import physics "./joltphysics-odin"
main :: proc() {
world := physics.world_init()
defer physics.world_shutdown(&world)
floor := physics.make_box_shape(50, 1, 50)
defer physics.jph_shape_destroy(floor)
floor_id := physics.body_add(&world, floor, 0, -1, 0, 0, 0, 0, 1, .Static)
_ = floor_id
box := physics.make_box_shape(0.5, 0.5, 0.5)
defer physics.jph_shape_destroy(box)
box_id := physics.body_add(&world, box, 0, 5, 0, 0, 0, 0, 1, .Dynamic)
for i in 0 ..< 60 {
physics.world_update(&world, 1.0 / 60.0)
x, y, z := physics.body_get_position(&world, box_id)
if i % 10 == 0 {
fmt.printf("box position: %.3f %.3f %.3f\n", x, y, z)
}
}
physics.body_remove(&world, box_id)
physics.body_remove(&world, floor_id)
}| Proc | Description |
|---|---|
world_init() |
Create a physics world with job system, broadphase, and collision filters |
world_update(w, delta_time, steps) |
Step the simulation |
world_shutdown(w) |
Destroy world, job system, and shutdown Jolt |
make_box_shape(hx, hy, hz) |
Create a box shape |
make_sphere_shape(radius) |
Create a sphere shape |
make_capsule_shape(half_height, radius) |
Create a capsule shape |
body_add(w, shape, px, py, pz, rx, ry, rz, rw, motion, layer) |
Add a rigid body |
body_remove(w, id) |
Remove and destroy a body |
body_get_position(w, id) / body_set_position(...) |
Get/set body position |
body_get_rotation(w, id) / body_set_rotation(...) |
Get/set body rotation |
body_get_linear_velocity(...) / body_set_linear_velocity(...) |
Get/set velocity |
body_add_force(w, id, x, y, z) |
Apply force |
body_add_impulse(w, id, x, y, z) |
Apply impulse |
body_is_active(w, id) |
Check if body is active |
All functions and types from joltc.h are available with the jph_ prefix. See the file or the joltc header for the full list.
./build_joltc.sh sharedThe shared library is needed if you want your physics state to survive DLL reloads in a hot-reload setup.
This project is MIT licensed. See LICENSE.
The bindings wrap joltc by Amer Koleci (MIT) which wraps Jolt Physics by Jorrit Rouwe (MIT).
Attribution: This project uses joltc, a C wrapper for Jolt Physics. joltc is MIT licensed and is the work of Amer Koleci. When building, clone joltc into vendor/joltc as shown in the quick start.