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)
Creates a new
Transform . |
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(Location<E> location)
location
- The provided location that provides the
extent, and positionpublic Transform(E extent)
extent
- The extent to usepublic Transform(E extent, com.flowpowered.math.vector.Vector3d position)
extent
- The extent to useposition
- The position to usepublic Transform(E extent, com.flowpowered.math.vector.Vector3d position, com.flowpowered.math.vector.Vector3d rotation)
extent
- The extent to useposition
- The position to userotation
- The rotation to usepublic Transform(Location<E> location, com.flowpowered.math.vector.Vector3d rotation, com.flowpowered.math.vector.Vector3d scale)
location
- The location to use, providing the extent and positionrotation
- The rotation to usescale
- The scale to usepublic Transform(E extent, com.flowpowered.math.vector.Vector3d position, com.flowpowered.math.vector.Vector3d rotation, com.flowpowered.math.vector.Vector3d scale)
Transform
.extent
- The extent to useposition
- The position to userotation
- The rotation to usescale
- The scale to usepublic 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 Transform<E> setRotation(com.flowpowered.math.vector.Vector3d rotation)
Quaternions are objectively better than the Euler angles preferred by Minecraft. This is for compatibility with the flow-math library.
rotation
- The new rotationpublic com.flowpowered.math.imaginary.Quaterniond getRotationAsQuaternion()
Quaternions are objectively better than the Euler angles preferred by Minecraft. This is for compatibility with the flow-math library.
public 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)
Returns the results as a new copy.
other
- The transform to addpublic Transform<E> addTranslation(com.flowpowered.math.vector.Vector3d translation)
Returns the results as a new copy.
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)
Quaternions are objectively better than the Euler angles preferred by Minecraft. This is the preferred method when dealing with rotation additions. This is for compatibility with the flow-math library.
Returns the results as a new copy.
rotation
- The rotation to addpublic Transform<E> addScale(com.flowpowered.math.vector.Vector3d scale)
Returns the results as a new copy.
scale
- The scale to addpublic com.flowpowered.math.matrix.Matrix4d toMatrix()
This includes the position, rotation and scale. To apply the transform to a vector, use the following:
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: