A high-performance static matrix math library used to calculate affine transforms on surfaces and other renderables. Famo.us uses 4x4 matrices corresponding directly to WebKit matrices (column-major order). The internal "type" of a Matrix is a 16-long float array in row-major order, with: elements [0],[1],[2],[4],[5],[6],[8],[9],[10] forming the 3x3 transformation matrix; elements [12], [13], [14] corresponding to the t_x, t_y, t_z translation; elements [3], [7], [11] set to 0; element [15] set to 1. All methods are static.
Multiply two or more Transform matrix types to return a Transform matrix.
Parameters
a
Transform
left Transform
b
Transform
right Transform
Returns
Transform
multiply(a, b)Static
Fast-multiply two Transform matrix types to return a Matrix, assuming bottom row on each is [0 0 0 1].
Parameters
a
Transform
left Transform
b
Transform
right Transform
Returns
Transform
thenMove(m, t)Static
Return a Transform translated by additional amounts in each dimension. This is equivalent to the result of Transform.multiply(Matrix.translate(t[0], t[1], t[2]), m).
Parameters
m
Transform
a Transform
t
Array.Number
floats delta vector of length 2 or 3
Returns
Transform
moveThen(v, m)Static
Return a Transform matrix which represents the result of a transform matrix applied after a move. This is faster than the equivalent multiply. This is equivalent to the result of: Transform.multiply(m, Transform.translate(t[0], t[1], t[2])).
Parameters
v
Array.Number
vector representing initial movement
m
Transform
matrix to apply afterwards
Returns
Transform
the resulting matrix
translate(x, y, z)Static
Return a Transform which represents a translation by specified amounts in each dimension.
Parameters
x
Number
x translation
y
Number
y translation
z
Number
z translation
Returns
Transform
thenScale(m, s)Static
Return a Transform scaled by a vector in each dimension. This is a more performant equivalent to the result of Transform.multiply(Transform.scale(s[0], s[1], s[2]), m).
Parameters
m
Transform
a matrix
s
Array.Number
delta vector (array of floats && array.length == 3)
Returns
Transform
scale(x, y, z)Static
Return a Transform which represents a scale by specified amounts in each dimension.
Parameters
x
Number
x scale factor
y
Number
y scale factor
z
Number
z scale factor
Returns
Transform
rotateX(theta)Static
Return a Transform which represents a clockwise rotation around the x axis.
Parameters
theta
Number
radians
Returns
Transform
rotateY(theta)Static
Return a Transform which represents a clockwise rotation around the y axis.
Parameters
theta
Number
radians
Returns
Transform
rotateZ(theta)Static
Return a Transform which represents a clockwise rotation around the z axis.
Parameters
theta
Number
radians
Returns
Transform
rotate(phi, theta, psi)Static
Return a Transform which represents composed clockwise rotations along each of the axes. Equivalent to the result of Matrix.multiply(rotateX(phi), rotateY(theta), rotateZ(psi)).
Parameters
phi
Number
radians to rotate about the positive x axis
theta
Number
radians to rotate about the positive y axis
psi
Number
radians to rotate about the positive z axis
Returns
Transform
rotateAxis(v, theta)Static
Return a Transform which represents an axis-angle rotation
Parameters
v
Array.Number
unit vector representing the axis to rotate about
theta
Number
radians to rotate clockwise about the axis
Returns
Transform
aboutOrigin(v, m)Static
Return a Transform which represents a transform matrix applied about a separate origin point.
Parameters
v
Array.Number
origin point to apply matrix
m
Transform
matrix to apply
Returns
Transform
skew(phi, theta, psi)Static
Return a Transform representation of a skew transformation
Parameters
phi
Number
scale factor skew in the x axis
theta
Number
scale factor skew in the y axis
psi
Number
scale factor skew in the z axis
Returns
Transform
skewX(angle)Static
Return a Transform representation of a skew in the x-direction
Parameters
angle
Number
the angle between the top and left sides
Returns
Transform
skewY(angle)Static
Return a Transform representation of a skew in the y-direction
Parameters
angle
Number
the angle between the top and right sides
Returns
Transform
perspective(focusZ)Static
Returns a perspective Transform matrix
Parameters
focusZ
Number
z position of focal point
Returns
Transform
getTranslate(m)Static
Return translation vector component of given Transform
Parameters
m
Transform
Transform
Returns
Array.Number
the translation vector [t_x, t_y, t_z]
inverse(m)Static
Return inverse affine transform for given Transform. Note: This assumes m[3] = m[7] = m[11] = 0, and m[15] = 1. Will provide incorrect results if not invertible or preconditions not met.
Parameters
m
Transform
Transform
Returns
Transform
transpose(m)Static
Returns the transpose of a 4x4 matrix
Parameters
m
Transform
matrix
Returns
Transform
the resulting transposed matrix
interpret(M)Static
Decompose Transform into separate .translate, .rotate, .scale, and .skew components.
Parameters
M
Transform
transform matrix
Returns
Object
matrix spec object with component matrices .translate, .rotate, .scale, .skew
average(M1, M2, t)Static
Weighted average between two matrices by averaging their translation, rotation, scale, skew components. f(M1,M2,t) = (1 - t) * M1 + t * M2
Parameters
M1
Transform
f(M1,M2,0) = M1
M2
Transform
f(M1,M2,1) = M2
t
Number
Returns
Transform
build(spec)Static
Compose .translate, .rotate, .scale, .skew components into Transform matrix
Parameters
spec
MatrixSpec
object with component matrices .translate, .rotate, .scale, .skew
Returns
Transform
composed transform
equals(a, b)Static
Determine if two Transforms are component-wise equal Warning: breaks on perspective Transforms
Parameters
a
Transform
matrix
b
Transform
matrix
Returns
Boolean
notEquals(a, b)Static
Determine if two Transforms are component-wise unequal Warning: breaks on perspective Transforms
Parameters
a
Transform
matrix
b
Transform
matrix
Returns
Boolean
normalizeRotation(rotation)Static
Constrain angle-trio components to range of [-pi, pi).
Parameters
rotation
Array.Number
phi, theta, psi (array of floats && array.length == 3)
Returns
Array.Number
new phi, theta, psi triplet (array of floats && array.length == 3)
inFront()Static
(Property) Array defining a translation forward in z by 1
behind()Static
(Property) Array defining a translation backwards in z by 1