libgpac
Documentation of the core library of GPAC
Matrix Interface Reference

import"evg.idl";

+ Collaboration diagram for Matrix:

Public Member Functions

Matrix copy (Matrix from)
 
boolean equal (Matrix other)
 
Matrix translate (float x, float y, float z)
 
Matrix translate (Vec3f v)
 
Matrix scale (float x, float y, float z)
 
Matrix scale (Vec3f v)
 
Matrix rotate (float x, float y, float z, float angle)
 
Matrix rotate (Vec4f v)
 
Matrix add (Matrix mul, optional boolean do_4x4=false)
 
Matrix inverse (optional boolean do_4x4=false)
 
Matrix transpose ()
 
Matrix ortho (float left, float right, float bottom, float top, float z_near, float z_far)
 
Matrix perspective (float fov, float aspect_ratio, float z_near, float z_far)
 
Matrix lookat (Vec3f position, Vec3f target, Vec3f up_vector)
 
Rectf apply (Rectf rc)
 
Vec4f apply (Vec4f v)
 
Vec3f apply (Vec3f v)
 

Data Fields

attribute boolean identity
 
attribute const boolean is3D = true
 
attribute Array< float > m
 
attribute readonly float yaw
 
attribute readonly float pitch
 
attribute readonly float roll
 
attribute readonly Vec3f dec_translate
 
attribute readonly Vec3f dec_scale
 
attribute readonly Vec4f dec_rotate
 
attribute readonly Vec3f dec_shear
 

Detailed Description

Matrix 4x4 object.

The Matrix object can be imported using:

import {Matrix} from 'webgl'
...
Definition: evg.idl:1261

Most transformation values return the matrix object so that transformations can be chained:

let mat = new Matrix().scale(1, 1, 2).translate(0, -10, 5);
Matrix scale(float x, float y, float z)
Matrix translate(float x, float y, float z)

All objects (Vec3f, Vec4f, Rectf) used in the API do not use constructors, their type is inferred if the expected attributes (eg x y, ...) are present in the object

let res = mat.apply({x:0,y: 0, z:10});
print(`transformed ${res.x} ${res.y} ${res.z});`
void print(DOMString log)

Member Function Documentation

◆ copy()

Matrix Matrix::copy ( Matrix  from)

copies matrix

Parameters
frommatrix to copy coeficient from
Returns
the matrix object

◆ equal()

boolean Matrix::equal ( Matrix  other)

check matrices are equal

Parameters
othermatrix to compare with
Returns
true if same matrices

◆ translate() [1/2]

Matrix Matrix::translate ( float  x,
float  y,
float  z 
)

translate a matrix

Parameters
xX translation value
yY translation value
zZ translation value
Returns
the matrix object

◆ translate() [2/2]

Matrix Matrix::translate ( Vec3f  v)

translate a matrix

Parameters
vtranslation vector
Returns
the matrix object

◆ scale() [1/2]

Matrix Matrix::scale ( float  x,
float  y,
float  z 
)

scale a matrix

Parameters
xX scale value
yY scale value
zZ scale value
Returns
the matrix object

◆ scale() [2/2]

Matrix Matrix::scale ( Vec3f  v)

scale a matrix

Parameters
vscale vector
Returns
the matrix object

◆ rotate() [1/2]

Matrix Matrix::rotate ( float  x,
float  y,
float  z,
float  angle 
)

rotate a matrix

Parameters
xX value of rotation axis vector
yY value of rotation axis vector
zZ value of rotation axis vector
anglerotation angle in radians
Returns
the matrix object

◆ rotate() [2/2]

Matrix Matrix::rotate ( Vec4f  v)

scale a matrix

Parameters
vrotation vector+angle
Returns
the matrix object

◆ add()

Matrix Matrix::add ( Matrix  mul,
optional boolean  do_4x4 = false 
)

multiplies with another matrix (mx = mx * mul)

Parameters
multhe matrix
do_4x4if true, performs full multiplication on each row/col, otherwise handles last row as 0 0 0 1
Returns
the matrix object

◆ inverse()

Matrix Matrix::inverse ( optional boolean  do_4x4 = false)

inverse the matrix

Parameters
do_4x4if true, performs full inversion on each row/col, otherwise handles last row as 0 0 0 1
Returns
the matrix object

◆ transpose()

Matrix Matrix::transpose ( )

transposes the matrix

Returns
the matrix object

◆ ortho()

Matrix Matrix::ortho ( float  left,
float  right,
float  bottom,
float  top,
float  z_near,
float  z_far 
)

Loads an orthogonal projection matrix

Parameters
leftmin horizontal coordinate of viewport
rightmax horizontal coordinate of viewport
bottommin vertical coordinate of viewport
topmax vertical coordinate of viewport
z_nearmin depth coordinate of viewport
z_farmax depth coordinate of viewport
Returns
the matrix object

◆ perspective()

Matrix Matrix::perspective ( float  fov,
float  aspect_ratio,
float  z_near,
float  z_far 
)

loads a perspective projection matrix

Parameters
fovcamera field of view angle in radian
aspect_ratioviewport aspect ratio
z_nearmin depth coordinate of viewport
z_farmax depth coordinate of viewport
Returns
the matrix object

◆ lookat()

Matrix Matrix::lookat ( Vec3f  position,
Vec3f  target,
Vec3f  up_vector 
)

loads a lookat matrix

Parameters
positionposition
targetlook direction
up_vectorvector describing the up direction
Returns
the matrix object

◆ apply() [1/3]

Rectf Matrix::apply ( Rectf  rc)

transforms a rectangle

Parameters
rcthe rectangle to transform
Returns
the transformed rectangle

◆ apply() [2/3]

Vec4f Matrix::apply ( Vec4f  v)

transforms a 4D vector

Parameters
vthe 4D vector to transform
Returns
the transformed 4D vector

◆ apply() [3/3]

Vec3f Matrix::apply ( Vec3f  v)

transforms a 3D vector

Parameters
vthe 3D vector to transform
Returns
the transformed 3D vector

Field Documentation

◆ identity

attribute boolean Matrix::identity

indicates if matrix is identity. If set to true, resets matrix

◆ is3D

attribute const boolean Matrix::is3D = true

indicates matrix is a 3D matrix

◆ m

attribute Array<float> Matrix::m

float buffer of coeficients (typically use matrix.m to pass matrices uniforms)

◆ yaw

attribute readonly float Matrix::yaw

yaw value of matrix

◆ pitch

attribute readonly float Matrix::pitch

pitch value of matrix

◆ roll

attribute readonly float Matrix::roll

roll value of matrix

◆ dec_translate

attribute readonly Vec3f Matrix::dec_translate

translation value of decomposed matrix

◆ dec_scale

attribute readonly Vec3f Matrix::dec_scale

scale value of decomposed matrix

◆ dec_rotate

attribute readonly Vec4f Matrix::dec_rotate

rotation value of decomposed matrix

◆ dec_shear

attribute readonly Vec3f Matrix::dec_shear

shear value of decomposed matrix