package gg

  1. Overview
  2. Docs

Module Gg.M4Source

4D square matrices.

Sourcetype t = m4

The type for 4D square matrices.

Sourceval dim : int

dim is the dimension of rows and columns.

Sourcetype v = v4

The type for rows and columns as vectors.

Constructors, accessors and constants

Sourceval v : float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> m4

v e00 e01 e02 e03 e10 e11 e12 e13 e20 e21 e22 e23 e30 e31 e32 e33 is a matrix whose components are specified in row-major order

Sourceval of_rows : v4 -> v4 -> v4 -> v4 -> m4

of_rows r0 r1 r2 r3 is the matrix whose rows are r0, r1, r2 and r3.

Sourceval of_cols : v4 -> v4 -> v4 -> v4 -> m4

of_cols c0 c1 c2 c3 is the matrix whose columns are c0, c1, c2 and c3.

Sourceval el : int -> int -> m4 -> float

el i j a is the element aij. See also the direct element accessors.

Raises Invalid_argument if i or j is not in [0;dim[.

Sourceval row : int -> m4 -> v

row i a is the ith row of a.

Raises Invalid_argument if i is not in [0;dim[.

Sourceval col : int -> m4 -> v

col j a is the jth column of a.

Raises Invalid_argument if j is not in [0;dim[.

Sourceval zero : m4

zero is the neutral element for add.

Sourceval id : m4

id is the identity matrix, the neutral element for mul.

Sourceval of_m3_v3 : m3 -> v3 -> m4

of_m3_v3 m v is the matrix whose first three rows are those of m,v side by side and the fourth is 0 0 0 1.

Sourceval of_quat : quat -> m4

to_quat q is the rotation of the unit quaternion q as 4D matrix.

Functions

Sourceval neg : m4 -> m4

neg a is the negated matrix -a.

Sourceval add : m4 -> m4 -> m4

add a b is the matrix addition a + b.

Sourceval sub : m4 -> m4 -> m4

sub a b is the matrix subtraction a - b.

Sourceval mul : m4 -> m4 -> m4

mul a b is the matrix multiplication a * b.

Sourceval emul : m4 -> m4 -> m4

emul a b is the element wise multiplication of a and b.

Sourceval ediv : m4 -> m4 -> m4

ediv a b is the element wise division of a and b.

Sourceval smul : float -> m4 -> m4

smul s a is a's elements multiplied by the scalar s.

Sourceval transpose : m4 -> m4

transpose a is the transpose aT.

Sourceval trace : m4 -> float

trace a is the matrix trace trace(a).

Sourceval det : m4 -> float

det a is the determinant |a|.

Sourceval inv : m4 -> m4

inv a is the inverse matrix a-1.

2D space transformations

Sourceval move2 : v2 -> m4
Sourceval rot2 : ?pt:p2 -> float -> m4

See M3.rot2.

Sourceval scale2 : v2 -> m4
Sourceval rigid2 : move:v2 -> rot:float -> m4
Sourceval srigid2 : move:v2 -> rot:float -> scale:v2 -> m4

3D space transformations

Sourceval move3 : v3 -> m4

move d translates 3D space in the x, y and z dimensions according to d.

Sourceval rot3_map : v3 -> v3 -> m4
Sourceval rot3_axis : v3 -> float -> m4
Sourceval rot3_zyx : v3 -> m4
Sourceval scale3 : v3 -> m4
Sourceval rigid3 : move:v3 -> rot:(v3 * float) -> m4

rigid3 move rot is the rigid body transformation of 3D space that rotates by the axis/radian angle rot and then translates by move.

Sourceval rigid3q : move:v3 -> rot:quat -> m4

rigid3q move rot is the rigid body transformation of 3D space that rotates by the quaternion rot and then translates by move.

Sourceval srigid3 : move:v3 -> rot:(v3 * float) -> scale:v3 -> m4

srigid3 scale move rot scale is like rigid3 but starts by scaling according to scale.

Sourceval srigid3q : move:v3 -> rot:quat -> scale:v3 -> m4

srigid3q move rot scale is like rigid3q but starts by scaling according to scale.

3D space projections

Projection matrices assume a right-handed coordinate system with the eye at the origin looking down the z-axis.

Sourceval ortho : left:float -> right:float -> bot:float -> top:float -> near:float -> far:float -> m4

ortho left right bot top near far maps 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).

Sourceval persp : left:float -> right:float -> bot:float -> top:float -> near:float -> far:float -> m4

persp left right bot top near far maps 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 -far to the axis aligned cube with corners (-1, -1, -1) and (1,1,1).

4D space transformations

Sourceval scale4 : v4 -> m4

scale4 s scales 4D space in the x, y, z and w dimensions according to s.

Traversal

Sourceval map : (float -> float) -> m4 -> m4

map f a is the element wise application of f to a.

Sourceval mapi : (int -> int -> float -> float) -> m4 -> m4

mapi f a is like map but the element indices are also given.

Sourceval fold : ('a -> float -> 'a) -> 'a -> m4 -> 'a

fold f acc a is f (...(f (f acc a00) a10)...).

Sourceval foldi : ('a -> int -> int -> float -> 'a) -> 'a -> m4 -> 'a

foldi f acc a is f (...(f (f acc 0 0 a00) 1 0 a10)...).

Sourceval iter : (float -> unit) -> m4 -> unit

iter f a is f a00; f a10; ...

Sourceval iteri : (int -> int -> float -> unit) -> m4 -> unit

iteri f a is f 0 0 a00; f 1 0 a10; ...

Predicates and comparisons

Sourceval for_all : (float -> bool) -> m4 -> bool

for_all p a is p a00 && p a10 && ...

Sourceval exists : (float -> bool) -> m4 -> bool

exists p a is p a00 || p a10 || ...

Sourceval equal : m4 -> m4 -> bool

equal a b is a = b.

Sourceval equal_f : (float -> float -> bool) -> m4 -> m4 -> bool

equal_f eq a b tests a and b like equal but uses eq to test floating point values.

Sourceval compare : m4 -> m4 -> int

compare a b is Stdlib.compare a b. That is lexicographic comparison in column-major order.

Sourceval compare_f : (float -> float -> int) -> m4 -> m4 -> int

compare_f cmp a b compares a and b like compare but uses cmp to compare floating point values.

Formatters

Sourceval pp : Format.formatter -> m4 -> unit

pp ppf a prints a textual representation of a on ppf.

Sourceval pp_f : (Format.formatter -> float -> unit) -> Format.formatter -> m4 -> unit

pp_f pp_e ppf a prints a like pp but uses pp_e to print floating point values.

Element accessors

Sourceval e00 : m4 -> float
Sourceval e01 : m4 -> float
Sourceval e02 : m4 -> float
Sourceval e03 : m4 -> float
Sourceval e10 : m4 -> float
Sourceval e11 : m4 -> float
Sourceval e12 : m4 -> float
Sourceval e13 : m4 -> float
Sourceval e20 : m4 -> float
Sourceval e21 : m4 -> float
Sourceval e22 : m4 -> float
Sourceval e23 : m4 -> float
Sourceval e30 : m4 -> float
Sourceval e31 : m4 -> float
Sourceval e32 : m4 -> float
Sourceval e33 : m4 -> float