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:<ul>

  • The 4x4 matrix passed to Transform#setMatrix, if the matrix was defined with that method and the transform wasn't reset yet with Transform#resetTransform.
  • The matrix resulting from the position, rotation, and scale properties, multiplied in that order, otherwise. </ul> #### 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 * `x` (Type: Array.<number> | number)
    Number to add to the X coordinate, If "y" and "z" are null, undefined, or omitted, this is instead a 3-element array giving the numbers to add to the X, Y, and Z coordinates, or a single number to add to all three coordinates. * `y` (Type: number)
    Number to add to the Y coordinate. If "x" is an array, this parameter may be omitted. * `z` (Type: number)
    Number to add to the Z coordinate. If "x" is an array, this parameter may be omitted. #### 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 * `quat` (Type: Array.<number>)
    A four-element array describing the rotation. A quaternion is returned from the methods MathUtil.quatFromAxisAngle or MathUtil.quatFromTaitBryan. #### 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 * `angle` (Type: Array.<number> | number)
    The desired angle to rotate in degrees. See Transform#setRotation. * `v` (Type: Array.<number> | number)
    X-component of the point lying on the axis of rotation. If "vy" and "vz" are omitted, this can instead be a 3-element array giving the axis of rotation in x, y, and z, respectively. * `vy` (Type: number)
    Y-component of the point lying on the axis of rotation. * `vz` (Type: number)
    Z-component of the point lying on the axis of rotation. #### 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 * `value` (Type: Array.<number>)
    A 4x4 matrix. This method will copy the value of this parameter. #### 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 * `x` (Type: Array.<number> | number)
    The X coordinate. If "y" and "z" are null, undefined, or omitted, this is instead a 3-element array giving the X, Y, and Z coordinates, or a single number giving the coordinate for all three dimensions. * `y` (Type: number) (optional)
    The Y coordinate. If "x" is an array, this parameter may be omitted. * `z` (Type: number) (optional)
    The Z coordinate. If "x" is an array, this parameter may be omitted. #### 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 * `quat` (Type: Array.<number>)
    A four-element array describing the rotation. A quaternion is returned from the methods MathUtil.quatFromAxisAngle and MathUtil.quatFromTaitBryan, among others. #### 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 * `angle` (Type: Array.<number> | number)
    The desired angle to rotate in degrees. If "v", "vy", and "vz" are omitted, this can instead be a 4-element array giving the axis of rotation as the first three elements, followed by the angle in degrees as the fourth element. If the axis of rotation points toward the viewer, a positive value means the angle runs in a counterclockwise direction for right-handed coordinate systems and in a clockwise direction for left-handed systems. * `v` (Type: Array.<number> | number)
    X-component of the point lying on the axis of rotation. If "vy" and "vz" are omitted, this can instead be a 3-element array giving the axis of rotation in x, y, and z, respectively. * `vy` (Type: number)
    Y-component of the point lying on the axis of rotation. * `vz` (Type: number)
    Z-component of the point lying on the axis of rotation. #### 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 * `x` (Type: number | Array.<number>)
    X axis scaling factor for this transform. If "y" and "z" are null, undefined, or omitted, this is instead a 3-element array giving the scaling factors for X, Y, and Z dimensions, respectively, or a single number giving the scaling factor for all three dimensions. * `y` (Type: number) (optional)
    Y axis scaling factor for this transform. * `z` (Type: number) (optional)
    Z axis scaling factor for this transform. #### 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.](index.html)