Module OgamlMath.Matrix2D

Provides easy creation and manipulation of 2D rendering matrices

Optimized operations on 2D (3x3) float matrices

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

Simple Matrices

type t
Type of 3x3 matrices stored in a flat, column-major array
val zero : unit -> t
Zero matrix
val identity : unit -> t
Identity matrix
val translation : Vector2f.t -> t
Builds a translation matrix from a vector
See : OgamlMath.Vector2f
val scaling : Vector2f.t -> t
Builds a scaling matrix from a vector
See : OgamlMath.Vector2f
val rotation : float -> t
Builds a rotation matrix from an angle
val transformation : translation:Vector2f.t -> rotation:float -> scale:Vector2f.t -> origin:Vector2f.t -> t
Efficiently builds a transformation matrix

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 : Vector2f.t -> t -> t
Translates a matrix by a vector. The original matrix is not modified.
See : OgamlMath.Vector2f
val scale : Vector2f.t -> t -> t
Scales a matrix by a vector. The original matrix is not modified.
See : OgamlMath.Vector2f
val rotate : float -> t -> t
Rotates a matrix by an angle. The original matrix is not modified.
val times : t -> Vector2f.t -> Vector2f.t
Computes the (right-)product of a matrix with a column vector
val print : t -> string
Returns a pretty-printed string (not for serialization)

Rendering Matrices Creation

val projection : size:Vector2f.t -> t
Builds an orthographic projection matrix englobing a screen
val iprojection : size:Vector2f.t -> t
Builds the inverse of an orthographic 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.