March Docs

Arcade.Camera

Types

typePosePose = { eye : Vec3, target : Vec3, up : Vec3 }#

Where the camera stands, what it looks at, and which way is up. up only has to be off the line of sight; the basis squares it up.

typeLensLens = Perspective(Float) | Orthographic(Float)#

How the camera sees. Perspective takes the vertical field of view in degrees; Orthographic takes the visible height in world units at every depth (a top-down 2D game uses this one).

typeRigRig = { pose : Pose, lens : Lens }#

A pose seen through a lens.

typeViewportViewport = { width : { Float | _ > 0.0 }, height : { Float | _ > 0.0 } }#

The drawing surface, in CSS pixels.

typeProjectionProjection = {#

A rig ready to project onto one viewport: its basis, worked out once. half is tan(fov / 2) for a perspective lens and half the visible height for an orthographic one: either way the camera-space rise that reaches the top edge is half per unit of depth (perspective) or half (ortho).

typeSeenSeen = { across : Float, rise : Float, depth : Float }#

A point in camera space: across, up, and depth along the view.

Functions

fnfraction_of_seenfraction_of_seen(n : Arcade.Numerics.Numerics, l : Projection, s : Seen) : Arcade.Vec2.Vec2 needs ()#
fnhalf_ofhalf_of(n : Arcade.Numerics.Numerics, lens : Lens) : Float needs ()#

fn tan_half(n : Arcade.Numerics.Numerics, fov : Float) : Float needs () do Math.tan(fov *. n.pi /. 360.0) end

fnjoltedjolted(p : Pose, offset : Vec3) : Pose needs ()#

fn shake_jolt_at(amplitude : Float, clock : Float, x_rate : Float, y_rate : Float) : Vec3 needs () do vec3(Math.sin(clock . x_rate) . amplitude, Math.cos(clock . y_rate) . amplitude, 0.0) end

fnlean_steplean_step(cur : Float, want : Float, dt : Float, rise_rate : Float, fall_rate : Float) : Float needs ()#
fnlean_towardlean_toward(p : Pose, focus : Vec3, eye_share : Float, target_share : Float) : Pose needs ()#

A pose leaned toward a focus point: the eye moves eye_share of the way there and the target target_share of the way. Up is kept.

fnpixel_of_seenpixel_of_seen(n : Arcade.Numerics.Numerics, l : Projection, s : Seen) : Arcade.Vec2.Vec2 needs ()#

fn fraction(n : Arcade.Numerics.Numerics, l : Projection, p : Vec3) : Arcade.Vec2.Vec2 needs () do fraction_of_seen(n, l, seen(l, p)) end

fnpixels_per_metrepixels_per_metre(l : Projection, depth : Float) : Float needs ()#
fnposepose(eye : Vec3, target : Vec3) : Pose needs ()#

fn world_up() : Vec3 needs () do vec3(0.0, 1.0, 0.0) end

fnprojectionprojection(n : Arcade.Numerics.Numerics, rig : Rig, v : Viewport) : Projection needs ()#

fn basis(p : Pose) : (Vec3, Vec3, Vec3) needs () do let f = normalized(sub(p.target, p.eye)) let r = normalized(cross(f, p.up)) (f, r, cross(r, f)) end

fnrayray(l : Projection, f : Arcade.Vec2.Vec2) : (Vec3, Vec3) needs ()#

The ray through a screen position (fractions, y down): origin and unit direction. Perspective rays leave the eye; orthographic rays leave the point on the eye's plane under that position, all along forward.

fnray_planeray_plane(origin : Vec3, dir : Vec3, point : Vec3, normal : Vec3) : Option(Vec3) needs ()#

Where a ray meets the plane through point with normal normal, in front of the origin. None when the ray runs within 0.00001 of parallel or the plane is behind it.

fnshake_joltshake_jolt(amplitude : Float, clock : Float) : Vec3 needs ()#

A shake offset at a clock time: sin and cos of the clock at 71 and 53 radians per second on world x and y, amplitude world units.

fnviewportviewport(width : Float, height : Float) : Viewport needs ()#

fn aspect(v : Viewport) : Float needs () do v.width /. v.height end