mirror of
https://github.com/Smaug123/ray-tracing-fsharp
synced 2025-10-07 04:48:45 +00:00
66 lines
2.1 KiB
Forth
66 lines
2.1 KiB
Forth
namespace RayTracing
|
|
|
|
type Camera<'a> =
|
|
{
|
|
Num : Num<'a>
|
|
/// How tall is our viewport?
|
|
ViewportHeight : 'a
|
|
/// How wide is our viewport?
|
|
ViewportWidth : 'a
|
|
/// In which direction is the camera pointing?
|
|
View : Ray<'a>
|
|
/// What is the orientation of the imaginary plane
|
|
/// onto which we're collecting the pixels of the result?
|
|
/// This is normal to View and to ViewportYAxis, and its
|
|
/// origin is at distance FocalLength from View.Origin.
|
|
ViewportXAxis : Ray<'a>
|
|
/// What is the orientation of the imaginary plane
|
|
/// onto which we're collecting the pixels of the result?
|
|
/// This is normal to View and to ViewportXAxis, and its
|
|
/// origin is at distance FocalLength from View.Origin.
|
|
ViewportYAxis : Ray<'a>
|
|
/// How far away from the camera is the imaginary plane
|
|
/// onto which we're collecting the pixels of the result?
|
|
FocalLength : 'a
|
|
/// How many samples will we take per pixel, for anti-aliasing?
|
|
SamplesPerPixel : int
|
|
}
|
|
|
|
[<RequireQualifiedAccess>]
|
|
module Camera =
|
|
let makeBasic<'a>
|
|
(n : Num<'a>)
|
|
(focalLength : 'a)
|
|
(aspectRatio : 'a)
|
|
(origin : Point<'a>)
|
|
: Camera<'a>
|
|
=
|
|
let height = n.Double n.One
|
|
let view =
|
|
{
|
|
Origin = origin
|
|
Vector = Vector [| n.Zero ; n.Zero ; n.One |]
|
|
}
|
|
let xAxis =
|
|
{
|
|
Origin = origin
|
|
Vector = Vector [| n.One ; n.Zero ; n.Zero |]
|
|
}
|
|
let yAxis =
|
|
{
|
|
Origin = origin
|
|
Vector = Vector [| n.Zero ; n.One ; n.Zero |]
|
|
}
|
|
|
|
{
|
|
Num = n
|
|
FocalLength = focalLength
|
|
ViewportHeight = height
|
|
ViewportWidth = n.Times aspectRatio height
|
|
View = view
|
|
ViewportXAxis =
|
|
Ray.parallelTo (Ray.walkAlong n view focalLength) xAxis
|
|
ViewportYAxis =
|
|
Ray.parallelTo (Ray.walkAlong n view focalLength) yAxis
|
|
SamplesPerPixel = 10
|
|
} |