Class Transform

java.lang.Object
me.deecaad.core.utils.Transform
All Implemented Interfaces:
TransformLike
Direct Known Subclasses:
EntityTransform

public class Transform extends Object implements TransformLike
A node in a transform hierarchy: a local position and rotation that may inherit from a parent. Rotation math is backed by JOML's Quaterniond.

Mutating a transform propagates to its owner and cascades down to all children, calling TransformLike.applyTransform() on each.

  • Constructor Details

    • Transform

      public Transform()
    • Transform

      public Transform(TransformLike owner)
    • Transform

      public Transform(TransformLike owner, @NotNull @NotNull org.bukkit.util.Vector localPosition, @NotNull @NotNull org.joml.Quaterniond localRotation)
  • Method Details

    • getTransform

      @NotNull public @NotNull Transform getTransform()
      Description copied from interface: TransformLike
      The transform node that places this object in a transform hierarchy.
      Specified by:
      getTransform in interface TransformLike
      Returns:
      The non-null transform.
    • getParent

      public TransformLike getParent()
    • getChild

      public TransformLike getChild(int i)
    • getChildren

      public List<TransformLike> getChildren()
    • addChild

      public void addChild(@NotNull @NotNull TransformLike child)
    • removeChild

      public void removeChild(@NotNull @NotNull TransformLike child)
    • setParent

      public void setParent(TransformLike parent)
    • getForward

      public org.bukkit.util.Vector getForward()
    • setForward

      public void setForward(org.bukkit.util.Vector forward)
    • getRight

      public org.bukkit.util.Vector getRight()
    • setRight

      public void setRight(org.bukkit.util.Vector right)
    • getUp

      public org.bukkit.util.Vector getUp()
    • setUp

      public void setUp(org.bukkit.util.Vector up)
    • getLocalPosition

      public org.bukkit.util.Vector getLocalPosition()
    • setLocalPosition

      public void setLocalPosition(org.bukkit.util.Vector localPosition)
    • getPosition

      public org.bukkit.util.Vector getPosition()
    • setPosition

      public void setPosition(org.bukkit.Location position)
    • setPosition

      public void setPosition(org.bukkit.util.Vector position)
    • getLocalRotation

      public org.joml.Quaterniond getLocalRotation()
    • setLocalRotation

      public void setLocalRotation(org.joml.Quaterniond localRotation)
    • getRotation

      public org.joml.Quaterniond getRotation()
    • setRotation

      public void setRotation(org.joml.Quaterniond rotation)
    • applyRotation

      public void applyRotation(org.joml.Quaterniond rotation)
    • set

      public void set(@NotNull @NotNull org.bukkit.util.Vector position, @NotNull @NotNull org.joml.Quaterniond rotation)
      Sets the world position and rotation in a single update (one propagation).
      Parameters:
      position - The non-null world position.
      rotation - The non-null world rotation.
    • propagate

      protected void propagate()
    • tick

      public void tick()
      Walks this transform and its descendants, calling TransformLike.update() on each. Intended to be invoked once per tick by an external ticking system.
    • lookAt

      public static org.joml.Quaterniond lookAt(org.bukkit.util.Vector direction, org.bukkit.util.Vector up)
      Builds a rotation that points the local forward axis (+Z) along direction, with the local up axis (+Y) aligned as closely as possible to up. If up is parallel to direction, an arbitrary perpendicular axis is chosen instead.
      Parameters:
      direction - The direction the local +Z axis should point.
      up - The reference up direction.
      Returns:
      A non-null JOML quaternion.
    • rotate

      public static org.bukkit.util.Vector rotate(org.joml.Quaterniondc rotation, org.bukkit.util.Vector vector)
      Rotates a Bukkit Vector by a JOML quaternion, returning a new vector.
      Parameters:
      rotation - The non-null rotation to apply.
      vector - The non-null vector to rotate (not modified).
      Returns:
      A new rotated vector.
    • fromYawPitch

      public static org.joml.Quaterniond fromYawPitch(float yaw, float pitch)
      Converts a Minecraft yaw/pitch (degrees) to a JOML rotation in the standard right-handed frame.
      Parameters:
      yaw - The Minecraft yaw, in degrees.
      pitch - The Minecraft pitch, in degrees.
      Returns:
      A non-null JOML quaternion.
    • yaw

      public static float yaw(org.joml.Quaterniondc rotation)
      Extracts the Minecraft yaw (degrees) from a JOML rotation. Computed from the rotated forward vector to avoid the gimbal lock that getEulerAnglesYXZ hits at pitch = ±90°.
      Parameters:
      rotation - The non-null rotation.
      Returns:
      The Minecraft yaw, in degrees.
    • pitch

      public static float pitch(org.joml.Quaterniondc rotation)
      Extracts the Minecraft pitch (degrees) from a JOML rotation.
      Parameters:
      rotation - The non-null rotation.
      Returns:
      The Minecraft pitch, in degrees.