Package com.jme3.math
Class Transform
java.lang.Object
com.jme3.math.Transform
- All Implemented Interfaces:
Savable
,Serializable
,Cloneable
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 Summary
-
Constructor Summary
ConstructorDescriptionInstantiates an identity transform: no translation, no rotation, and no scaling.Transform
(Quaternion rot) Instantiates a rotation-only transform.Instantiates a translation-only transform.Transform
(Vector3f translation, Quaternion rot) Instantiates a coordinate transform without scaling.Transform
(Vector3f translation, Quaternion rot, Vector3f scale) Instantiates a coordinate transform with scaling. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Creates a copy.combineWithParent
(Transform parent) Combines with the argument and returns the (modified) current instance.boolean
Tests for exact equality with the argument, distinguishing -0 from 0.void
Sets the current instance from a transform matrix.Returns the rotation component.getRotation
(Quaternion quat) Copies the rotation component to the argument.getScale()
Returns the scaling component.Copies the scaling component to the argument.Returns the translation component.getTranslation
(Vector3f trans) Copies the translation component to the argument.int
hashCode()
Returns a hash code.void
interpolateTransforms
(Transform t1, Transform t2, float delta) Interpolates quickly between the specified transforms, usingQuaternion.nlerp(com.jme3.math.Quaternion, float)
andVector3f.interpolateLocal(com.jme3.math.Vector3f, com.jme3.math.Vector3f, float)
.invert()
Returns the inverse.boolean
Tests for exact identity.void
Sets the current instance to the identity transform: translation=(0,0,0) scaling=(1,1,1) rotation=(0,0,0,1).void
read
(JmeImporter importer) De-serializes from the argument, for example when loading from a J3O file.Copies all 3 components from the argument.setRotation
(Quaternion rot) Sets the rotation component to the argument.setScale
(float scale) Sets the scaling component to the argument.setScale
(float x, float y, float z) Sets the scaling component to the specified values.Sets the scaling component to the argument.setTranslation
(float x, float y, float z) Sets the translation component to the specified values.setTranslation
(Vector3f trans) Sets the translation component to the argument.toString()
Returns a string representation of the transform, which is unaffected.Creates an equivalent transform matrix.toTransformMatrix
(Matrix4f store) Converts to an equivalent transform matrix.transformInverseVector
(Vector3f in, Vector3f store) Applies the inverse transform to the specified coordinates and returns the result instore
.transformVector
(Vector3f in, Vector3f store) Transforms the specified coordinates and returns the result instore
.void
write
(JmeExporter e) Serializes to the argument, for example when saving to a J3O file.
-
Field Details
-
IDENTITY
Shared instance of the identity transform. Do not modify!
-
-
Constructor Details
-
Transform
Instantiates a coordinate transform without scaling.- Parameters:
translation
- the desired translation (not null, unaffected)rot
- the desired rotation (not null, unaffected)
-
Transform
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
Instantiates a translation-only transform.- Parameters:
translation
- the desired translation (not null, unaffected)
-
Transform
Instantiates a rotation-only transform.- Parameters:
rot
- the desired rotation (not null, unaffected)
-
Transform
public Transform()Instantiates an identity transform: no translation, no rotation, and no scaling.
-
-
Method Details
-
setRotation
Sets the rotation component to the argument.- Parameters:
rot
- the desired rotation value (not null, unaffected)- Returns:
- the (modified) current instance (for chaining)
-
setTranslation
Sets the translation component to the argument.- Parameters:
trans
- the desired offsets (not null, unaffected)- Returns:
- the (modified) current instance (for chaining)
-
getTranslation
Returns the translation component.- Returns:
- the pre-existing instance (not null)
-
setScale
Sets the scaling component to the argument.- Parameters:
scale
- the desired scale factors (not null, unaffected)- Returns:
- the (modified) current instance (for chaining)
-
setScale
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
Returns the scaling component.- Returns:
- the pre-existing instance (not null)
-
getTranslation
Copies the translation component to the argument. If the argument is null, a new Vector3f is created to hold the value. Either way, the current instance is unaffected, unless the argument is its scaling component.- Parameters:
trans
- storage for the result (modified if not null)- Returns:
- the translation offsets (either
trans
or a new Vector3f)
-
getRotation
Copies the rotation component to the argument. If the argument is null, a new Quaternion is created to hold the value. Either way, the current instance is unaffected.- Parameters:
quat
- storage for the result (modified if not null)- Returns:
- the rotation value (either
quat
or a new Quaternion)
-
getRotation
Returns the rotation component.- Returns:
- the pre-existing instance (not null)
-
getScale
Copies the scaling component to the argument. If the argument is null, a new Vector3f is created to hold the value. Either way, the current instance is unaffected, unless the argument is its translation component.- Parameters:
scale
- storage for the result (modified if not null)- Returns:
- the scale factors (either
scale
or a new Vector3f)
-
interpolateTransforms
Interpolates quickly between the specified transforms, usingQuaternion.nlerp(com.jme3.math.Quaternion, float)
andVector3f.interpolateLocal(com.jme3.math.Vector3f, com.jme3.math.Vector3f, float)
.- Parameters:
t1
- the desired value whendelta
=0 (not null, unaffected unless it'sthis
)t2
- the desired value whendelta
=1 (not null, unaffected unless it'sthis
)delta
- the fractional change amount
-
combineWithParent
Combines with the argument and returns the (modified) current instance. This method is used to combine Node and Spatial transforms.- Parameters:
parent
- the parent transform (not null, unaffected unless it'sthis
)- Returns:
- the (modified) current instance (for chaining)
-
setTranslation
Sets the translation component to the specified values.- Parameters:
x
- the desired X offsety
- the desired Y offsetz
- the desired Z offset- Returns:
- the (modified) current instance (for chaining)
-
setScale
Sets the scaling component to the specified values.- Parameters:
x
- the desired X scale factory
- the desired Y scale factorz
- the desired Z scale factor- Returns:
- the (modified) current instance (for chaining)
-
transformVector
Transforms the specified coordinates and returns the result instore
. If thestore
is null, a new Vector3f is created to hold the value. Either way, the current instance is unaffected, unlessstore
is its translation or scaling.- Parameters:
in
- the coordinates to transform (not null, unaffected)store
- storage for the result (modified if not null)- Returns:
- the transformed coordinates (either
store
or a new Vector3f)
-
transformInverseVector
Applies the inverse transform to the specified coordinates and returns the result instore
. If thestore
is null, a new Vector3f is created to hold the value. Either way, the current instance is unaffected, unlessstore
is its translation or scaling.- Parameters:
in
- the coordinates to transform (not null, unaffected unless it'sstore
)store
- storage for the result (modified if not null)- Returns:
- the transformed coordinates (either
store
or a new Vector3f)
-
toTransformMatrix
Creates an equivalent transform matrix. The current instance is unaffected.- Returns:
- a new Matrix4f
-
toTransformMatrix
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
Sets the current instance from a transform matrix. Any shear in the matrix is lost -- in other words, it may not be possible to recreate the original matrix from the result.- Parameters:
mat
- the input matrix (not null, unaffected)
-
invert
Returns the inverse. The current instance is unaffected.- 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). -
isIdentity
public boolean isIdentity()Tests for exact identity. The current instance is unaffected.- Returns:
- true if equal to
IDENTITY
, otherwise false
-
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. -
equals
Tests for exact equality with the argument, distinguishing -0 from 0. Ifobj
is null, false is returned. Either way, the current instance is unaffected. -
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]
-
set
Copies all 3 components from the argument.- Parameters:
transform
- The Transform to copy (not null, unaffected)- Returns:
- the (modified) current instance (for chaining)
-
write
Serializes to the argument, for example when saving to a J3O file. The current instance is unaffected.- Specified by:
write
in interfaceSavable
- Parameters:
e
- (not null)- Throws:
IOException
- from the exporter
-
read
De-serializes from the argument, for example when loading from a J3O file.- Specified by:
read
in interfaceSavable
- Parameters:
importer
- (not null)- Throws:
IOException
- from the importer
-
clone
Creates a copy. The current instance is unaffected.
-