Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

# Math Matrix Functions

## mat4cubeTransform(int face)

Returns cube viewing matrix for the given cube face.

### Arguments

• int face - Cube face number.

### Return value

Cube viewing matrix.

## mat4frustum(float left, float right, float bottom, float top, float znear, float zfar)

Returns perspective projection matrix:
 2.0 * znear / (right - left) 0.0 (right + left) / (right - left) 0.0 0.0 2.0 * znear / (top - bottom) (top + bottom) / (top - bottom) 0.0 0.0 0.0 -(zfar + znear) / (zfar - znear) -2.0 * zfar * znear / (zfar - znear) 0.0 0.0 -1.0 0.0

Coordinates of top, left, right, bottom are set relatively to center point of the znear plane.

There are two different points (A and B) on the picture above. Since the top, left, right, bottom are coordinates relatively to the center point of the znear plane, coordinates of the A point should be A(left, bottom, znear). Coordinates of the B point are B(k * left, k * bottom, zfar), where k = zfar/znear.

### Arguments

• float left - Left coordinate of the near clipping plane relatively to the center.
• float right - Right coordinate of the near clipping plane relatively to the center.
• float bottom - Bottom coordinate of the near clipping plane relatively to the center.
• float top - Top coordinate of the near clipping plane relatively to the center.
• float znear - Distance to the near depth clipping plane.
• float zfar - Distance to the farther depth clipping plane.

### Return value

Perspective projection matrix.

## mat4inverse4(const mat4 & m)

Return inverse of 3x4 matrix.

### Arguments

• const mat4 & m - The value of the matrix.

### Return value

The resulting matrix.

## dmat4inverse(const dmat4 & m)

Return inverse matrix.

### Arguments

• const dmat4 & m - The value of the first matrix.

### Return value

The resulting matrix.

## mat4inverse(const mat4 & m)

Return inverse of 4x4 matrix.

### Arguments

• const mat4 & m - The value of the matrix.

### Return value

The resulting matrix.

## mat4lookAt(const vec3 & position, const vec3 & direction, const vec3 & up)

Return viewing matrix.

### Arguments

• const vec3 & position - Position coordinates of the target point.
• const vec3 & direction - Direction of the vector.
• const vec3 & up - Direction of the up vector.

### Return value

The viewing matrix.

## dmat4lookAt(const dvec3 & position, const dvec3 & direction, const vec3 & up)

Return viewing matrix.

### Arguments

• const dvec3 & position - Position coordinates of the target point.
• const dvec3 & direction - Direction of the vector.
• const vec3 & up - Direction of the up vector.

### Return value

The viewing matrix.

## mat4obliqueProjection(const mat4 & projection, const vec4 & plane)

Return oblique projection matrix.

### Arguments

• const mat4 & projection - Projection matrix.
• const vec4 & plane - Clipping plane.

### Return value

The oblique projection matrix.

## quatorthoTangent(const vec4 & tangent, const vec3 & normal)

Creates the ortho triangle tangent space basis.

### Arguments

• const vec4 & tangent - Tangent vector.
• const vec3 & normal - Normal vector.

### Return value

The tangent basis.

## quatorthoTangent(const vec3 & tangent, const vec3 & binormal, const vec3 & normal)

Creates the ortho triangle tangent space basis.

### Arguments

• const vec3 & tangent - Tangent vector.
• const vec3 & binormal - Binormal vector.
• const vec3 & normal - Normal vector.

### Return value

The tangent basis.

## mat4perspective(float fov, float aspect, float znear, float zfar)

Returns perspective projection matrix.

### Arguments

• float fov - Field of view angle.
• float aspect - Aspect ratio. The aspect ratio is the ratio of width to height.
• float znear - Nearest depth clipping plane.
• float zfar - Farther depth clipping plane.

### Return value

Perspective projection matrix.

## mat4reflect(const vec4 & plane)

Return reflection matrix.

### Arguments

• const vec4 & plane - Reflection plane.

### Return value

The reflection matrix.

