Skip to content

Commit b304db7

Browse files
committed
zbullet: Tiny progress.
1 parent 735aaa8 commit b304db7

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

libs/zbullet/src/zbullet.zig

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,55 @@ const c = @cImport({
55
@cInclude("cbullet.h");
66
});
77

8-
pub const Vector3 = [3]f32;
9-
108
pub const World = struct {
119
handle: c.CbtWorldHandle,
1210

13-
pub fn create() World {
11+
pub fn allocateAndCreate() World {
1412
return .{ .handle = c.cbtWorldCreate() };
1513
}
1614

17-
pub fn destroy(world: World) void {
15+
pub fn destroyAndDeallocate(world: World) void {
1816
c.cbtWorldDestroy(world.handle);
1917
}
2018

21-
pub fn setGravity(world: World, gravity: []const f32) void {
22-
assert(gravity.len >= 3);
23-
c.cbtWorldSetGravity(world.handle, gravity.ptr);
19+
pub fn setGravity(world: World, gravity: [3]f32) void {
20+
c.cbtWorldSetGravity(world.handle, &gravity);
21+
}
22+
23+
pub fn getGravity(world: World) [3]f32 {
24+
var gravity: [3]f32 = undefined;
25+
c.cbtWorldGetGravity(world.handle, &gravity);
26+
return gravity;
2427
}
2528

26-
pub fn getGravity(world: World, gravity: []f32) void {
27-
assert(gravity.len >= 3);
28-
c.cbtWorldGetGravity(world.handle, gravity.ptr);
29+
pub fn stepSimulation(world: World, time_step: f32, max_sub_steps: u32, fixed_time_step: f32) u32 {
30+
return @intCast(u32, c.cbtWorldStepSimulation(
31+
world.handle,
32+
time_step,
33+
@intCast(c_int, max_sub_steps),
34+
fixed_time_step,
35+
));
2936
}
3037
};
3138

3239
test "zbullet.world.gravity" {
3340
const zm = @import("zmath");
3441

35-
const world = World.create();
36-
defer world.destroy();
42+
const world = World.allocateAndCreate();
43+
defer world.destroyAndDeallocate();
3744

3845
{
3946
const v = zm.f32x4(0.0, -10.0, 0.0, 0.0);
4047
var gravity: [3]f32 = undefined;
4148
zm.store(gravity[0..], v, 3);
42-
world.setGravity(gravity[0..]);
49+
world.setGravity(gravity);
4350
}
4451

52+
const num_steps = world.stepSimulation(1.0 / 60.0, 1, 1.0 / 60.0);
53+
try expect(num_steps == 1);
54+
4555
const gravity = blk: {
46-
var gravity: [3]f32 = undefined;
47-
world.getGravity(gravity[0..]);
56+
const gravity = world.getGravity();
4857
break :blk zm.load(gravity[0..], zm.F32x4, 3);
4958
};
5059
try expect(gravity[0] == 0.0 and gravity[1] == -10.0 and gravity[2] == 0.0);

samples/bullet_physics_test/build.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ pub fn build(b: *std.build.Builder) void {
111111
};
112112
exe.addPackage(pkg_win32);
113113

114+
const pkg_zbullet = Pkg{
115+
.name = "zbullet",
116+
.path = .{ .path = "../../libs/zbullet/src/zbullet.zig" },
117+
};
118+
exe.addPackage(pkg_zbullet);
119+
114120
const pkg_common = Pkg{
115121
.name = "common",
116122
.path = .{ .path = "../../libs/common/common.zig" },

0 commit comments

Comments
 (0)