Module Gg.M4
type t= m4The type for 4D square matrices.
type v= v4The type for rows and columns as vectors.
Constructors, accessors and constants
val v : float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> m4v e00 e01 e02 e03 e10 e11 e12 e13 e20 e21 e22 e23 e30 e31 e32 e33is a matrix whose components are specified in row-major order
val of_rows : v4 -> v4 -> v4 -> v4 -> m4of_rows r0 r1 r2 r3is the matrix whose rows arer0,r1,r2andr3.
val of_cols : v4 -> v4 -> v4 -> v4 -> m4of_cols c0 c1 c2 c3is the matrix whose columns arec0,c1,c2andc3.
val el : int -> int -> m4 -> floatel i j ais the elementaij. See also the direct element accessors.- raises Invalid_argument
if
iorjis not in [0;dim[.
val col : int -> m4 -> vcol j ais thejth column ofa.- raises Invalid_argument
if
jis not in [0;dim[.
Functions
val mul : m4 -> m4 -> m4mul a bis the matrix multiplicationa * b.
val trace : m4 -> floattrace ais the matrix tracetrace(a).
val det : m4 -> floatdet ais the determinant|a|.
val inv : m4 -> m4inv ais the inverse matrixa-1.
2D space transformations
val srigid2 : move:v2 -> rot:float -> scale:v2 -> m4See
M3.srigid2.
3D space transformations
val rot3_map : v3 -> v3 -> m4See
M3.rot3_map.
val rot3_axis : v3 -> float -> m4See
M3.rot3_axis.
val rot3_zyx : v3 -> m4See
M3.rot3_zyx.
val rigid3 : move:v3 -> rot:(v3 * float) -> m4rigid3 move rotis the rigid body transformation of 3D space that rotates by the axis/radian anglerotand then translates bymove.
val rigid3q : move:v3 -> rot:quat -> m4rigid3q move rotis the rigid body transformation of 3D space that rotates by the quaternionrotand then translates bymove.
3D space projections
Projection matrices assume a right-handed coordinate system with the eye at the origin looking down the z-axis.
val ortho : left:float -> right:float -> bot:float -> top:float -> near:float -> far:float -> m4ortho left right bot top near farmaps the axis aligned box with corners(left, bot, -near)and(right, top, -far)to the axis aligned cube with corner(-1, -1, -1)and(1, 1, 1).
val persp : left:float -> right:float -> bot:float -> top:float -> near:float -> far:float -> m4persp left right bot top near farmaps the frustum with top of the underlying pyramid at the origin, near clip rectangle corners(left, bot, -near),(right, top, -near)and far plane at-farto the axis aligned cube with corners(-1, -1, -1)and(1,1,1).
4D space transformations
Traversal
val mapi : (int -> int -> float -> float) -> m4 -> m4mapi f ais likemapbut the element indices are also given.
val fold : ('a -> float -> 'a) -> 'a -> m4 -> 'afold f acc aisf (...(f (f acc a00) a10)...).
val foldi : ('a -> int -> int -> float -> 'a) -> 'a -> m4 -> 'afoldi f acc aisf (...(f (f acc 0 0 a00) 1 0 a10)...).
val iter : (float -> unit) -> m4 -> unititer f aisf a00; f a10;...
val iteri : (int -> int -> float -> unit) -> m4 -> unititeri f aisf 0 0 a00; f 1 0 a10;...
Predicates and comparisons
val for_all : (float -> bool) -> m4 -> boolfor_all p aisp a00&& p a10&&...
val exists : (float -> bool) -> m4 -> boolexists p aisp a00|| p a10||...
val equal_f : (float -> float -> bool) -> m4 -> m4 -> boolequal_f eq a btestsaandblikeequalbut useseqto test floating point values.
Printers
val pp : Stdlib.Format.formatter -> m4 -> unitpp ppf aprints a textual representation ofaonppf.
val pp_f : (Stdlib.Format.formatter -> float -> unit) -> Stdlib.Format.formatter -> m4 -> unitpp_f pp_e ppf aprintsalikeppbut usespp_eto print floating point values.
Element accessors
val e00 : m4 -> floatval e01 : m4 -> floatval e02 : m4 -> floatval e03 : m4 -> floatval e10 : m4 -> floatval e11 : m4 -> floatval e12 : m4 -> floatval e13 : m4 -> floatval e20 : m4 -> floatval e21 : m4 -> floatval e22 : m4 -> floatval e23 : m4 -> floatval e30 : m4 -> floatval e31 : m4 -> floatval e32 : m4 -> floatval e33 : m4 -> float