diff options
author | Nat Lasseter <user@4574.co.uk> | 2024-06-24 16:01:18 +0100 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2024-06-24 16:01:18 +0100 |
commit | b7814d6822d03517fc846b95865965618be7d406 (patch) | |
tree | 2afc2a5de6d3ca82f465f51686d47dc032d2efb4 /ray.go |
Initial Commit, finished Chapter 6
Diffstat (limited to 'ray.go')
-rw-r--r-- | ray.go | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -0,0 +1,26 @@ +package main + +import ( + maths "math" +) + +type Ray struct { + Origin Vec3 + Direction Vec3 +} + +func (r Ray) At(t float64) Vec3 { + return r.Origin.Add(r.Direction.Mul(Splat(t))); +} + +func (r Ray) Colour(world Hittable) Vec3 { + hit := world.Hit(r, Interval{0, maths.Inf(1)}) + if hit.Valid { + return hit.N.Add(Splat(1)).Div(Splat(2)); + } + + unit_dir := r.Direction.Unit(); + a := (unit_dir.Y + 1) / 2; + return Vec3{0.5, 0.7, 1.0}.Mul(Splat(a)). + Add(Splat(1).Mul(Splat(1.0 - a))); +} |