## dmat4reflect(const dvec4 & plane)

Return reflection matrix.

### Arguments

• const dvec4 & plane - Reflection plane.

### Return value

The reflection matrix.

## mat4rotateX(float angle)

Returns matrix of rotation at the given angle around X axis:
 1 0.0 0.0 0 0 cos -sin 0 0 sin cos 0 0 0.0 0.0 1

### Arguments

• float angle - Rotation angle, degrees.

Rotation matrix.

## dmat4rotateX(double angle)

Return X rotation matrix.

### Arguments

• double angle - Rotation angle (in degrees).

### Return value

The resulting matrix.

## mat4rotateY(float angle)

Returns matrix of rotation at the given angle around Y axis:
 cos 0 sin 0 0.0 1 0.0 0 -sin 0 cos 0 0.0 0 0.0 1

### Arguments

• float angle - Rotation angle, degrees.

Rotation matrix.

## dmat4rotateY(double angle)

Return Y rotation matrix.

### Arguments

• double angle - Rotation angle (in degrees).

### Return value

The resulting matrix.

## mat4rotateZ(float angle)

Returns matrix of rotation at the given angle around Z axis:
 cos -sin 0 0 sin cos 0 0 0.0 0.0 1 0 0.0 0.0 0 1

### Arguments

• float angle - Rotation angle, degrees.

Rotation matrix.

## dmat4rotateZ(double angle)

Return Z rotation matrix.

### Arguments

• double angle - Rotation angle (in degrees).

### Return value

The resulting matrix.

## mat4rotate(const vec3 & axis, float angle)

Return rotation matrix.

### Arguments

• const vec3 & axis - Rotation axis.
• float angle - Rotation angle (in degrees).

### Return value

The resulting matrix.

## dmat4rotate(const dvec3 & axis, double angle)

Return rotation matrix.

### Arguments

• const dvec3 & axis - Rotation axis.
• double angle - Rotation angle (in degrees).

### Return value

The resulting matrix.

## mat4rotation(const mat4 & m)

Return rotation matrix.

### Arguments

• const mat4 & m - The value of the matrix.

### Return value

The resulting matrix.

## mat4scale(const vec3 & v)

Return scaling matrix.

### Arguments

• const vec3 & v - The value of the scaling vector.

### Return value

The resulting matrix.

## dmat4scale(const dvec3 & v)

Return scaling matrix.

### Arguments

• const dvec3 & v - The value of the scaling vector.

### Return value

The resulting matrix.

## dmat4setTo(const dvec3 & position, const dvec3 & direction, const vec3 & up)

Return placing matrix.

### Arguments

• const dvec3 & position - Position coordinates of the target point.
• const dvec3 & direction - Direction of the vector.
• const vec3 & up - Direction of the up vector.

### Return value

The placing matrix.

## mat4setTo(const vec3 & position, const vec3 & direction, const vec3 & up)

Return placing matrix.

### Arguments

• const vec3 & position - Position coordinates of the target point.
• const vec3 & direction - Direction of the vector.
• const vec3 & up - Direction of the up vector.

### Return value

The placing matrix.

## mat4symmetryProjection(const mat4 & projection)

Return symmetry projection matrix.

### Arguments

• const mat4 & projection - Projection matrix.

### Return value

The symmetry projection matrix.

## mat4translate(const vec3 & v)

Return translation matrix.

### Arguments

• const vec3 & v - The value of the translation vector.

### Return value

The resulting matrix.

## dmat4translate(const dvec3 & v)

Return translation matrix.

### Arguments

• const dvec3 & v - The value of the translation vector.

### Return value

The resulting matrix.

## mat4transpose3(const mat4 & m)

Return transposed rotation matrix.

### Arguments

• const mat4 & m - The value of the matrix.

### Return value

The resulting matrix.

## mat4transpose(const mat4 & m)

Return transpose matrix.

### Arguments

• const mat4 & m - The value of the matrix.

### Return value

The resulting matrix.
Last update: 2017-07-03