Package org.alban098.common
Class Transform
java.lang.Object
org.alban098.common.Transform
- All Implemented Interfaces:
Cleanable
an Element allowing an Entity to be moved, scaled and rotated in the world
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FloatBufferA Buffer used to store the absolute transformation matrix for renderingprivate booleanA flag to indicate that a change has occurredprivate final org.joml.Vector2fThe current displacement of the Componentprivate final org.joml.Matrix4fThe transformation matrixprivate final float[]An array used to store the transformation matrix before loading it to a GPU bufferprivate final org.joml.Vector2fThe displacement to apply at the next updateprivate floatThe rotation to apply at the next updateprivate final org.joml.Vector2fThe scale to apply at the next updateprivate floatThe current rotation of the Componentprivate final org.joml.Vector2fThe current scale of the Component -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidapplyTransform(Transform parent) Apply a transformation to the current onevoidcleanUp()Clears the Transform and its buffervoidcommit()Updates the Transform by recomputing its matrixorg.joml.Vector2fReturns the current displacement fo the Transformorg.joml.Matrix4fReturns the absolute transformation matrix, with all parent transformations appliedorg.joml.Vector2fgetScale()Returns the current scale of the Transformvoidmove(float x, float y) Move the Transform a certain amount from its current positionvoidmove(org.joml.Vector2f offset) Move the Transform a certain amount from its current positionvoidrotate(float angle) Rotates the Transform by a certain amount, and then wrap the rotation between 0 and 2*PIvoidscale(float scale) Scale the Transform by a set amount, on both axisvoidscale(org.joml.Vector2f scale) Scale the Transform by a set amountvoidsetDisplacement(float x, float y) Sets the displacement of the TransformvoidsetDisplacement(org.joml.Vector2f displacement) Sets the displacement of the Transformprivate voidApplies the requested state to the current statevoidsetRotation(float rotation) Sets the new rotation of the Transform around the Z axisvoidsetScale(float x, float y) Sets the scale of the TransformvoidsetScale(org.joml.Vector2f scale) Sets the scale of the TransformReturns aBuffercontaining the transformation matrixprivate voidRecomputes the transformation matrixMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.alban098.common.Cleanable
initialize
-
Field Details
-
matrix
private final org.joml.Matrix4f matrixThe transformation matrix -
buffer
A Buffer used to store the absolute transformation matrix for rendering -
matrixArray
private final float[] matrixArrayAn array used to store the transformation matrix before loading it to a GPU buffer -
displacement
private final org.joml.Vector2f displacementThe current displacement of the Component -
scale
private final org.joml.Vector2f scaleThe current scale of the Component -
rotation
private float rotationThe current rotation of the Component -
requestedDisplacement
private final org.joml.Vector2f requestedDisplacementThe displacement to apply at the next update -
requestedScale
private final org.joml.Vector2f requestedScaleThe scale to apply at the next update -
requestedRotation
private float requestedRotationThe rotation to apply at the next update -
change
private boolean changeA flag to indicate that a change has occurred
-
-
Constructor Details
-
Transform
public Transform()Creates a new Transform -
Transform
public Transform(org.joml.Vector2f displacement, float scale, float rotation) Creates a new Transform with set values- Parameters:
displacement- the current displacement of the Transformscale- the current scale of the Transform, applied to both axisrotation- the current rotation of the Transform
-
Transform
public Transform(org.joml.Vector2f displacement, org.joml.Vector2f scale, float rotation) Creates a new Transform with set values- Parameters:
displacement- the current displacement of the Transformscale- the current scale of the Transformrotation- the current rotation of the Transform
-
-
Method Details
-
setRequestedState
private void setRequestedState()Applies the requested state to the current state -
updateMatrix
private void updateMatrix()Recomputes the transformation matrix -
applyTransform
Apply a transformation to the current one- Parameters:
parent- the parent transform to apply
-
getMatrix
public org.joml.Matrix4f getMatrix()Returns the absolute transformation matrix, with all parent transformations applied- Returns:
- the absolute transformation matrix, with all parent transformations applied
-
setDisplacement
public void setDisplacement(org.joml.Vector2f displacement) Sets the displacement of the Transform- Parameters:
displacement- the new displacement of the Transform
-
setDisplacement
public void setDisplacement(float x, float y) Sets the displacement of the Transform- Parameters:
x- the x component of the new displacementy- the y component of the new displacement
-
setScale
public void setScale(org.joml.Vector2f scale) Sets the scale of the Transform- Parameters:
scale- the new scale of the Transform
-
setScale
public void setScale(float x, float y) Sets the scale of the Transform- Parameters:
x- the x component of the new scaley- the y component of the new scale
-
setRotation
public void setRotation(float rotation) Sets the new rotation of the Transform around the Z axis- Parameters:
rotation- the new rotation of the Transform around the Z axis
-
move
public void move(org.joml.Vector2f offset) Move the Transform a certain amount from its current position- Parameters:
offset- the amount to move the Transform
-
move
public void move(float x, float y) Move the Transform a certain amount from its current position- Parameters:
x- the x component of the offset vectory- the y component of the offset vector
-
scale
public void scale(float scale) Scale the Transform by a set amount, on both axis- Parameters:
scale- the amount to scale
-
scale
public void scale(org.joml.Vector2f scale) Scale the Transform by a set amount- Parameters:
scale- the amount to scale
-
rotate
public void rotate(float angle) Rotates the Transform by a certain amount, and then wrap the rotation between 0 and 2*PI- Parameters:
angle- the amount to rotate
-
toFloatBuffer
Returns aBuffercontaining the transformation matrix- Returns:
- a
Buffercontaining the transformation matrix
-
cleanUp
public void cleanUp()Clears the Transform and its buffer -
commit
public void commit()Updates the Transform by recomputing its matrix -
getDisplacement
public org.joml.Vector2f getDisplacement()Returns the current displacement fo the Transform- Returns:
- the current displacement fo the Transform
-
getScale
public org.joml.Vector2f getScale()Returns the current scale of the Transform- Returns:
- the current scale of the Transform
-