Module Lit.View

module View: sig .. end
Views.

A view defines a view volume in 3D space mapped to clipped space.

A view defines the rendered view volume in 3D space and the viewport on which rendering occurs on the renderer's surface.

The view volume is specified by a view transform Lit.View.tr that locates and orients the view volume and a projection transform Lit.View.proj that defines the shape of the volume. Multiplied toghether these transform map world space to clip space.

The view's Lit.View.viewport defines, in normalized surface coordinates, a rectangular area of the surface. The normalized device coordinates are mapped on the viewport.



View


type t = Lit.view 
The type for views.
val create : ?tr:Gg.m4 -> ?proj:Gg.m4 -> ?viewport:Gg.box2 -> unit -> t
create tr proj viewport is a view such that:
val tr : Lit.view -> Gg.m4
val set_tr : Lit.view -> Gg.m4 -> unit
val proj : Lit.view -> Gg.m4
val set_proj : Lit.view -> Gg.m4 -> unit
val viewport : Lit.view -> Gg.box2
val set_viewport : Lit.view -> Gg.box2 -> unit

Coordinate system transforms

TODO explain in detail coordinate systems

val viewport_of_surface : Lit.view -> Gg.p2 -> Gg.p2
viewport_of_surface view pt is the normalized viewport coordinates in view of the normalized surface coordinates pt.
val viewport_of_ndc : Lit.view -> Gg.p2 -> Gg.p2
viewport_of_ndc view pt is the normalized viewport coordinates in view of the normalized device coordinates pt in view.
val surface_of_viewport : Lit.view -> Gg.p2 -> Gg.p2
surface_of_viewport view pt is the normalized surface coordinates of the normalized viewport coordinates pt in view.
val surface_of_ndc : Lit.view -> Gg.p2 -> Gg.p2
surface_of_ndc view pt is the normalized surface coordinates of the normalized device coordinates pt in view.
val ndc_of_viewport : Lit.view -> Gg.p2 -> Gg.p2
ndc_of_viewport view pt is the normalized device coordinates in view of the normalized viewport coordinates pt in view.
val ndc_of_surface : Lit.view -> Gg.p2 -> Gg.p2
ndc_of_surface view pt is the normalized device coordinates of the normalized surface coordinates pt in view.

Projections and view matrices


type fov = [ `H of float | `V of float ] 
The type for field of view angles along horizontal or vertical axes.
val persp : fov:fov -> aspect:float -> near:float -> far:float -> Gg.m4
persp fov aspect near far is a perspective projection matrix such that:

The transform is defined as follows according to fov.

The projection maps the symmetric frustum with top of the underlying pyramid at the origin, near clip rectangle corners (-w/2,-h/2,-near), (w/2,h/2,-near) and far plane at -far to the axis aligned cube with corners (-1, -1, -1) and (1,1,1).
val look : ?up:Gg.v3 -> at:Gg.p3 -> from:Gg.p3 -> unit -> Gg.m4
look up at ~from:pos () in layman terms this is the transform which has the effect of putting you at position pos looking at the point at and with your head tilted to match the up direction.

More precisely, the transform maps:

The final up vector oy' matches exactly up only if up is orthogonal the the forward direction at - from.