# Transform

## Transform

Transform models a transformation in 3d space as: Y = MX+T, with M being a Matrix3 and T is a Vector3. Generally M will be a rotation
only matrix in which case it is represented by the matrix and scale fields as R
S, where S is a positive scale vector. For non-uniform
scales and reflections, use setMatrix, which will consider M as being a general 3x3 matrix and disregard anything set in scale.

## Constructor

### Members

#### sortScale :boolean

Sort the scale and rotation in decompose. if it is turned on, the scale will be sorted and consistent in decomposition
Default to false because it breaking some existing features.

### Methods

#### (static) combine(lhs, rhs, target) → {Transform}

Combines two transforms into one.

##### Parameters:
Name Type Description
`lhs`

left hand side transform

`rhs`

right hand side transform

`target`

#### applyForward(point, store) → {Vector3}

Applies this transform to supplied vector as a point

##### Parameters:
Name Type Description
`point`
`store`
##### Example
``````// Vector3 representing one unit right, two units up, two units back
var v1 = new Vector3(1, 2, 2);
// Vector3 to store the local position
var localPos = new Vector3();
// converts v1 to be in 'world space' based on the entities position / rotation
entity.transformComponent.transform.applyForward(v1, localPos);``````

#### applyForwardVector(vector, store) → {Vector3}

Applies this transform to supplied vector as a direction-vector (translation will not affect it)

##### Parameters:
Name Type Description
`vector`
`store`
##### Example
``````// Vector3 pointing in the direction we want
var back = new Vector3(0, 0, 1);
// Vector3 to store the local 'back'
var localBack = new Vector3();
// converts 'back' to a localized direction based on the entities rotation
entity.transformComponent.transform.applyForwardVector(back, localBack);``````

#### clone() → {Transform}

Returns a clone of this transform

#### combine(rhs) → {Transform}

Combines new transform into this one. This will only work if scaling in the left hand transform is uniform

##### Parameters:
Name Type Description
`rhs`

right hand side transform

#### copy(transform) → {Transform}

Copy supplied transform into this transform

##### Parameters:
Name Type Description
`transform`

#### decompose() → {Transform}

Decompose matrix to get translation, rotation, scale and scaleRotation

#### fromMatrix(matrix)

Set a transform from matrix.

##### Parameters:
Name Type Description
`matrix`

#### invert(store) → {Transform}

Invert this transform and store it in supplied transform

##### Parameters:
Name Type Description
`store`

#### lookAt(position, upopt) → {Transform}

Sets the transform to look in a specific direction.

##### Parameters:
Name Type Attributes Default Description
`position`

Target position.

`up` <optional>
(0, 1, 0)

Up vector.

#### multiply(a, b) → {Transform}

multiply two transforms and store result in this transform

##### Parameters:
Name Type Description
`a`
`b`

#### setIdentity() → {Transform}

Set Transform to identity

#### setRotationXYZ(x, y, z) → {Transform}

Set this transform's rotation to rotation around X, Y and Z axis. Euler order is YZX.

##### Parameters:
Name Type Description
`x` number
`y` number
`z` number

#### update() → {Transform}

Updates the transform according to set scaling, rotation and translation. This is done automatically by the engine

#### updateNormalMatrix() → {Transform}

Updates the normal matrix. This is done automatically by the engine.