module View:sig..end
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.
typet =Lit.view
val create : ?tr:Gg.m4 -> ?proj:Gg.m4 -> ?viewport:Gg.box2 -> unit -> tcreate tr proj viewport is a view such that:
tr, defines the location and orientation of the view.
It is the transform that maps world coordinates to view
coordinates. Defaults to M4.id, i.e. we are at the origin
looking at down the z-axis. It defines the builtin uniform
value Lit.Uniform.world_to_view.proj, defines the viewing volume. It is the transform
that maps view coordinates to clip space. Defaults to
Lit.View.persp(`H Float.pi_div_4) 1.5 1. 100.. It defines the
builtin uniform value Lit.Uniform.view_to_clip.viewport a rectangular area in normalized screen
coordinates of the renderer's viewport; default is
Box2.unit. It defines the builtin uniform values
Lit.Uniform.viewport_o and Lit.Uniform.viewport_size.
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
TODO explain in detail coordinate systems
val viewport_of_surface : Lit.view -> Gg.p2 -> Gg.p2viewport_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.p2viewport_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.p2surface_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.p2surface_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.p2ndc_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.p2ndc_of_surface view pt is the normalized device coordinates
of the normalized surface coordinates pt in view.typefov =[ `H of float | `V of float ]
val persp : fov:fov -> aspect:float -> near:float -> far:float -> Gg.m4persp fov aspect near far is a perspective projection matrix
such that:
fov is the field of view angle in radians along a given
axis.aspect is the ratio between the horizontal field of view
and the vertical field of view.near and far are positive distances to the near and
far clip planes.
The transform is defined as follows according to fov.
fov = `V fovy, then let h = 2 * near * (tan (fovy / 2))
and w = aspect * h.fov = `H fovx, then let h = w / aspec and
w = 2 * near * (tan (fovx / 2))(-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.m4look 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:
pos on the origin P3.ooz' = V3.(unit (from - at)) to V3.ozox' = V3.(unit (cross up oz')) to V3.oxoy' = V3.(unit (cross oz ox')) to V3.oyoy' matches exactly up only if up
is orthogonal the the forward direction at - from.