Package me.deecaad.core.utils
Class Transform
java.lang.Object
me.deecaad.core.utils.Transform
- All Implemented Interfaces:
TransformLike
- Direct Known Subclasses:
EntityTransform
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 Summary
ConstructorsConstructorDescriptionTransform(TransformLike owner) Transform(TransformLike owner, @NotNull org.bukkit.util.Vector localPosition, @NotNull org.joml.Quaterniond localRotation) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChild(@NotNull TransformLike child) voidapplyRotation(org.joml.Quaterniond rotation) static org.joml.QuaterniondfromYawPitch(float yaw, float pitch) Converts a Minecraft yaw/pitch (degrees) to a JOML rotation in the standard right-handed frame.getChild(int i) org.bukkit.util.Vectororg.bukkit.util.Vectororg.joml.Quaterniondorg.bukkit.util.Vectororg.bukkit.util.VectorgetRight()org.joml.Quaterniond@NotNull TransformThe transform node that places this object in a transform hierarchy.org.bukkit.util.VectorgetUp()static org.joml.QuaterniondlookAt(org.bukkit.util.Vector direction, org.bukkit.util.Vector up) Builds a rotation that points the local forward axis (+Z) alongdirection, with the local up axis (+Y) aligned as closely as possible toup.static floatpitch(org.joml.Quaterniondc rotation) Extracts the Minecraft pitch (degrees) from a JOML rotation.protected voidvoidremoveChild(@NotNull TransformLike child) static org.bukkit.util.Vectorrotate(org.joml.Quaterniondc rotation, org.bukkit.util.Vector vector) Rotates a BukkitVectorby a JOML quaternion, returning a new vector.voidset(@NotNull org.bukkit.util.Vector position, @NotNull org.joml.Quaterniond rotation) Sets the world position and rotation in a single update (one propagation).voidsetForward(org.bukkit.util.Vector forward) voidsetLocalPosition(org.bukkit.util.Vector localPosition) voidsetLocalRotation(org.joml.Quaterniond localRotation) voidsetParent(TransformLike parent) voidsetPosition(org.bukkit.Location position) voidsetPosition(org.bukkit.util.Vector position) voidsetRight(org.bukkit.util.Vector right) voidsetRotation(org.joml.Quaterniond rotation) voidsetUp(org.bukkit.util.Vector up) voidtick()Walks this transform and its descendants, callingTransformLike.update()on each.static floatyaw(org.joml.Quaterniondc rotation) Extracts the Minecraft yaw (degrees) from a JOML rotation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.deecaad.core.utils.TransformLike
applyTransform, update
-
Constructor Details
-
Transform
public Transform() -
Transform
-
Transform
public Transform(TransformLike owner, @NotNull @NotNull org.bukkit.util.Vector localPosition, @NotNull @NotNull org.joml.Quaterniond localRotation)
-
-
Method Details
-
getTransform
Description copied from interface:TransformLikeThe transform node that places this object in a transform hierarchy.- Specified by:
getTransformin interfaceTransformLike- Returns:
- The non-null transform.
-
getParent
-
getChild
-
getChildren
-
addChild
-
removeChild
-
setParent
-
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, callingTransformLike.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) alongdirection, with the local up axis (+Y) aligned as closely as possible toup. Ifupis parallel todirection, 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 BukkitVectorby 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 thatgetEulerAnglesYXZhits 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.
-