Class Transform

java.lang.Object
org.alban098.common.Transform
All Implemented Interfaces:
Cleanable

public final class Transform extends Object implements Cleanable
an Element allowing an Entity to be moved, scaled and rotated in the world
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final FloatBuffer
    A Buffer used to store the absolute transformation matrix for rendering
    private boolean
    A flag to indicate that a change has occurred
    private final org.joml.Vector2f
    The current displacement of the Component
    private final org.joml.Matrix4f
    The transformation matrix
    private final float[]
    An array used to store the transformation matrix before loading it to a GPU buffer
    private final org.joml.Vector2f
    The displacement to apply at the next update
    private float
    The rotation to apply at the next update
    private final org.joml.Vector2f
    The scale to apply at the next update
    private float
    The current rotation of the Component
    private final org.joml.Vector2f
    The current scale of the Component
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new Transform
    Transform(org.joml.Vector2f displacement, float scale, float rotation)
    Creates a new Transform with set values
    Transform(org.joml.Vector2f displacement, org.joml.Vector2f scale, float rotation)
    Creates a new Transform with set values
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Apply a transformation to the current one
    void
    Clears the Transform and its buffer
    void
    Updates the Transform by recomputing its matrix
    org.joml.Vector2f
    Returns the current displacement fo the Transform
    org.joml.Matrix4f
    Returns the absolute transformation matrix, with all parent transformations applied
    org.joml.Vector2f
    Returns the current scale of the Transform
    void
    move(float x, float y)
    Move the Transform a certain amount from its current position
    void
    move(org.joml.Vector2f offset)
    Move the Transform a certain amount from its current position
    void
    rotate(float angle)
    Rotates the Transform by a certain amount, and then wrap the rotation between 0 and 2*PI
    void
    scale(float scale)
    Scale the Transform by a set amount, on both axis
    void
    scale(org.joml.Vector2f scale)
    Scale the Transform by a set amount
    void
    setDisplacement(float x, float y)
    Sets the displacement of the Transform
    void
    setDisplacement(org.joml.Vector2f displacement)
    Sets the displacement of the Transform
    private void
    Applies the requested state to the current state
    void
    setRotation(float rotation)
    Sets the new rotation of the Transform around the Z axis
    void
    setScale(float x, float y)
    Sets the scale of the Transform
    void
    setScale(org.joml.Vector2f scale)
    Sets the scale of the Transform
    Returns a Buffer containing the transformation matrix
    private void
    Recomputes the transformation matrix

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.alban098.common.Cleanable

    initialize
  • Field Details

    • matrix

      private final org.joml.Matrix4f matrix
      The transformation matrix
    • buffer

      private final FloatBuffer buffer
      A Buffer used to store the absolute transformation matrix for rendering
    • matrixArray

      private final float[] matrixArray
      An array used to store the transformation matrix before loading it to a GPU buffer
    • displacement

      private final org.joml.Vector2f displacement
      The current displacement of the Component
    • scale

      private final org.joml.Vector2f scale
      The current scale of the Component
    • rotation

      private float rotation
      The current rotation of the Component
    • requestedDisplacement

      private final org.joml.Vector2f requestedDisplacement
      The displacement to apply at the next update
    • requestedScale

      private final org.joml.Vector2f requestedScale
      The scale to apply at the next update
    • requestedRotation

      private float requestedRotation
      The rotation to apply at the next update
    • change

      private boolean change
      A 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 Transform
      scale - the current scale of the Transform, applied to both axis
      rotation - 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 Transform
      scale - the current scale of the Transform
      rotation - 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

      private void applyTransform(Transform parent)
      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 displacement
      y - 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 scale
      y - 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 vector
      y - 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

      public FloatBuffer toFloatBuffer()
      Returns a Buffer containing the transformation matrix
      Returns:
      a Buffer containing the transformation matrix
    • cleanUp

      public void cleanUp()
      Clears the Transform and its buffer
      Specified by:
      cleanUp in interface Cleanable
    • 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