summaryrefslogtreecommitdiff
path: root/src/vec.zig
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2022-12-21 21:53:24 +0100
committerTom Barrett <tom@tombarrett.xyz>2022-12-21 21:53:24 +0100
commit8ab21b7ec6bd83fe12b48534e4f670500e8d5e2c (patch)
tree3b52e0d8cd5187db969e0948b6e68f56df3677a0 /src/vec.zig
parent545c41f79e37e9b7d4b5bf7ba64aa7efa549aded (diff)
move to file
Diffstat (limited to 'src/vec.zig')
-rw-r--r--src/vec.zig25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/vec.zig b/src/vec.zig
new file mode 100644
index 0000000..cc245a4
--- /dev/null
+++ b/src/vec.zig
@@ -0,0 +1,25 @@
+pub const vec = @Vector(3, f32);
+
+pub fn init(x: f32, y: f32, z: f32) vec {
+ return @Vector(3, f32){ x, y, z };
+}
+
+pub fn scalar(x: f32) vec {
+ return @splat(3, x);
+}
+
+pub fn unit_vector(v: vec) vec {
+ return v / scalar(length(v));
+}
+
+pub fn length_squared(v: vec) f32 {
+ return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
+}
+
+pub fn length(v: vec) f32 {
+ return @sqrt(length_squared(v));
+}
+
+pub fn dot(x: vec, y: vec) f32 {
+ return x[0] * y[0] + x[1] * y[1] + x[2] * y[2];
+}