Package org.spongepowered.api.util
Class DiscreteTransform3
java.lang.Object
org.spongepowered.api.util.DiscreteTransform3
Represents a transform. It is 3 dimensional and discrete.
It will never cause aliasing.
Rotations are performed around block centers unless the block corner flags are set to true. To prevent aliasing, quarter turn rotations are only legal on block centers or corners. Half turns can be performed additionally on edge and face centers.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final DiscreteTransform3
Represents an identity transformation. -
Method Summary
Modifier and TypeMethodDescriptionandThen
(DiscreteTransform3 that) Returns a transform that is the composition of the given transform with this transform.compose
(DiscreteTransform3 that) Returns a transform that is the composition of this transform and the given transform.static DiscreteTransform3
fromRotation
(int quarterTurns, Axis axis) Returns a new transform representing a rotation around an axis around the origin.static DiscreteTransform3
fromRotation
(int quarterTurns, Axis axis, Vector3i point, boolean blockCorner) Returns a new transform representing a rotation around an axis, around a given point.static DiscreteTransform3
fromRotation
(int halfTurns, Axis axis, Vector3i point, boolean blockCornerX, boolean blockCornerY, boolean blockCornerZ) Returns a new transform representing a rotation around an axis, around a given point.static DiscreteTransform3
fromScale
(int a) Returns a new transform representing a scaling.static DiscreteTransform3
fromScale
(int x, int y, int z) Returns a new transform representing a scaling on each axis.static DiscreteTransform3
Returns a new transform representing a scaling on each axis.static DiscreteTransform3
fromTranslation
(int x, int y, int z) Returns a new transform representing a translation.static DiscreteTransform3
fromTranslation
(Vector3i vector) Returns a new transform representing a translation.invert()
Inverts the transform and returns it as a new transform.matrix()
Returns the matrix representation of the transform.static Optional
<DiscreteTransform3> Returns a new transform from the given transformation matrix, if the resulting transform would be discrete.static DiscreteTransform3
rotationAroundCenter
(int quarterTurns, Axis axis, Vector3i size) Returns a new transform representing a centered rotation of an volume of blocks.transform
(int x, int y, int z) Transform a vector represented as a pair of coordinates using this transform.Transforms a vector using this transforms.int
transformX
(int x, int y, int z) Transforms the x coordinate of a vector using this transform.int
transformX
(Vector3i vector) Transforms the x coordinate of a vector using this transform.int
transformY
(int x, int y, int z) Transforms the y coordinate of a vector using this transform.int
transformY
(Vector3i vector) Transforms the y coordinate of a vector using this transform.int
transformZ
(int x, int y, int z) Transforms the z coordinate of a vector using this transform.int
transformZ
(Vector3i vector) Transforms the z coordinate of a vector using this transform.withRotation
(int quarterTurns, Axis axis) Adds a rotation to this transform, around an axis, around the origin and returns it as a new transform.withRotation
(int quarterTurns, Axis axis, Vector3i point, boolean blockCorner) Adds a a rotation to this transform, around an axis, around a given point, and returns it as a new transform.withRotation
(int halfTurns, Axis axis, Vector3i point, boolean blockCornerX, boolean blockCornerY, boolean blockCornerZ) Adds a a rotation to this transform, around an axis, around a given point.withScale
(int a) Adds a scale factor to this transform and returns it as a new transform.withScale
(int x, int y, int z) Adds a scale factor for each axis to this transform and returns it as a new transform.Adds a scale factor for each axis to this transform and returns it as a new transform.withTransformation
(DiscreteTransform3 transform) Adds another transformation to this transformation and returns int as a new transform.withTranslation
(int x, int y, int z) Adds a translation to this transform and returns it as a new transform.withTranslation
(Vector3i vector) Adds a translation to this transform and returns it as a new transform.
-
Field Details
-
IDENTITY
Represents an identity transformation. Does nothing!
-
-
Method Details
-
matrix
Returns the matrix representation of the transform. It is 4D to allow it to include a translation.- Returns:
- The matrix for this transform
-
transform
Transforms a vector using this transforms.- Parameters:
vector
- The original vector- Returns:
- The transformed vector
-
transform
Transform a vector represented as a pair of coordinates using this transform.- Parameters:
x
- The x coordinate of the original vectory
- The y coordinate of the original vectorz
- The z coordinate of the original vector- Returns:
- The transformed vector
-
transformX
Transforms the x coordinate of a vector using this transform. Only creates a new object on the first call.- Parameters:
vector
- The original vector- Returns:
- The transformed x coordinate
-
transformX
public int transformX(int x, int y, int z) Transforms the x coordinate of a vector using this transform. Only creates a new object on the first call.- Parameters:
x
- The x coordinate of the original vectory
- The y coordinate of the original vectorz
- The z coordinate of the original vector- Returns:
- The transformed x coordinate
-
transformY
Transforms the y coordinate of a vector using this transform. Only creates a new object on the first call.- Parameters:
vector
- The original vector- Returns:
- The transformed y coordinate
-
transformY
public int transformY(int x, int y, int z) Transforms the y coordinate of a vector using this transform. Only creates a new object on the first call.- Parameters:
x
- The x coordinate of the original vectory
- The y coordinate of the original vectorz
- The z coordinate of the original vector- Returns:
- The transformed y coordinate
-
transformZ
Transforms the z coordinate of a vector using this transform. Only creates a new object on the first call.- Parameters:
vector
- The original vector- Returns:
- The transformed z coordinate
-
transformZ
public int transformZ(int x, int y, int z) Transforms the z coordinate of a vector using this transform. Only creates a new object on the first call.- Parameters:
x
- The x coordinate of the original vectory
- The y coordinate of the original vectorz
- The z coordinate of the original vector- Returns:
- The transformed z coordinate
-
invert
Inverts the transform and returns it as a new transform.- Returns:
- The inverse of this transform
-
compose
Returns a transform that is the composition of this transform and the given transform. The result will apply this transformation after the given one.- Parameters:
that
- The transform to compose with- Returns:
- The new composed transform
-
andThen
Returns a transform that is the composition of the given transform with this transform. The result will apply the given transformation after this one.- Parameters:
that
- The transform to compose with- Returns:
- The new composed transform
-
withTranslation
Adds a translation to this transform and returns it as a new transform.- Parameters:
vector
- The translation vector- Returns:
- The translated transform as a copy
-
withTranslation
Adds a translation to this transform and returns it as a new transform.- Parameters:
x
- The x coordinate of the translationy
- The y coordinate of the translationz
- The z coordinate of the translation- Returns:
- The translated transform as a copy
-
withScale
Adds a scale factor to this transform and returns it as a new transform. This factor must be non-zero.- Parameters:
a
- The scale factor- Returns:
- The scaled transform as a copy
-
withScale
Adds a scale factor for each axis to this transform and returns it as a new transform. The factors must be non-zero.- Parameters:
vector
- The scale vector- Returns:
- The scaled transform as a copy
-
withScale
Adds a scale factor for each axis to this transform and returns it as a new transform. The factors must be non-zero.- Parameters:
x
- The scale factor on xy
- The scale factor on yz
- The scale factor on z- Returns:
- The scaled transform as a copy
-
withRotation
Adds a rotation to this transform, around an axis, around the origin and returns it as a new transform. The rotation is given is quarter turns. The actual rotation isquarterTurns * 90
. The rotation is around the block center, not the corner.- Parameters:
quarterTurns
- The number of quarter turns in this rotationaxis
- The axis to rotate around- Returns:
- The rotated transform as a copy
-
withRotation
public DiscreteTransform3 withRotation(int quarterTurns, Axis axis, Vector3i point, boolean blockCorner) Adds a a rotation to this transform, around an axis, around a given point, and returns it as a new transform. The rotation is given is quarter turns. The actual rotation isquarterTurns * 90
. The block corner flag changes the point to be the block upper corner instead of the center.- Parameters:
quarterTurns
- The number of quarter turns in this rotationaxis
- The axis to rotate aroundpoint
- The point of rotation, as block coordinatesblockCorner
- Whether or not to use the corner of the block instead of the center- Returns:
- The rotated transform as a copy
-
withRotation
public DiscreteTransform3 withRotation(int halfTurns, Axis axis, Vector3i point, boolean blockCornerX, boolean blockCornerY, boolean blockCornerZ) Adds a a rotation to this transform, around an axis, around a given point. The rotation is given is half turns. The actual rotation ishalfTurns * 180
. The block corner flags change the point to be the block corner or edge instead of the center. When all flags are false, the center is used. When only one is true the face traversed by the axis of flag is used. When two are true the edge in the direction of the remaining flag is used. When all are true the upper corner is used.- Parameters:
halfTurns
- The number of half turns in this rotationaxis
- The axis to rotate aroundpoint
- The point of rotation, as block coordinatesblockCornerX
- Whether or not to use the corner of the block instead of the center on the x axisblockCornerY
- Whether or not to use the corner of the block instead of the center on the y axisblockCornerZ
- Whether or not to use the corner of the block instead of the center on the z axis- Returns:
- The rotated transform as a copy
-
withTransformation
Adds another transformation to this transformation and returns int as a new transform.- Parameters:
transform
- The transformation to add- Returns:
- The added transforms as a copy
-
of
Returns a new transform from the given transformation matrix, if the resulting transform would be discrete.- Parameters:
matrix
- The matrix to use for the transform- Returns:
- The new transform, or
Optional.empty()
-
fromTranslation
Returns a new transform representing a translation.- Parameters:
vector
- The translation vector- Returns:
- The new translation transform
-
fromTranslation
Returns a new transform representing a translation.- Parameters:
x
- The x coordinate of the translationy
- The y coordinate of the translationz
- The z coordinate of the translation- Returns:
- The new translation transform
-
fromScale
Returns a new transform representing a scaling. The scale factor must be non-zero.- Parameters:
a
- The scale factor- Returns:
- The new scale transform
-
fromScale
Returns a new transform representing a scaling on each axis. The scale factors must be non-zero.- Parameters:
vector
- The scale vector- Returns:
- The new scale transform
-
fromScale
Returns a new transform representing a scaling on each axis. The scale factors must be non-zero.- Parameters:
x
- The scale factor on xy
- The scale factor on yz
- The scale factor on z- Returns:
- The new scale transform
-
fromRotation
Returns a new transform representing a rotation around an axis around the origin. The rotation is given is quarter turns. The actual rotation isquarterTurns * 90
. The rotation is around the block center, not the corner.- Parameters:
quarterTurns
- The number of quarter turns in this rotationaxis
- The axis to rotate around- Returns:
- The new rotation transform
-
fromRotation
public static DiscreteTransform3 fromRotation(int quarterTurns, Axis axis, Vector3i point, boolean blockCorner) Returns a new transform representing a rotation around an axis, around a given point. The rotation is given is quarter turns. The actual rotation isquarterTurns * 90
. The block corner flag change the point to be the block corner instead of the center.- Parameters:
quarterTurns
- The number of quarter turns in this rotationaxis
- The axis to rotate aroundpoint
- The point of rotation, as block coordinatesblockCorner
- Whether or not to use the corner of the block instead of the center- Returns:
- The new rotation transform
-
fromRotation
public static DiscreteTransform3 fromRotation(int halfTurns, Axis axis, Vector3i point, boolean blockCornerX, boolean blockCornerY, boolean blockCornerZ) Returns a new transform representing a rotation around an axis, around a given point. The rotation is given in half turns. The actual rotation ishalfTurns * 180
. When all flags are false, the center is used. When only one is true the face traversed by the axis of flag is used. When two are true the edge in the direction of the remaining flag is used. When all are true the upper corner is used.- Parameters:
halfTurns
- The number of half turns in this rotationaxis
- The axis to rotate aroundpoint
- The point of rotation, as block coordinatesblockCornerX
- Whether or not to use the corner of the block instead of the center on the x axisblockCornerY
- Whether or not to use the corner of the block instead of the center on the y axisblockCornerZ
- Whether or not to use the corner of the block instead of the center on the z axis- Returns:
- The new rotation transform
-
rotationAroundCenter
Returns a new transform representing a centered rotation of an volume of blocks. The rotation is given is quarter turns. The actual rotation isquarterTurns * 90
. Volumes with differing parities on the axes can only be rotated by multiples of 180 degrees.- Parameters:
quarterTurns
- The amount of quarter turns in this rotationaxis
- Axis for rotationsize
- The size of the volume to rotate- Returns:
- The new rotation transform
-