From 154961b8cd61d5788b0442756acc3381c0fc6166 Mon Sep 17 00:00:00 2001 From: HVukman Date: Wed, 11 Feb 2026 15:15:24 +0100 Subject: [PATCH 1/4] Create hellobox.odin --- box2d/hellobox.odin | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 box2d/hellobox.odin diff --git a/box2d/hellobox.odin b/box2d/hellobox.odin new file mode 100644 index 0000000..125c6ba --- /dev/null +++ b/box2d/hellobox.odin @@ -0,0 +1,61 @@ +package hellobox + +import "core:fmt" +import "vendor:box2d" + +// Translation of https://box2d.org/documentation/hello.html + + +main :: proc() { + + // Create World + world_def := box2d.DefaultWorldDef() + world_def.gravity = [2]f32{0.0,-10.0} + world_id := box2d.CreateWorld(world_def) + + // Create Ground + ground_bodydef := box2d.DefaultBodyDef() + ground_bodydef.position = box2d.Vec2{0.0,-10.0} + ground_Id := box2d.CreateBody(world_id,ground_bodydef) + // Create Body + + ground_box := box2d.MakeBox(50.0,10.0) + + ground_shape_def := box2d.DefaultShapeDef() + ground_polygon := box2d.CreatePolygonShape(ground_Id,ground_shape_def,ground_box) + + // create dynamic body + body_def := box2d.DefaultBodyDef() + body_def.type = box2d.BodyType.dynamicBody + body_def.position = box2d.Vec2{0.0,4.0} + body_id := box2d.CreateBody(world_id,body_def) + + dynamic_box := box2d.MakeBox(1.0,1.0) + shape_def := box2d.DefaultShapeDef() + // Reset friction and density + shape_def.density = 1.0 + shape_def.material.friction = 0.3 + + shape_body:=box2d.CreatePolygonShape(body_id,shape_def,dynamic_box) + + // simulation time step + time_step := 1.0/60.0 + + substep_count := 4 + + // Keep handles for potential use + // They are not needed explicitly, but the results will be wrong without them + _ = ground_polygon + _ = shape_body + + // Simulation steps + for i:=0;i<90;i+=1 { + box2d.World_Step(world_id,f32(time_step),i32(substep_count)) + pos := box2d.Body_GetPosition(body_id) + rot := box2d.Body_GetRotation(body_id) + + fmt.printfln("%4.2f %4.2f %4.2f\n", pos.x, pos.y, box2d.Rot_GetAngle(rot)) + } + box2d.DestroyWorld(world_id) + +} From e05146a2454a3b25bc0968b20e89e65fe13ef21b Mon Sep 17 00:00:00 2001 From: HVukman Date: Wed, 11 Feb 2026 15:16:31 +0100 Subject: [PATCH 2/4] Update check.yml --- .github/workflows/check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 73b767d..0412c2a 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -50,6 +50,7 @@ jobs: odin check arena_allocator $FLAGS + odin check box2d/hellobox $FLAGS odin check directx/d3d12_triangle_sdl2 -target:windows_amd64 $FLAGS odin check glfw/window $FLAGS From 9ea07c440ab3133b418b29645bfbcf289db9159a Mon Sep 17 00:00:00 2001 From: HVukman Date: Wed, 11 Feb 2026 15:17:52 +0100 Subject: [PATCH 3/4] Create hello_box.odin --- box2d/hello_box/hello_box.odin | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 box2d/hello_box/hello_box.odin diff --git a/box2d/hello_box/hello_box.odin b/box2d/hello_box/hello_box.odin new file mode 100644 index 0000000..b286eca --- /dev/null +++ b/box2d/hello_box/hello_box.odin @@ -0,0 +1,61 @@ +package hello_box + +import "core:fmt" +import "vendor:box2d" + +// Translation of https://box2d.org/documentation/hello.html + + +main :: proc() { + + // Create World + world_def := box2d.DefaultWorldDef() + world_def.gravity = [2]f32{0.0,-10.0} + world_id := box2d.CreateWorld(world_def) + + // Create Ground + ground_bodydef := box2d.DefaultBodyDef() + ground_bodydef.position = box2d.Vec2{0.0,-10.0} + ground_Id := box2d.CreateBody(world_id,ground_bodydef) + // Create Body + + ground_box := box2d.MakeBox(50.0,10.0) + + ground_shape_def := box2d.DefaultShapeDef() + ground_polygon := box2d.CreatePolygonShape(ground_Id,ground_shape_def,ground_box) + + // create dynamic body + body_def := box2d.DefaultBodyDef() + body_def.type = box2d.BodyType.dynamicBody + body_def.position = box2d.Vec2{0.0,4.0} + body_id := box2d.CreateBody(world_id,body_def) + + dynamic_box := box2d.MakeBox(1.0,1.0) + shape_def := box2d.DefaultShapeDef() + // Reset friction and density + shape_def.density = 1.0 + shape_def.material.friction = 0.3 + + shape_body:=box2d.CreatePolygonShape(body_id,shape_def,dynamic_box) + + // simulation time step + time_step := 1.0/60.0 + + substep_count := 4 + + // Keep handles for potential use + // They are not needed explicitly, but the results will be wrong without them + _ = ground_polygon + _ = shape_body + + // Simulation steps + for i:=0;i<90;i+=1 { + box2d.World_Step(world_id,f32(time_step),i32(substep_count)) + pos := box2d.Body_GetPosition(body_id) + rot := box2d.Body_GetRotation(body_id) + + fmt.printfln("%4.2f %4.2f %4.2f\n", pos.x, pos.y, box2d.Rot_GetAngle(rot)) + } + box2d.DestroyWorld(world_id) + +} From 418a8c0224ebff86186c71621422b4c88fff97d6 Mon Sep 17 00:00:00 2001 From: HVukman Date: Wed, 11 Feb 2026 15:22:58 +0100 Subject: [PATCH 4/4] Update hello_box.odin --- box2d/hello_box/hello_box.odin | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/box2d/hello_box/hello_box.odin b/box2d/hello_box/hello_box.odin index b286eca..5c19207 100644 --- a/box2d/hello_box/hello_box.odin +++ b/box2d/hello_box/hello_box.odin @@ -17,10 +17,9 @@ main :: proc() { ground_bodydef := box2d.DefaultBodyDef() ground_bodydef.position = box2d.Vec2{0.0,-10.0} ground_Id := box2d.CreateBody(world_id,ground_bodydef) + // Create Body - ground_box := box2d.MakeBox(50.0,10.0) - ground_shape_def := box2d.DefaultShapeDef() ground_polygon := box2d.CreatePolygonShape(ground_Id,ground_shape_def,ground_box) @@ -32,15 +31,14 @@ main :: proc() { dynamic_box := box2d.MakeBox(1.0,1.0) shape_def := box2d.DefaultShapeDef() + // Reset friction and density shape_def.density = 1.0 shape_def.material.friction = 0.3 - shape_body:=box2d.CreatePolygonShape(body_id,shape_def,dynamic_box) // simulation time step time_step := 1.0/60.0 - substep_count := 4 // Keep handles for potential use @@ -56,6 +54,7 @@ main :: proc() { fmt.printfln("%4.2f %4.2f %4.2f\n", pos.x, pos.y, box2d.Rot_GetAngle(rot)) } + // Delete World box2d.DestroyWorld(world_id) }