@@ -5,46 +5,55 @@ const c = @cImport({
5
5
@cInclude ("cbullet.h" );
6
6
});
7
7
8
- pub const Vector3 = [3 ]f32 ;
9
-
10
8
pub const World = struct {
11
9
handle : c.CbtWorldHandle ,
12
10
13
- pub fn create () World {
11
+ pub fn allocateAndCreate () World {
14
12
return .{ .handle = c .cbtWorldCreate () };
15
13
}
16
14
17
- pub fn destroy (world : World ) void {
15
+ pub fn destroyAndDeallocate (world : World ) void {
18
16
c .cbtWorldDestroy (world .handle );
19
17
}
20
18
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 ;
24
27
}
25
28
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
+ ));
29
36
}
30
37
};
31
38
32
39
test "zbullet.world.gravity" {
33
40
const zm = @import ("zmath" );
34
41
35
- const world = World .create ();
36
- defer world .destroy ();
42
+ const world = World .allocateAndCreate ();
43
+ defer world .destroyAndDeallocate ();
37
44
38
45
{
39
46
const v = zm .f32x4 (0.0 , -10.0 , 0.0 , 0.0 );
40
47
var gravity : [3 ]f32 = undefined ;
41
48
zm .store (gravity [0.. ], v , 3 );
42
- world .setGravity (gravity [0 .. ] );
49
+ world .setGravity (gravity );
43
50
}
44
51
52
+ const num_steps = world .stepSimulation (1.0 / 60.0 , 1 , 1.0 / 60.0 );
53
+ try expect (num_steps == 1 );
54
+
45
55
const gravity = blk : {
46
- var gravity : [3 ]f32 = undefined ;
47
- world .getGravity (gravity [0.. ]);
56
+ const gravity = world .getGravity ();
48
57
break :blk zm .load (gravity [0.. ], zm .F32x4 , 3 );
49
58
};
50
59
try expect (gravity [0 ] == 0.0 and gravity [1 ] == -10.0 and gravity [2 ] == 0.0 );
0 commit comments