Core.Transform Class
samsara/core/Transform.js:13
A library for creating and composing CSS3 matrix transforms.
A Transform is a 16 element float array t = [t0, ..., t15]
that corresponds to a 4x4 transformation matrix (in row-major order)
┌ ┐
│ t0 t1 t2 0 │
│ t4 t5 t6 0 │
│ t8 t9 t10 0 │
│ t12 t13 t14 1 │
└ ┘
This matrix is a data structure encoding a combination of translation, scale, skew and rotation components.
Note: these matrices are transposes from their mathematical counterparts.
Item Index
Methods
- aboutOrigin static
- average static
- build static
- compose static
- composeMany static
- equals static
- getTranslate static
- interpret static
- inverse static
- moveThen static
- notEquals static
- perspective static
- rotateAxis static
- rotateX static
- rotateX static
- rotateY static
- scale static
- scaleX static
- scaleY static
- scaleZ static
- skewX static
- skewY static
- thenMove static
- thenScale static
- translate static
- translateX static
- translateY static
- translateZ static
- transpose static
Methods
aboutOrigin
-
v
-
t
Return a Transform which represents a Transform applied about an origin point. Useful for rotating and scaling relative to an origin.
Parameters:
-
v
Number[]Origin point [x,y,z]
-
t
TransformTransform
Returns:
average
-
M1
-
M2
-
[t=1/2]
Weighted average between two matrices by averaging their translation, rotation, scale, skew components. f(M1,M2,t) = (1 - t) * M1 + t * M2
Parameters:
-
M1
TransformM1 = f(M1,M2,0) Transform
-
M2
TransformM2 = f(M1,M2,1) Transform
-
[t=1/2]
Number optional
Returns:
build
-
spec
Compose .translate, .rotate, .scale and .skew components into a Transform matrix. The "inverse" of .interpret.
Parameters:
-
spec
ObjectObject with keys "translate, rotate, scale, skew" and their vector values
Returns:
compose
-
t1
-
t2
Compose Transform arrays via matrix multiplication.
Parameters:
-
t1
TransformLeft Transform
-
t2
TransformRight Transform
Returns:
composeMany
-
Transform
Convenience method to Compose several Transform arrays.
Parameters:
-
Transform
...Transformarrays
Returns:
equals
-
a
-
b
Determine if two Transforms are component-wise equal.
Parameters:
-
a
TransformTransform
-
b
TransformTransform
Returns:
getTranslate
-
t
Return translation vector component of the given Transform.
Parameters:
-
t
TransformTransform
Returns:
interpret
-
t
Decompose Transform into separate translate
, rotate
, scale
and skew
components.
Parameters:
-
t
TransformTransform
Returns:
inverse
-
t
Return inverse Transform for given Transform. Note: will provide incorrect results if Transform is not invertible.
Parameters:
-
t
TransformTransform
Returns:
moveThen
-
v
-
t
Translate a Transform before the Transform is applied.
Parameters:
-
v
Number[]Array of [x,y,z] translation components
-
t
TransformTransform
Returns:
notEquals
-
a
-
b
Determine if two Transforms are component-wise unequal
Parameters:
-
a
TransformTransform
-
b
TransformTransform
Returns:
perspective
-
focusZ
Returns a perspective Transform.
Parameters:
-
focusZ
Numberz-depth of focal point
Returns:
rotateAxis
-
v
-
angle
Return a Transform which represents an axis-angle rotation.
Parameters:
Returns:
rotateX
-
angle
Return a Transform representing a clockwise rotation around the x-axis.
Parameters:
-
angle
NumberAngle in radians
Returns:
rotateX
-
angle
Return a Transform representing a clockwise rotation around the z-axis.
Parameters:
-
angle
NumberAngle in radians
Returns:
rotateY
-
angle
Return a Transform representing a clockwise rotation around the y-axis.
Parameters:
-
angle
NumberAngle in radians
Returns:
scale
-
v
Return a Transform which represents a scaling by specified amounts in each dimension.
Parameters:
-
v
Number[]Scale vector [x,y,z]
Returns:
scaleX
-
x
Return a Transform which represents scaling in the x-direction.
Parameters:
-
x
NumberScale amount
scaleY
-
y
Return a Transform which represents scaling in the y-direction.
Parameters:
-
y
NumberScale amount
scaleZ
-
z
Return a Transform which represents scaling in the z-direction.
Parameters:
-
z
NumberScale amount
skewX
-
angle
Return a Transform representation of a skew in the x-direction
Parameters:
-
angle
NumberThe angle between the top and left sides
Returns:
skewY
-
angle
Return a Transform representation of a skew in the y-direction
Parameters:
-
angle
NumberThe angle between the bottom and right sides
Returns:
thenMove
-
t
-
v
Translate a Transform after the Transform is applied.
Parameters:
-
t
TransformTransform
-
v
Number[]Array of [x,y,z] translation components
Returns:
thenScale
-
t
-
v
Scale a Transform after the Transform is applied.
Parameters:
-
t
TransformTransform
-
v
Number[]Array of [x,y,z] scale components
Returns:
translate
-
v
Return a Transform which represents translation by a translation vector.
Parameters:
-
v
Number[]Translation vector [x,y,z]
Returns:
translateX
-
x
Return a Transform which represents translation in the x-direction.
Parameters:
-
x
NumberTranslation amount
translateY
-
y
Return a Transform which represents translation in the y-direction.
Parameters:
-
y
NumberTranslation amount
translateZ
-
z
Return a Transform which represents translation in the z-direction.
Parameters:
-
z
NumberTranslation amount