Klasse Quaternion

java.lang.Object
net.risingworld.api.utils.Quaternion
Alle implementierten Schnittstellen:
Serializable

public class Quaternion extends Object implements Serializable
A quaternion which describes a rotation.
Siehe auch:
  • Feldübersicht

    Felder
    Modifizierer und Typ
    Feld
    Beschreibung
    static final Quaternion
    A quaternion representing no rotation
    float
    The W value of this Quaternion (scalar part)
    float
    The X value of this Quaternion (vector part)
    float
    The Y value of this Quaternion (vector part)
    float
    The Z value of this Quaternion (vector part)
    static final Quaternion
    An "empty" quaternion.
  • Konstruktorübersicht

    Konstruktoren
    Konstruktor
    Beschreibung
     
    Quaternion(float x, float y, float z, float w)
     
     
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    float
    angle(Quaternion quaternion)
    Gets the angle (in degrees) between this quaternion and the other quaternion.
    Creates a copy of this Quaternion.
    float
    dot(Quaternion quaternion)
    Gets the dot product of this quaternion with the provided quaternion.
    boolean
    equals(float x, float y, float z, float w)
     
    boolean
    Gets whether or not this quaternion is equal to another object.
    fromAngles(float[] angles)
    Calculates this quaternion from the given Euler rotation angles (pitch, yaw, roll) aka (attitude, heading, bank) aka (x, y, z).
    fromAngles(float pitch, float yaw, float roll)
    Calculates this quaternion from the given Euler rotation angles (pitch, yaw, roll) aka (attitude, heading, bank) aka (x, y, z).
     
    float
    Gets the pitch (aka attitude aka x euler angle) of this quaternion.
    float
    Gets the roll (aka bank aka z euler angle) of this quaternion.
    float
    Returns the W value of this Quaternion.
    float
    Returns the X value of this Quaternion.
    float
    Returns the Y value of this Quaternion.
    float
    Gets the yaw (aka heading aka y euler angle) of this quaternion.
    float
    Returns the Z value of this Quaternion.
    int
    Gets a unique* hash code for this quaternion, based on its values.
    Gets the inverse of this quaternion as a new quaternion.
    Calculates the inverse of this quaternion and stores the result in this quaternion.
    boolean
    Checks if this quaternion is invalid, or more precisely, if any of its values is NaN (not a number).
    Sets this quaternion to 0, 0, 0, 1.
    lookAt(float directionx, float directiony, float directionz)
    "Looks at" a given direction, i.e the quaternion will be set based on the direction.
    lookAt(Vector3f direction)
    "Looks at" a given direction, i.e the quaternion will be set based on the direction.
    lookAt(Vector3f direction, Vector3f up)
    "Looks at" a given direction, i.e the quaternion will be set based on the direction and an up vector.
    mult(Vector3f vector)
    Multiplies the quaternion by a Vector3f.
    multLocal(float scalar)
    Multiplies the quaternion by a scalar.
    multLocal(float qx, float qy, float qz, float qw)
    Multiplies this quaternion by the provided values.
    multLocal(Quaternion quaternion)
    Multiplies this quaternion by the provided quaternion.
    Multiplies the quaternion by a Vector3f.
    Negates the values of this quaternion.
    float
    Gets the norm of this quaternion, i.e the dot product of this quaternion with itself.
    Gets the normalized quaternion as a new quaternion.
    Normalizes this quaternion.
    set(float x, float y, float z, float w)
    Sets the X, Y, Z and W values of this Quaternion to the provided values.
    set(Quaternion quaternion)
    Sets the X, Y, Z and W values of this Quaternion to the values of the provided quaternion.
    setW(float w)
    Sets the Z value of this Quaternion.
    setX(float x)
    Sets the X value of this Vector3f.
    setY(float y)
    Sets the Y value of this Vector3f.
    setZ(float z)
    Sets the Z value of this Quaternion.
    float[]
    Calculates the according Euler rotation angles (pitch, yaw, roll) for this quaternion and stores them in the provided float array.
    float[]
    toAngles(float[] storeTo)
    Calculates the according Euler rotation angles (pitch, yaw, roll) for this quaternion and stores them in the provided float array.
    Gets a String representation of this quaternion, for example (0.0, 1.25, -0.7, 1.0)

    Von Klasse geerbte Methoden java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Felddetails

    • IDENTITY

      public static final Quaternion IDENTITY
      A quaternion representing no rotation
    • ZERO

      public static final Quaternion ZERO
      An "empty" quaternion. If you're looking for a quaternion with no rotation instead, check out IDENTITY
    • x

      public float x
      The X value of this Quaternion (vector part)
    • y

      public float y
      The Y value of this Quaternion (vector part)
    • z

      public float z
      The Z value of this Quaternion (vector part)
    • w

      public float w
      The W value of this Quaternion (scalar part)
  • Konstruktordetails

    • Quaternion

      public Quaternion()
    • Quaternion

      public Quaternion(float x, float y, float z, float w)
    • Quaternion

      public Quaternion(Quaternion copy)
  • Methodendetails

    • copy

      public Quaternion copy()
      Creates a copy of this Quaternion.
      Gibt zurück:
      a new instance with the same values of this Quaternion.
    • set

      public Quaternion set(Quaternion quaternion)
      Sets the X, Y, Z and W values of this Quaternion to the values of the provided quaternion.
      Parameter:
      quaternion - the Quaternion to copy.
      Gibt zurück:
      this Quaternion.
    • set

      public Quaternion set(float x, float y, float z, float w)
      Sets the X, Y, Z and W values of this Quaternion to the provided values.
      Parameter:
      x - the X value.
      y - the Y value.
      z - the Z value.
      w - the W value.
      Gibt zurück:
      this Quaternion.
    • setX

      public Quaternion setX(float x)
      Sets the X value of this Vector3f.
      Parameter:
      x - the new X value.
      Gibt zurück:
      this Vector3f.
    • setY

      public Quaternion setY(float y)
      Sets the Y value of this Vector3f.
      Parameter:
      y - the new Y value.
      Gibt zurück:
      this Vector3f.
    • setZ

      public Quaternion setZ(float z)
      Sets the Z value of this Quaternion.
      Parameter:
      z - the new Z value.
      Gibt zurück:
      this Quaternion.
    • setW

      public Quaternion setW(float w)
      Sets the Z value of this Quaternion.
      Parameter:
      w - the new W value.
      Gibt zurück:
      this Quaternion.
    • getX

      public float getX()
      Returns the X value of this Quaternion.
      Gibt zurück:
      the current X value.
    • getY

      public float getY()
      Returns the Y value of this Quaternion.
      Gibt zurück:
      the current Y value.
    • getZ

      public float getZ()
      Returns the Z value of this Quaternion.
      Gibt zurück:
      the current Z value.
    • getW

      public float getW()
      Returns the W value of this Quaternion.
      Gibt zurück:
      the current W value.
    • getPitch

      public float getPitch()
      Gets the pitch (aka attitude aka x euler angle) of this quaternion.
      Gibt zurück:
      the pitch/attitude as euler angle in degrees.
    • getYaw

      public float getYaw()
      Gets the yaw (aka heading aka y euler angle) of this quaternion.
      Gibt zurück:
      the yaw/heading as euler angle in degrees.
    • getRoll

      public float getRoll()
      Gets the roll (aka bank aka z euler angle) of this quaternion.
      Gibt zurück:
      the roll/bank as euler angle in degrees.
    • loadIdentity

      public Quaternion loadIdentity()
      Sets this quaternion to 0, 0, 0, 1. i.e it does no longer represent any rotation.
      Gibt zurück:
      this quaternion.
    • fromAngles

      public Quaternion fromAngles(float[] angles)
      Calculates this quaternion from the given Euler rotation angles (pitch, yaw, roll) aka (attitude, heading, bank) aka (x, y, z). The rotation will be applied in the order: y, z, x
      Parameter:
      angles - Euler rotation angles (pitch, yaw, roll) in degrees as a float array.
      Gibt zurück:
      this quaternion.
    • fromAngles

      public Quaternion fromAngles(float pitch, float yaw, float roll)
      Calculates this quaternion from the given Euler rotation angles (pitch, yaw, roll) aka (attitude, heading, bank) aka (x, y, z). The rotation will be applied in the order: x, y, z
      Parameter:
      pitch - Euler pitch (attitude) rotation in degrees.
      yaw - Euler yaw (heading) rotation in degrees.
      roll - Euler roll (bank) rotation in degrees.
      Gibt zurück:
      this quaternion.
      Siehe auch:
    • toAngles

      public float[] toAngles()
      Calculates the according Euler rotation angles (pitch, yaw, roll) for this quaternion and stores them in the provided float array.
      Gibt zurück:
      a float array containing the Euler angles (pitch, yaw, roll).
    • toAngles

      public float[] toAngles(float[] storeTo)
      Calculates the according Euler rotation angles (pitch, yaw, roll) for this quaternion and stores them in the provided float array. The angles are stored in degrees.
      Parameter:
      storeTo - the float array in which the angles should be stored. This array needs to be able to hold at least three elements. If null is provided, a new float array will be created.
      Gibt zurück:
      the float array containing the Euler angles (in degrees).
      Siehe auch:
    • angle

      public float angle(Quaternion quaternion)
      Gets the angle (in degrees) between this quaternion and the other quaternion.
      Parameter:
      quaternion - the other quaternion.
      Gibt zurück:
      the angle between the two quaternions (in degrees).
    • multLocal

      public Quaternion multLocal(Quaternion quaternion)
      Multiplies this quaternion by the provided quaternion. The result is stored in this quaternion.
      Parameter:
      quaternion - the quaternion to multiply this one by.
      Gibt zurück:
      this quaternion.
    • multLocal

      public Quaternion multLocal(float qx, float qy, float qz, float qw)
      Multiplies this quaternion by the provided values. The result is stored in this quaternion.
      Parameter:
      qx - the x compontent to multiply this quaternion by.
      qy - the y compontent to multiply this quaternion by.
      qz - the z compontent to multiply this quaternion by.
      qw - the w compontent to multiply this quaternion by.
      Gibt zurück:
      this quaternion.
    • multLocal

      public Quaternion multLocal(float scalar)
      Multiplies the quaternion by a scalar. The result is stored in this quaternion.
      Parameter:
      scalar - the scalar value.
      Gibt zurück:
      this quaternion.
    • multLocal

      public Vector3f multLocal(Vector3f vector)
      Multiplies the quaternion by a Vector3f. The result is stored in the vector. You can use this method to apply a rotation (represented by the quaternion) to a vector.
      Parameter:
      vector - the Vector3f to multiply this quaternion by.
      Gibt zurück:
      the vector.
    • mult

      public Vector3f mult(Vector3f vector)
      Multiplies the quaternion by a Vector3f. The result is returned as a new vector. You can use this method to apply a rotation (represented by the quaternion) to a vector.
      Parameter:
      vector - the Vector3f to multiply this quaternion by.
      Gibt zurück:
      a new vector.
      Example: Turn a rotation in a direction
      1//Get an arbitrary rotation
      2Quaternion rotation = new Quaternion().fromAngles(45f, 90f, 0f);
      3
      4//Apply rotation to a vector to get a direction (unit vector)
      5Vector3f direction = rotation.mult(Vector3f.FORWARD);
    • negateLocal

      public Quaternion negateLocal()
      Negates the values of this quaternion.
      Gibt zurück:
      this quaternion.
    • inverse

      public Quaternion inverse()
      Gets the inverse of this quaternion as a new quaternion. The inverse quaternion represents the same rotation, but in the opposite direction.
      If this quaternion does not have an inverse, null is returned.
      Gibt zurück:
      a new quaternion containing the inverse of this quaternion, or null if there is no inverse for this quaternion.
    • inverseLocal

      public Quaternion inverseLocal()
      Calculates the inverse of this quaternion and stores the result in this quaternion. The inverse quaternion represents the same rotation, but in the opposite direction.
      If this quaternion does not have an inverse, nothing happens.
      Gibt zurück:
      this quaternion containing the inverse of this quaternion.
    • normalize

      public Quaternion normalize()
      Gets the normalized quaternion as a new quaternion.
      Gibt zurück:
      a new quaternion containing the normalized values of this quaternion.
    • normalizeLocal

      public Quaternion normalizeLocal()
      Normalizes this quaternion.
      Gibt zurück:
      this quaternion.
    • dot

      public float dot(Quaternion quaternion)
      Gets the dot product of this quaternion with the provided quaternion.
      Parameter:
      quaternion - the quaternion to calculate the dot product with.
      Gibt zurück:
      the dot product.
    • norm

      public float norm()
      Gets the norm of this quaternion, i.e the dot product of this quaternion with itself.
      Gibt zurück:
      the norm of this quaternion.
    • lookAt

      public Quaternion lookAt(Vector3f direction)
      "Looks at" a given direction, i.e the quaternion will be set based on the direction. The resulting quaternion represents the rotation for transforming a z-axis to point into the given direction.
      Parameter:
      direction - the direction (where to "look at").
      Gibt zurück:
      this quaternion.
      Example:
      1//Our target position
      2Vector3f targetPosition = ...;
      3
      4//Our start position (e.g player position)
      5Vector3f startPosition = player.getPosition();
      6
      7//Calculate "target-start" to get a direction vector from start to target
      8Vector3f direction = targetPosition.subtract(startPosition);
      9
      10//Normalize the vector, i.e turn it into a unit vector
      11direction.normalizeLocal();
      12
      13//Create a new quaternion looking at this direction
      14Quaternion rotation = new Quaternion().lookAt(direction);

      Example: Simplified version
      1//Use Utils method to calculate direction
      2Vector3f direction = Utils.VectorUtils.getDirection(startPosition, targetPosition);
      3
      4//Create a new quaternion looking at this direction
      5Quaternion rotation = new Quaternion().lookAt(direction);
    • lookAt

      public Quaternion lookAt(float directionx, float directiony, float directionz)
      "Looks at" a given direction, i.e the quaternion will be set based on the direction. The resulting quaternion represents the rotation for transforming a z-axis to point into the given direction.
      Parameter:
      directionx - the x component of the direction vector.
      directiony - the y component of the direction vector.
      directionz - the z component of the direction vector.
      Gibt zurück:
      this quaternion.
      Siehe auch:
    • lookAt

      public Quaternion lookAt(Vector3f direction, Vector3f up)
      "Looks at" a given direction, i.e the quaternion will be set based on the direction and an up vector. The resulting quaternion represents the rotation for transforming a z-axis to point into the given direction.
      Parameter:
      direction - the direction (where to "look at").
      up - the according up-vector, typically (0, 1, 0);
      Gibt zurück:
      this quaternion.
      Siehe auch:
    • isNaN

      public boolean isNaN()
      Checks if this quaternion is invalid, or more precisely, if any of its values is NaN (not a number).
      Gibt zurück:
      true if this quaternion contains any NaN values, false if not.
    • equals

      public boolean equals(float x, float y, float z, float w)
    • equals

      public boolean equals(Object o)
      Gets whether or not this quaternion is equal to another object. This function returns true, if the other object is a Quaternion and if it has exactly the same x, y, z and w values.
      Setzt außer Kraft:
      equals in Klasse Object
      Parameter:
      o - the object to compare for equality.
      Gibt zurück:
      true if the other object is a Quaternion and has the same values as this quaternion, false if not.
    • hashCode

      public int hashCode()
      Gets a unique* hash code for this quaternion, based on its values. If two quaternions have the same x, y, z and w values, they will return the same hash code.

      * Please keep in mind that the uniqueness is not fully reliable. There is always a small chance that collisions occur (i.e two completely different quaternions return the same hash code). But usually the reliability is sufficient.
      Setzt außer Kraft:
      hashCode in Klasse Object
      Gibt zurück:
      the hash code for this quaternion.
    • toString

      public String toString()
      Gets a String representation of this quaternion, for example (0.0, 1.25, -0.7, 1.0)
      Setzt außer Kraft:
      toString in Klasse Object
      Gibt zurück:
      a string representing the values of this quaternion.
    • fromString

      public Quaternion fromString(String input)