E
- The extent containing the transformpublic final class Transform<E extends Extent> extends Object
Entity
. Comprised of
a Location
and two Vector3d
representing the rotation
and the scale. The implementation may internally use a location or a
separate extent and position. Be wary that calling getLocation()
could result in object creation.
A transform might not have an extent if it is invalid. In this case
all methods which return a reference to it will throw
IllegalStateException
.
This is an entity transform, not a model one. These values are subject to interpretation by the implementation and may trigger animations depending on the target model.
Even though Minecraft doesn't currently support entity scales
it is part of the transform in case it gets added later. For now
this return Vector3d.ONE
.
Constructor and Description |
---|
Transform(E extent) |
Transform(E extent,
com.flowpowered.math.vector.Vector3d position) |
Transform(E extent,
com.flowpowered.math.vector.Vector3d position,
com.flowpowered.math.vector.Vector3d rotation) |
Transform(E extent,
com.flowpowered.math.vector.Vector3d position,
com.flowpowered.math.vector.Vector3d rotation,
com.flowpowered.math.vector.Vector3d scale) |
Transform(Location<E> location) |
Transform(Location<E> location,
com.flowpowered.math.vector.Vector3d rotation,
com.flowpowered.math.vector.Vector3d scale) |
Modifier and Type | Method and Description |
---|---|
Transform<E> |
add(Transform<E> other)
"Adds" another transform to this one.
|
Transform<E> |
addRotation(com.flowpowered.math.imaginary.Quaterniond rotation)
Adds a rotation to this transform.
|
Transform<E> |
addRotation(com.flowpowered.math.vector.Vector3d rotation)
Adds a rotation to this transform.
|
Transform<E> |
addScale(com.flowpowered.math.vector.Vector3d scale)
"Adds" a scale to this transform.
|
Transform<E> |
addTranslation(com.flowpowered.math.vector.Vector3d translation)
Adds a translation to this transform.
|
boolean |
equals(Object other) |
E |
getExtent()
Gets the
Extent this transform contains. |
Location<E> |
getLocation()
Gets the
Location this transform contains. |
double |
getPitch()
Gets the pitch component of this transform rotation
|
com.flowpowered.math.vector.Vector3d |
getPosition()
Gets the coordinates of this transform.
|
double |
getRoll()
Gets the roll component of this transform rotation
|
com.flowpowered.math.vector.Vector3d |
getRotation()
Gets the rotation of this transform, as a
Vector3d . |
com.flowpowered.math.imaginary.Quaterniond |
getRotationAsQuaternion()
Returns the rotation as a quaternion.
|
com.flowpowered.math.vector.Vector3d |
getScale()
Gets the scale of the transform for each axis.
|
double |
getYaw()
Gets the yaw component of this transform rotation
|
int |
hashCode() |
boolean |
isValid()
Returns if this
Transform is still valid. |
Transform<E> |
setExtent(E extent)
Creates a copy of this transform and sets the
Extent . |
Transform<E> |
setLocation(Location<E> location)
Creates a copy of this transform and sets the
Location . |
Transform<E> |
setPosition(com.flowpowered.math.vector.Vector3d position)
Creates a copy of this transform while setting the position of the new one.
|
Transform<E> |
setRotation(com.flowpowered.math.imaginary.Quaterniond rotation)
Creates a copy of this transform and sets the rotation.
|
Transform<E> |
setRotation(com.flowpowered.math.vector.Vector3d rotation)
Creates a copy of this transform and sets the rotation as
a quaternion.
|
Transform<E> |
setScale(com.flowpowered.math.vector.Vector3d scale)
Creates a copy of this transform and sets the scale for
each axis.
|
com.flowpowered.math.matrix.Matrix4d |
toMatrix()
Returns a matrix representation of this transform.
|
String |
toString() |
public Transform(E extent)
public Transform(E extent, com.flowpowered.math.vector.Vector3d position)
public Transform(E extent, com.flowpowered.math.vector.Vector3d position, com.flowpowered.math.vector.Vector3d rotation)
public Transform(Location<E> location, com.flowpowered.math.vector.Vector3d rotation, com.flowpowered.math.vector.Vector3d scale)
public Transform(E extent, com.flowpowered.math.vector.Vector3d position, com.flowpowered.math.vector.Vector3d rotation, com.flowpowered.math.vector.Vector3d scale)
public Location<E> getLocation()
Location
this transform contains.
This is the position and the extent.IllegalStateException
- If the transform doesn't have an extentpublic Transform<E> setLocation(Location<E> location)
Location
.
This sets both the position and the extent.location
- The new locationpublic E getExtent()
Extent
this transform contains.
Note: This can be null if the Extent
is unloaded and garbage
collected.
IllegalStateException
- If the transform doesn't have an extentpublic Transform<E> setExtent(E extent)
Extent
.extent
- The new extentpublic com.flowpowered.math.vector.Vector3d getPosition()
public Transform<E> setPosition(com.flowpowered.math.vector.Vector3d position)
position
- The positionpublic com.flowpowered.math.vector.Vector3d getRotation()
Vector3d
.
The format of the rotation is represented by:
x -> pitch
y -> yaw
z -> roll
public Transform<E> setRotation(com.flowpowered.math.imaginary.Quaterniond rotation)
The format of the rotation is represented by:
x -> pitch
y -> yaw
z -> roll
rotation
- The new rotationpublic com.flowpowered.math.imaginary.Quaterniond getRotationAsQuaternion()
public Transform<E> setRotation(com.flowpowered.math.vector.Vector3d rotation)
rotation
- The new rotationpublic double getPitch()
public double getYaw()
public double getRoll()
public com.flowpowered.math.vector.Vector3d getScale()
public Transform<E> setScale(com.flowpowered.math.vector.Vector3d scale)
scale
- The scalepublic Transform<E> add(Transform<E> other)
other
- The transform to addpublic Transform<E> addTranslation(com.flowpowered.math.vector.Vector3d translation)
translation
- The translation to addpublic Transform<E> addRotation(com.flowpowered.math.vector.Vector3d rotation)
rotation
- The rotation to addpublic Transform<E> addRotation(com.flowpowered.math.imaginary.Quaterniond rotation)
rotation
- The rotation to addpublic Transform<E> addScale(com.flowpowered.math.vector.Vector3d scale)
scale
- The scale to addpublic com.flowpowered.math.matrix.Matrix4d toMatrix()
Vector3d original = ...;
Transform transform = ...;
Vector3d transformed = transform.toMatrix().transform(original.toVector4(1)).toVector3();
This converts the original 3D vector to 4D by appending 1 as the w coordinate, applies the transformation, then converts it back to 3D by dropping the w coordinate.
Using a 4D matrix and a w coordinate with value 1 is what allows for the position to be included in the transformation applied by the matrix.
public boolean isValid()
Transform
is still valid.
Examples of invalid Transforms are: