From e25ffd24ee2e115d8453644d3670348c3678af67 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Tue, 20 Dec 2022 22:48:27 +0100 Subject: 6.1 --- src/main.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.zig b/src/main.zig index c55bc06..40ac9c7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,7 +2,11 @@ const std = @import("std"); const warn = @import("std").debug.print; pub fn unit_vector(v: vec) vec { - return v / scalar(3); + return v / scalar(length(v)); +} + +pub fn length(v: vec) f32 { + return @sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); } pub fn ray_color(r: ray) vec { -- cgit v1.2.3