LS.Components.Transform Class
Transform that contains the position (vec3), rotation (quat) and scale (vec3) It uses lazy update to recompute the matrices.
Constructor
LS.Components.Transform
-
object
Parameters:
-
object
Objectto configure from
Item Index
Methods
- applyTransform
- applyTransformMatrix
- configure
- copyFrom
- fromGlobalMatrix
- fromMatrix
- getAncestors
- getFront
- getGlobalMatrix
- getGlobalMatrix
- getGlobalPosition
- getGlobalRotation
- getGlobalRotationMatrix
- getGlobalRotationMatrix
- getGlobalScale
- getGlobalTranslationMatrix
- getGlobalTranslationRotationMatrix
- getLocalMatrixRef
- getMatrix
- getNormalMatrix
- getPosition
- getRight
- getRotation
- getRotation
- getScale
- getTop
- globalToLocal
- identity
- interpolate
- localToGlobal
- localVectorToGlobal
- lookAt
- orbit
- resetPosition
- resetRotation
- resetScale
- rotate
- rotateGlobal
- rotateQuat
- rotateQuatGlobal
- rotateX
- rotateY
- rotateZ
- scale
- serialize
- setPosition
- setRotation
- setRotationFromEuler
- setScale
- transformPoint
- transformPointGlobal
- transformVector
- translate
- translateGlobal
- updateGlobalMatrix
- updateMatrix
Properties
Events
Methods
applyTransform
()
Apply a transform to this transform
applyTransformMatrix
-
matrix
-
center
-
is_global
Applies the transformation using a matrix
Parameters:
-
matrix
Mat4with the transform
-
center
Vec3different pivot [optional] if omited 0,0,0 will be used
-
is_global
Bool(optional) tells if the transformation should be applied in global space or local space
configure
-
object
Configure from a serialized object
Parameters:
-
object
Objectwith the serialized info
copyFrom
-
src
Copy the transform from another Transform
Parameters:
-
src
Transform
fromGlobalMatrix
-
matrix
Configure the transform from a global Matrix (do not tested carefully)
Parameters:
-
matrix
Mat4the matrix in array format
fromMatrix
-
matrix
-
is_global
Configure the transform from a local Matrix (do not tested carefully)
Parameters:
-
matrix
Mat4the matrix in array format
-
is_global
Booltells if the matrix is in global space [optional]
getAncestors
()
Array
Returns an array with all the ancestors
Returns:
getFront
()
Vec3
returns the [0,0,-1] vector in global space
Returns:
getGlobalMatrix
-
out
-
fast
Returns a copy of the global matrix of this transform (it updates the matrix automatically)
Parameters:
-
out
Mat4optional
-
fast
Booleanthis flags skips recomputing parents matrices
Returns:
the matrix in array format
getGlobalMatrix
()
Mat4
Returns a copy of the global matrix of this transform (it updates the matrix automatically)
Returns:
the matrix in array format
getGlobalPosition
-
out
Returns a copy of the global position
Parameters:
-
out
Vec3[optional] where to store the result, otherwise one vec3 is created and returned
Returns:
the position
getGlobalRotation
()
Quat
Returns a quaternion with all parents rotations
Returns:
Quaternion
getGlobalRotationMatrix
()
Mat4
Returns the global rotation in quaternion array (a copy)
Returns:
the rotation
getGlobalRotationMatrix
()
Mat4
Returns a Matrix with all parents rotations
Returns:
Matrix rotation
getGlobalScale
-
out
Returns a copy of the global scale (this is not correct, there is no global_scale factor, because due to rotations the axis could change)
Parameters:
-
out
Vec3[optional] where to store the result, otherwise one vec3 is created and returned
Returns:
the scale
getGlobalTranslationMatrix
()
Mat4
Returns the local matrix of this transform without the rotation or scale
Returns:
the matrix in array format
getGlobalTranslationRotationMatrix
()
Mat4
Returns the local matrix of this transform without the scale
Returns:
the matrix in array format
getLocalMatrixRef
()
Mat4
Returns the original local matrix of this transform (it updates the matrix automatically)
Returns:
the matrix in array format
getMatrix
-
out
Returns a copy of the local matrix of this transform (it updates the matrix automatically)
Parameters:
-
out
Mat4[optional] where to store the result, otherwise one mat4 is created and returned
Returns:
the matrix
getNormalMatrix
()
Mat4
Returns the matrix for the normals in the shader
Returns:
the matrix in array format
getPosition
-
out
Returns a copy of the local position
Parameters:
-
out
Vec3[optional] where to store the result, otherwise one vec3 is created and returned
Returns:
the position
getRight
()
Vec3
returns the [1,0,0] vector in global space
Returns:
getRotation
-
out
Returns the rotation in quaternion array (a copy)
Parameters:
-
out
Quat[optional] where to store the result, otherwise one quat is created and returned
Returns:
the rotation
getRotation
-
out
Returns the global rotation in quaternion array (a copy)
Parameters:
-
out
Quat[optional] where to store the result, otherwise one quat is created and returned
Returns:
the rotation
getScale
-
out
Returns the scale (its a copy)
Parameters:
-
out
Vec3[optional] where to store the result, otherwise one vec3 is created and returned
Returns:
the scale
getTop
()
Vec3
returns the [0,1,0] vector in global space
Returns:
globalToLocal
-
point
-
destination
convert from global coordinates to local coordinates
Parameters:
-
point
Vec3 -
destination
Vec3(optional)
identity
()
Reset this transform
interpolate
-
a
-
b
-
factor
-
the
This method is static (call it from Transform.interpolate) interpolate the transform between two transforms and stores the result in another Transform
Parameters:
-
a
Transform -
b
Transform -
factor
Numberfrom 0 to 1
-
the
Transformdestination
localToGlobal
-
point
-
destination
convert from local coordinates to global coordinates If no destination is specified a new vector is created
Parameters:
-
point
Vec3 -
destination
Vec3(optional)
localVectorToGlobal
-
vector
-
destination
Applies the transformation to a vector (rotate but not translate)
Parameters:
-
vector
Vec3 -
destination
Vec3(optional)
lookAt
-
position
-
target
-
up
-
in_world
Orients the transform to look from one position to another
Parameters:
-
position
Vec3 -
target
Vec3 -
up
Vec3 -
in_world
Booleantells if the values are in world coordinates (otherwise asume its in local coordinates)
orbit
-
angle_in_deg
-
axis
-
center
Orbits around a point
Parameters:
-
angle_in_deg
Number -
axis
Vec3 -
center
Vec3in local coordinates
resetPosition
()
Sets the position to 0,0,0
resetRotation
()
Sets the rotation to identity
resetScale
()
Sets the scale to 1,1,1
rotate
-
angle_in_deg
-
axis
-
is_global
rotate object in local space (axis is in local space)
Parameters:
-
angle_in_deg
Number -
axis
Vec3 -
is_global
Booleantells if the axis is in global coordinates or local coordinates
rotateGlobal
-
angle_in_deg
-
axis
rotate object in global space (axis is in global space)
Parameters:
-
angle_in_deg
Number -
axis
Vec3
rotateQuat
-
quaternion
rotate object in local space using a quat
Parameters:
-
quaternion
Quat
rotateQuatGlobal
-
quaternion
rotate object in global space using a quat
Parameters:
-
quaternion
Quat
rotateX
-
angle_in_rad
rotate object in local space in local X axis
Parameters:
-
angle_in_rad
Number
rotateY
-
angle_in_rad
rotate object in local space in local Y axis
Parameters:
-
angle_in_rad
Number
rotateZ
-
angle_in_rad
rotate object in local space in local Z axis
Parameters:
-
angle_in_rad
Number
scale
-
x
-
y
-
z
scale the object
Parameters:
-
x
Number -
y
Number -
z
Number
serialize
()
Object
Serialize the object
Returns:
object with the serialized info
setPosition
-
x
-
y
-
z
sets the position
Parameters:
-
x
Number -
y
Number -
z
Number
setRotation
-
rotation
sets the rotation from a quaternion or from an angle(rad) and axis
Parameters:
-
rotation
Quatin quaterion format or angle
setRotationFromEuler
-
src,
Configure the transform rotation from a vec3 Euler angles (heading,attitude,bank)
Parameters:
-
src,
Mat4the matrix in array format
setScale
-
x
-
y
-
z
sets the scale
Parameters:
-
x
Number -
y
Number -
z
Number
transformPoint
-
point
-
destination
Multiplies a point by the local matrix (not global) If no destination is specified a new vector is created
Parameters:
-
point
Vec3 -
destination
Vec3(optional)
transformPointGlobal
-
point
-
destination
same as localToGlobal
Parameters:
-
point
Vec3 -
destination
Vec3(optional)
transformVector
-
vector
-
destination
Applies the transformation to a vector (rotate but not translate)
Parameters:
-
vector
Vec3 -
destination
Vec3(optional)
translate
-
x
-
y
-
z
translates object in local coordinates (using the rotation and the scale)
Parameters:
-
x
Number -
y
Number -
z
Number
translateGlobal
-
x
-
y
-
z
translates object in local coordinates (adds to the position)
Parameters:
-
x
Number -
y
Number -
z
Number
updateGlobalMatrix
-
fast
updates the global matrix using the parents transformation
Parameters:
-
fast
Boolit doesnt recompute parent matrices, just uses the stored one, is faster but could create errors if the parent doesnt have its global matrix update
updateMatrix
()
update the local Matrix to match the position,scale and rotation
Properties
forward
Mat4
The forward vector in global coordinates
globalMatrix
Mat4
The matrix transform relative to world coordinates
matrix
Mat4
The local matrix transform relative to its parent in mat4 format
mustUpdate
Boolean
Force object to update matrices in case they were modified
position
Vec3
The position relative to its parent in vec3 format
position
Vec3
The position relative to its parent in vec3 format
rotation
Quat
The orientation relative to its parent in quaternion format
scaling
Vec3
The scaling relative to its parent in vec3 format (default is [1,1,1])
Events
changed
Fired when the node has changed its transform