mirror of
https://github.com/Smaug123/ray-tracing-fsharp
synced 2025-10-05 11:58:44 +00:00
32 lines
1.1 KiB
Forth
32 lines
1.1 KiB
Forth
namespace RayTracing
|
|
|
|
type Hittable =
|
|
| Sphere of Sphere
|
|
| UnboundedSphere of Sphere
|
|
| InfinitePlane of InfinitePlane
|
|
|
|
member this.Reflection (incoming : LightRay) (strikePoint : Point) =
|
|
match this with
|
|
| Sphere s
|
|
| UnboundedSphere s -> s.Reflection incoming strikePoint
|
|
| InfinitePlane p -> p.Reflection incoming strikePoint
|
|
|
|
member this.BoundingBox : BoundingBox voption =
|
|
match this with
|
|
| Sphere s -> Sphere.boundingBox s |> ValueSome
|
|
| UnboundedSphere _
|
|
| InfinitePlane _ -> ValueNone
|
|
|
|
[<RequireQualifiedAccess>]
|
|
module Hittable =
|
|
|
|
let inline boundingBox (h : Hittable) = h.BoundingBox
|
|
|
|
/// Returns the distance we must walk along this ray before we first hit an object, the
|
|
/// colour the resulting light ray is after the interaction, and the new ray.
|
|
let hits (ray : Ray) (h : Hittable) : float voption =
|
|
match h with
|
|
| UnboundedSphere s
|
|
| Sphere s -> Sphere.firstIntersection s ray
|
|
| InfinitePlane plane -> InfinitePlane.intersection plane ray
|