diff options
Diffstat (limited to 'hitable.go')
| -rw-r--r-- | hitable.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/hitable.go b/hitable.go new file mode 100644 index 0000000..a44026d --- /dev/null +++ b/hitable.go @@ -0,0 +1,19 @@ +package main + +type Hitable interface { + Hit(ray Ray) bool +} + +type Sphere struct { + center Vec3D + radius float64 +} + +func (sphere Sphere) Hit(ray Ray) bool { + oc := SubVec3D(ray.origin, sphere.center) + a := DotProduct(ray.direction, ray.direction) + b := 2.0 * DotProduct(oc, ray.direction) + c := DotProduct(oc, oc) - sphere.radius*sphere.radius + discriminant := b*b - 4*a*c + return discriminant > 0 +} |
