From 3a1f9fe6800ef5fe7bbf1c0a5976720383ba84fe Mon Sep 17 00:00:00 2001 From: Joel Stålnacke Date: Mon, 23 Mar 2026 19:50:18 +0200 Subject: Rewrite native code in Odin and use ECS --- lib/common.odin | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/common.odin (limited to 'lib/common.odin') diff --git a/lib/common.odin b/lib/common.odin new file mode 100644 index 0000000..3c6679f --- /dev/null +++ b/lib/common.odin @@ -0,0 +1,24 @@ +package djup + +import "core:math" + +vec2 :: [2]f32 + +vec2_dot :: proc(a, b: vec2) -> vec2 { + return vec2{a.x * b.x, a.y * b.y} +} + +vec2_length :: proc(v: vec2) -> f32 { + if v == (vec2{0, 0}) { + return 0 + } + return math.sqrt(math.pow(v.x, 2) + math.pow(v.y, 2)) +} + +vec2_normal :: proc(v: vec2) -> vec2 { + len := vec2_length(v) + if len == 0 { + return vec2{0, 0} + } + return v * (1 / len) +} -- cgit v1.2.3