- Object
-
- Transform
-
- All Implemented Interfaces:
Copyable<Transform>
,Rotatable
,Transformable
,Translatable
public class Transform extends Object implements Transformable, Copyable<Transform>
Represents a transformation matrix.Supported operations are rotation and translation.
- Since:
- 1.0.0
- Version:
- 4.0.0
- Author:
- William Bittle
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Transform
copy()
Returns a deep copy of this object.Vector2
getInverseTransformed(Vector2 vector)
void
getInverseTransformed(Vector2 vector, Vector2 destination)
Vector2
getInverseTransformedR(Vector2 vector)
void
getInverseTransformedR(Vector2 vector, Vector2 destination)
Rotation
getRotation()
double
getRotationAngle()
Returns the rotation.Transform
getRotationTransform()
Vector2
getTransformed(Vector2 vector)
void
getTransformed(Vector2 vector, Vector2 destination)
Transforms the givenVector2
and returns the result in dest.Vector2
getTransformedR(Vector2 vector)
void
getTransformedR(Vector2 vector, Vector2 destination)
double
getTransformedX(Vector2 vector)
Transforms only the x coordinate of the givenVector2
and returns the result.double
getTransformedY(Vector2 vector)
Transforms only the y coordinate of the givenVector2
and returns the result.Vector2
getTranslation()
Returns the translationVector2
.Transform
getTranslationTransform()
double
getTranslationX()
Returns the x translation.double
getTranslationY()
Returns the x translation.double[]
getValues()
Returns the values stored in this transform.void
identity()
Sets thisTransform
to the identity.void
inverseTransform(Vector2 vector)
void
inverseTransformR(Vector2 vector)
boolean
isIdentity()
Returns true if thisTransform
is an identity transform.void
lerp(Transform end, double alpha)
Interpolates this transform linearly by alpha towards the given end transform.void
lerp(Transform end, double alpha, Transform result)
Interpolates linearly by alpha towards the given end transform placing the result in the given transform.void
lerp(Vector2 dp, double da, double alpha)
Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa).void
lerp(Vector2 dp, double da, double alpha, Transform result)
Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa) and places it into result.Transform
lerped(Transform end, double alpha)
Interpolates linearly by alpha towards the given end transform returning a new transform containing the result.Transform
lerped(Vector2 dp, double da, double alpha)
Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa) and returns the result.void
rotate(double theta)
Rotates the object about the origin.void
rotate(double theta, double x, double y)
Rotates the object about the given coordinates.void
rotate(double theta, Vector2 point)
Rotates the object about the given point.void
rotate(Rotation rotation)
Rotates the object about the origin.void
rotate(Rotation rotation, double x, double y)
Rotates the object about the given point.void
rotate(Rotation rotation, Vector2 point)
Rotates the object about the given point.void
set(Transform transform)
Sets this transform to the given transform.double
setRotation(double theta)
Sets the rotation and returns the previous rotation.Rotation
setRotation(Rotation rotation)
Sets the rotation and returns the previous rotation.void
setTranslation(double x, double y)
Sets the translation.void
setTranslation(Vector2 translation)
Sets the translation.void
setTranslationX(double x)
Sets the translation along the x axis.void
setTranslationY(double y)
Sets the translation along the y axis.String
toString()
void
transform(Vector2 vector)
void
transformR(Vector2 vector)
void
transformX(Vector2 vector)
void
transformY(Vector2 vector)
void
translate(double x, double y)
Translates the object the given amounts in the respective directions.void
translate(Vector2 vector)
Translates the object along the given vector.
-
-
-
Field Detail
-
IDENTITY
@Deprecated public static final Transform IDENTITY
Deprecated.create your own instances ofTransform
instead; since 3.4.0NOTE: as of being deprecated this instance is no longer immutable.
-
-
Constructor Detail
-
Transform
public Transform()
Default public constructor
-
Transform
public Transform(Transform transform)
Public copy constructor constructor- Parameters:
transform
- the transform to copy- Since:
- 3.4.0
-
-
Method Detail
-
rotate
public void rotate(double theta)
Description copied from interface:Rotatable
Rotates the object about the origin.
-
rotate
public void rotate(Rotation rotation)
Description copied from interface:Rotatable
Rotates the object about the origin.
-
rotate
public void rotate(double theta, double x, double y)
Description copied from interface:Rotatable
Rotates the object about the given coordinates.
-
rotate
public void rotate(Rotation rotation, double x, double y)
Description copied from interface:Rotatable
Rotates the object about the given point.
-
rotate
public void rotate(double theta, Vector2 point)
Description copied from interface:Rotatable
Rotates the object about the given point.
-
rotate
public void rotate(Rotation rotation, Vector2 point)
Description copied from interface:Rotatable
Rotates the object about the given point.
-
translate
public void translate(double x, double y)
Description copied from interface:Translatable
Translates the object the given amounts in the respective directions.- Specified by:
translate
in interfaceTranslatable
- Parameters:
x
- the translation in the x directiony
- the translation in the y direction
-
translate
public void translate(Vector2 vector)
Description copied from interface:Translatable
Translates the object along the given vector.- Specified by:
translate
in interfaceTranslatable
- Parameters:
vector
- the translation along a vector
-
copy
public Transform copy()
Description copied from interface:Copyable
Returns a deep copy of this object.
-
set
public void set(Transform transform)
Sets this transform to the given transform.- Parameters:
transform
- the transform to copy- Since:
- 1.1.0
-
identity
public void identity()
Sets thisTransform
to the identity.
-
isIdentity
public boolean isIdentity()
Returns true if thisTransform
is an identity transform.- Returns:
- boolean
- Since:
- 4.0.0
-
getTransformedX
public double getTransformedX(Vector2 vector)
Transforms only the x coordinate of the givenVector2
and returns the result.- Parameters:
vector
- theVector2
to transform- Returns:
- the transformed x coordinate
- Since:
- 3.4.0
-
getTransformedY
public double getTransformedY(Vector2 vector)
Transforms only the y coordinate of the givenVector2
and returns the result.- Parameters:
vector
- theVector2
to transform- Returns:
- the transformed y coordinate
- Since:
- 3.4.0
-
transformX
public void transformX(Vector2 vector)
Transforms only the x coordinate of the givenVector2
and places the result in the x field of the givenVector2
.- Parameters:
vector
- theVector2
to transform- Since:
- 3.4.0
-
transformY
public void transformY(Vector2 vector)
Transforms only the y coordinate of the givenVector2
and places the result in the y field of the givenVector2
.- Parameters:
vector
- theVector2
to transform- Since:
- 3.4.0
-
getTransformed
public void getTransformed(Vector2 vector, Vector2 destination)
Transforms the givenVector2
and returns the result in dest.
-
inverseTransform
public void inverseTransform(Vector2 vector)
- Parameters:
vector
- theVector2
to transform
-
inverseTransformR
public void inverseTransformR(Vector2 vector)
- Parameters:
vector
- theVector2
to transform
-
getTranslationX
public double getTranslationX()
Returns the x translation.- Returns:
- double
-
setTranslationX
public void setTranslationX(double x)
Sets the translation along the x axis.- Parameters:
x
- the translation along the x axis- Since:
- 1.2.0
-
getTranslationY
public double getTranslationY()
Returns the x translation.- Returns:
- double
-
setTranslationY
public void setTranslationY(double y)
Sets the translation along the y axis.- Parameters:
y
- the translation along the y axis- Since:
- 1.2.0
-
setTranslation
public void setTranslation(double x, double y)
Sets the translation.- Parameters:
x
- the translation along the x axisy
- the translation along the y axis- Since:
- 1.2.0
-
setTranslation
public void setTranslation(Vector2 translation)
Sets the translation.- Parameters:
translation
- the translation along both axes- Since:
- 1.2.0
-
getRotationAngle
public double getRotationAngle()
Returns the rotation.- Returns:
- double angle in the range [-π, π]
-
getRotation
public Rotation getRotation()
-
setRotation
public double setRotation(double theta)
Sets the rotation and returns the previous rotation.- Parameters:
theta
- the angle in radians- Returns:
- double the old rotation in radians in the range [-π, π]
- Since:
- 3.1.0
-
setRotation
public Rotation setRotation(Rotation rotation)
Sets the rotation and returns the previous rotation.
-
getValues
public double[] getValues()
Returns the values stored in this transform.The values are in the order of 00, 01, x, 10, 11, y.
- Returns:
- double[]
- Since:
- 3.0.1
-
lerp
public void lerp(Transform end, double alpha)
Interpolates this transform linearly by alpha towards the given end transform.Interpolating from one angle to another can have two results depending on the direction of the rotation. If a rotation was from 30 to 200 the rotation could be 170 or -190. This interpolation method will always choose the smallest rotation (regardless of sign) as the rotation direction.
- Parameters:
end
- the end transformalpha
- the amount to interpolate- Since:
- 1.2.0
-
lerp
public void lerp(Transform end, double alpha, Transform result)
Interpolates linearly by alpha towards the given end transform placing the result in the given transform.Interpolating from one angle to another can have two results depending on the direction of the rotation. If a rotation was from 30 to 200 the rotation could be 170 or -190. This interpolation method will always choose the smallest rotation (regardless of sign) as the rotation direction.
- Parameters:
end
- the end transformalpha
- the amount to interpolateresult
- the transform to place the result- Since:
- 1.2.0
-
lerp
public void lerp(Vector2 dp, double da, double alpha, Transform result)
Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa) and places it into result.- Parameters:
dp
- the change in positionda
- the change in anglealpha
- the amount to interpolateresult
- the transform to place the result- Since:
- 3.1.5
-
lerp
public void lerp(Vector2 dp, double da, double alpha)
Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa).- Parameters:
dp
- the change in positionda
- the change in anglealpha
- the amount to interpolate- Since:
- 3.1.5
-
lerped
public Transform lerped(Vector2 dp, double da, double alpha)
Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa) and returns the result.- Parameters:
dp
- the change in positionda
- the change in anglealpha
- the amount to interpolate- Returns:
Transform
- Since:
- 3.1.5
-
lerped
public Transform lerped(Transform end, double alpha)
Interpolates linearly by alpha towards the given end transform returning a new transform containing the result.Interpolating from one angle to another can have two results depending on the direction of the rotation. If a rotation was from 30 to 200 the rotation could be 170 or -190. This interpolation method will always choose the smallest rotation (regardless of sign) as the rotation direction.
- Parameters:
end
- the end transformalpha
- the amount to interpolate- Returns:
Transform
the resulting transform- Since:
- 1.2.0
-
-