bounce rays around

This commit is contained in:
Fabien Freling 2021-05-10 23:30:34 +02:00
parent a3df9a7707
commit 58f710c967
3 changed files with 42 additions and 8 deletions

View file

@ -1,4 +1,7 @@
const math = @import("std").math;
const std = @import("std");
const print = std.debug.print;
const math = std.math;
const Random = std.rand.Random;
pub const Vec3 = packed struct {
x: f32 = 0.0,
@ -66,6 +69,24 @@ pub fn unitVector(vec: Vec3) Vec3 {
return vec.div(vec.length());
}
pub fn random(rng: *Random, min: f32, max: f32) Vec3 {
const range = max - min;
return Vec3{
.x = rng.*.float(f32) * range + min,
.y = rng.*.float(f32) * range + min,
.z = rng.*.float(f32) * range + min,
};
}
pub fn random_in_unit_sphere(rng: *Random) Vec3 {
while (true) {
const v = random(rng, -1, 1);
if (v.length_squared() < 1) {
return v;
}
}
}
pub const Point3 = Vec3;
const assert = @import("std").debug.assert;