Package com.jme3.math

Class Transform

java.lang.Object
com.jme3.math.Transform
All Implemented Interfaces:
Serializable, Cloneable

public final class Transform extends Object implements Cloneable, Serializable
A 3-D coordinate transform composed of translation, rotation, and scaling. The order of application is: scale, then rotate, then translate.

Started July 16, 2004

See Also:
  • Field Details

    • IDENTITY

      public static final Transform IDENTITY
      Shared instance of the identity transform. Do not modify!
  • Constructor Details

    • Transform

      public Transform(Vector3f translation, Quaternion rot)
      Instantiates a coordinate transform without scaling.
      Parameters:
      translation - the desired translation (not null, unaffected)
      rot - the desired rotation (not null, unaffected)
    • Transform

      public Transform(Vector3f translation, Quaternion rot, Vector3f scale)
      Instantiates a coordinate transform with scaling.
      Parameters:
      translation - the desired translation (not null, unaffected)
      rot - the desired rotation (not null, unaffected)
      scale - the desired scaling (not null, unaffected)
    • Transform

      public Transform()
      Instantiates an identity transform: no translation, no rotation, and no scaling.
  • Method Details

    • setRotation

      public Transform setRotation(Quaternion rot)
      Sets the rotation component to the argument.
      Parameters:
      rot - the desired rotation value (not null, unaffected)
      Returns:
      the (modified) current instance (for chaining)
    • setTranslation

      public Transform setTranslation(Vector3f trans)
      Sets the translation component to the argument.
      Parameters:
      trans - the desired offsets (not null, unaffected)
      Returns:
      the (modified) current instance (for chaining)
    • getTranslation

      public Vector3f getTranslation()
      Returns the translation component.
      Returns:
      the pre-existing instance (not null)
    • setScale

      public Transform setScale(Vector3f scale)
      Sets the scaling component to the argument.
      Parameters:
      scale - the desired scale factors (not null, unaffected)
      Returns:
      the (modified) current instance (for chaining)
    • setScale

      public Transform setScale(float scale)
      Sets the scaling component to the argument. This yields uniform scaling.
      Parameters:
      scale - the desired scale factor for all local axes
      Returns:
      the (modified) current instance (for chaining)
    • getScale

      public Vector3f getScale()
      Returns the scaling component.
      Returns:
      the pre-existing instance (not null)
    • getRotation

      public Quaternion getRotation()
      Returns the rotation component.
      Returns:
      the pre-existing instance (not null)
    • toTransformMatrix

      public Matrix4f toTransformMatrix()
      Creates an equivalent transform matrix. The current instance is unaffected.
      Returns:
      a new Matrix4f
    • toTransformMatrix

      public Matrix4f toTransformMatrix(Matrix4f store)
      Converts to an equivalent transform matrix. The current instance is unaffected.
      Parameters:
      store - storage for the result (modified if not null)
      Returns:
      a transform matrix (either store or a new Matrix4f)
    • fromTransformMatrix

      public void fromTransformMatrix(Matrix4f mat)
      Sets the current instance from a transform matrix. Any reflection or shear in the matrix is lost -- in other words, it may not be possible to recreate the original matrix from the result.

      After this method is invoked, all components of scale will be non-negative, even if mat includes reflection.

      Parameters:
      mat - the input matrix (not null, unaffected)
    • invert

      public Transform invert()
      Returns the inverse. The current instance is unaffected.

      Assumes (but does not verify) that the scale factors are all positive. If any component of scale is negative or zero, the result is undefined.

      Returns:
      a new Transform
    • loadIdentity

      public void loadIdentity()
      Sets the current instance to the identity transform: translation=(0,0,0) scaling=(1,1,1) rotation=(0,0,0,1).
    • hashCode

      public int hashCode()
      Returns a hash code. If two transforms have identical values, they will have the same hash code. The current instance is unaffected.
      Overrides:
      hashCode in class Object
      Returns:
      a 32-bit value for use in hashing
    • equals

      public boolean equals(Object obj)
      Tests for exact equality with the argument, distinguishing -0 from 0. If obj is null, false is returned. Either way, the current instance is unaffected.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare (may be null, unaffected)
      Returns:
      true if this and obj have identical values, otherwise false
    • toString

      public String toString()
      Returns a string representation of the transform, which is unaffected. For example, the identity transform is represented by:
       Transform[ 0.0, 0.0, 0.0]
       [ 0.0, 0.0, 0.0, 1.0]
       [ 1.0 , 1.0, 1.0]
       
      Overrides:
      toString in class Object
      Returns:
      the string representation (not null, not empty)
    • clone

      public Transform clone()
      Creates a copy. The current instance is unaffected.
      Overrides:
      clone in class Object
      Returns:
      a new instance, equivalent to the current one