Module OgamlMath.Matrix3D

Provides easy creation and manipulation of rendering matrices

Optimized operations on 3D (4x4) float matrices

exception Matrix3D_exception of string
Raised when an error occurs (usually a division by zero)

Simple Matrices

type t
Type of 4x4 matrices stored in a flat, column-major array
val zero : unit -> t
Zero matrix
val identity : unit -> t
Identity matrix
val translation : Vector3f.t -> t
Builds a translation matrix from a vector
See : OgamlMath.Vector3f
val scaling : Vector3f.t -> t
Builds a scaling matrix from a vector
See : OgamlMath.Vector3f
val rotation : Vector3f.t -> float -> t
Builds a rotation matrix from an axis and an angle
See : OgamlMath.Vector3f
val from_quaternion : Quaternion.t -> t
Builds a rotation matrix from a quaternion
See : OgamlMath.Quaternion

Matrix Operations

val product : t -> t -> t
Computes the product of two matrices
val transpose : t -> t
Transposes a matrix. The original is not modified.
val translate : Vector3f.t -> t -> t
Translates a matrix by a vector. The original matrix is not modified.
See : OgamlMath.Vector3f
val scale : Vector3f.t -> t -> t
Scales a matrix by a vector. The original matrix is not modified.
See : OgamlMath.Vector3f
val rotate : Vector3f.t -> float -> t -> t
Rotates a matrix by an angle around a given axis. The original matrix is not modified.
See : OgamlMath.Vector3f
val times : t -> Vector3f.t -> Vector3f.t
Computes the (right-)product of a matrix with a column vector
See : OgamlMath.Vector3f
val print : t -> string
Returns a pretty-printed string (not for serialization)

Rendering Matrices Creation

val look_at : from:Vector3f.t -> at:Vector3f.t -> up:Vector3f.t -> t
Builds a "look-at" view matrix. Raises Matrix3D_exception if up = zero .
See : OgamlMath.Vector3f
val ilook_at : from:Vector3f.t -> at:Vector3f.t -> up:Vector3f.t -> t
Builds the inverse of a "look-at" view matrix. Raises Matrix3D_exception if up = zero .
See : OgamlMath.Vector3f
val look_at_eulerian : from:Vector3f.t -> theta:float -> phi:float -> t
Builds a "look-at" view matrix from eulerian angles. Theta should be in [0;2pi] and phi in [-pi/2;pi/2]. If phi = pi/2, the camera is looking up (towards positive Y). If theta = 0, the camera is looking towards negative Z.
See : OgamlMath.Vector3f
val ilook_at_eulerian : from:Vector3f.t -> theta:float -> phi:float -> t
Builds the inverse of a "look-at" view matrix from eulerian angles. Theta should be in [0;2pi] and phi in [-pi/2;pi/2].
See : OgamlMath.Vector3f
val orthographic : right:float -> left:float -> near:float -> far:float -> top:float -> bottom:float -> t
Builds an orthographic projection matrix englobing a volume defined by six planes. Raises Matrix3D_exception if right = left or near = far or top = bottom
val iorthographic : right:float -> left:float -> near:float -> far:float -> top:float -> bottom:float -> t
Builds the inverse of an orthographic projection matrix
val perspective : near:float -> far:float -> width:float -> height:float -> fov:float -> t
Builds a perspective projection matrix. Near and far are the positions of the clipping planes relatively to the camera position (nothing will be rendered outside those planes). Width and height should usually be the dimensions of the screen in pixels. Fov corresponds to the view angle, and is given in radians.
Raises Matrix3D_exception if near = far .
val iperspective : near:float -> far:float -> width:float -> height:float -> fov:float -> t
Builds the inverse of a perspective projection matrix

Other functions

val to_bigarray : t -> (float, Bigarray.float32_elt, Bigarray.c_layout) Bigarray.Array1.t
Returns a matrix as a flat bigarray. Used internally by OGAML, it should not be necessary for your programs.