Menu - Top - Home - Donate to Me

H3DU.Transform

Back to documentation index.

new H3DU.Transform()

A class offering a convenient way to set a transformation from one coordinate system to another.

Methods

H3DU.Transform#copy()

Makes a copy of this transform. The copied object will have its own version of the rotation, scale, position, and matrix data.

Return Value

A copy of this transform. (Type: Transform)

H3DU.Transform#getMatrix()

Gets the transformation matrix used by an object. Depending on the state of this transform, will return either:

Return Value

Return value. (Type: Array.<number>)

H3DU.Transform#getPosition()

Returns a copy of a three-element array giving the X, Y, and Z coordinates of the position of an object relative to its original position.

Return Value

Return value. (Type: Array.<number>)

H3DU.Transform#getQuaternion()

Returns a copy of the rotation of an object in the form of a quaternion.

Return Value

Return value. (Type: Array.<number>)

H3DU.Transform#getScale()

Returns a copy of a three-element array giving the scaling for an object's width, height, and depth, respectively. For each component, 1 means no scaling.

Return Value

Return value. (Type: Array.<number>)

H3DU.Transform#isIdentity()

Returns whether this transform is the identity transform.

Return Value

Return value. (Type: boolean)

H3DU.Transform#movePosition(x, y, z)

Moves the relative position of an object from its original position. Has no effect if a matrix was defined with Transform#setMatrix and the transform wasn't reset yet with Transform#resetTransform.

Parameters

Return Value

This object. (Type: Transform)

H3DU.Transform#multQuaternion(quat)

Combines an object's current rotation with another rotation described by a quaternion (a 4-element array for describing 3D rotations). The combined rotation will have the same effect as the new rotation followed by the existing rotation. Has no effect if a matrix was defined with Transform#setMatrix and the transform wasn't reset yet with Transform#resetTransform.

Parameters

Return Value

This object. (Type: Transform)

Examples

// Combine an object's rotation with a rotation 20 degrees about the X axis
transform.multQuaternion(MathUtil.quatFromAxisAngle(20,1,0,0));
// Combine an object's rotation with identity
transform.multQuaternion(MathUtil.quatIdentity());
// Combine an object's rotation with 30 degree pitch multiplied
// by 40 degree roll
transform.multQuaternion(MathUtil.quatFromTaitBryan(30,0,40));

H3DU.Transform#multRotation(angle, v, vy, vz)

Combines an object's current rotation with another rotation in the form of an angle and an axis of rotation. The combined rotation will have the same effect as the new rotation followed by the existing rotation. Has no effect if a matrix was defined with Transform#setMatrix and the transform wasn't reset yet with Transform#resetTransform.

Parameters

Return Value

This object. (Type: Transform)

H3DU.Transform#reset()

Resets this transform to the untransformed state.

Return Value

This object. (Type: Transform)

H3DU.Transform#setMatrix(value)

Sets this transform's transformation matrix. This method will set the position, rotation, and scale properties accordingly to the matrix given.

Parameters

Return Value

This object. (Type: Transform)

H3DU.Transform#setPosition(x, [y], [z])

Sets the relative position of an object from its original position. Has no effect if a matrix was defined with Transform#setMatrix and the transform wasn't reset yet with Transform#resetTransform.

Parameters

Return Value

This object. (Type: Transform)

Examples

// Set the relative position to 2 units along X axis, 4 units along Y axis,
// and 5 units along Z axis
transform.setPosition(2,4,5);
// same, but passing an array
transform.setPosition([2,4,5]);

H3DU.Transform#setQuaternion(quat)

Sets this transform's rotation in the form of a quaternion (a 4-element array for describing 3D rotations). Has no effect if a matrix was defined with Transform#setMatrix and the transform wasn't reset yet with Transform#resetTransform.

Parameters

Return Value

This object. (Type: Transform)

Examples

// Set an object's rotation to 30 degrees about the X axis
transform.setQuaternion(MathUtil.quatFromAxisAngle(20,1,0,0));
// Set an object's rotation to identity (the object isn't transformed)
transform.setQuaternion(MathUtil.quatIdentity());
// Set an object's rotation to 30 degree pitch multiplied
// by 40 degree roll
transform.setQuaternion(MathUtil.quatFromTaitBryan(30,0,40));
// Set an object's rotation to 40 units about X axis, 20 units about Y axis,
// and 50 units about Z axis
transform.setQuaternion(H3DU.MathUtil.quatFromTaitBryan(40,20,50));
// Set an object's rotation to 20 units about Y axis
transform.setQuaternion(H3DU.MathUtil.quatFromAxisAngle(20,0,1,0));

H3DU.Transform#setRotation(angle, v, vy, vz)

Sets this transform's rotation in the form of an angle and an axis of rotation. Has no effect if a matrix was defined with Transform#setMatrix and the transform wasn't reset yet with Transform#resetTransform.

Parameters

Return Value

This object. (Type: Transform)

H3DU.Transform#setScale(x, [y], [z])

Sets the scale of an object relative to its original size. Has no effect if a matrix was defined with Transform#setMatrix and the transform wasn't reset yet with Transform#resetTransform.

Parameters

Return Value

This object. (Type: Transform)

Examples

// scale coordinates by 2x in all axes
transform.setScale(2,2,2);
// same, but passing an array
transform.setScale([2,2,2]);

Back to documentation index.