Zig build package, bindings and C API for Bullet Physics SDK
  • C++ 93.9%
  • C 4.2%
  • Zig 1.4%
  • CMake 0.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
hazeycode 6c3acca3cd Update to Zig 0.17.0
Updates zmath dependency
2026-10-21 15:58:47 +01:00
.github/workflows upgrade setup-zig 2025-07-20 22:11:43 +01:00
libs add get/setLinearVelocity + add convexHullShape (#6) 2025-04-27 10:40:56 +01:00
src Update to Zig 0.17.0 2026-10-21 15:58:47 +01:00
.gitignore Upgrade to Zig 0.16.0 (#11) 2026-05-30 11:17:51 +01:00
build.zig Upgrade to Zig 0.16.0 (#11) 2026-05-30 11:17:51 +01:00
build.zig.zon Update to Zig 0.17.0 2026-10-21 15:58:47 +01:00
LICENSE files from monorepo @ 613d847104a072fc1d4442f58d5f50b3f9c3f27c 2024-11-03 20:24:52 +00:00
README.md fix: wrong variable name (#3) 2025-03-29 10:40:04 +00:00

zbullet

Zig bindings for Bullet Physics SDK

Overview

Bullet Physics SDK 3.25 (C++) ---> cbullet v0.2 (C) ---> zbullet (Zig)

cbullet is C API for Bullet Physics SDK which is being developed as a part of zig-gamedev project (source code).

zbullet is built on top of cbullet and provides Zig friendly bindings.

Features

Some cbullet features:

  • Most collision shapes
  • Rigid bodies
  • Most constraint types
  • Tries to minimize number of memory allocations
    • Multiple rigid bodies and motion states can be created with one memory allocation
    • New physics objects can re-use existing memory
  • Lots of error checks in debug builds

For an example code please see:

Getting started

Example build.zig:

pub fn build(b: *std.Build) void {
    const exe = b.addExecutable(.{ ... });

    const zbullet = b.dependency("zbullet", .{});
    exe.root_module.addImport("zbullet", zbullet.module("root"));
    exe.linkLibrary(zbullet.artifact("cbullet"));
}

Now in your code you may import and use zbullet:

const zbt = @import("zbullet");

pub fn main() !void {
    ...
    zbt.init(allocator);
    defer zbt.deinit();

    const world = zbt.initWorld();
    defer world.deinit();

    // Create unit cube shape.
    const box_shape = zbt.initBoxShape(&.{ 0.5, 0.5, 0.5 });
    defer box_shape.deinit();

    // Create rigid body that will use above shape.
    const initial_transform = [_]f32{
        1.0, 0.0, 0.0, // orientation
        0.0, 1.0, 0.0,
        0.0, 0.0, 1.0,
        2.0, 2.0, 2.0, // translation
    };
    const box_body = zbt.initBody(
        1.0, // mass (0.0 for static objects)
        &initial_transform,
        box_shape.asShape(),
    );
    defer box_body.deinit();

    // Add body to the physics world.
    world.addBody(box_body);
    defer world.removeBody(box_body);

    while (...) {
        ...
        // Perform a simulation step.
        _ = world.stepSimulation(time_step, .{});
        ...
    }
}