Class Quaternion


  • public class Quaternion
    extends java.lang.Object
    A Sceneform quaternion class for floats.

    Quaternion operations are Hamiltonian using the right-hand-rule convention.

    • Field Detail

      • x

        public float x
      • y

        public float y
      • z

        public float z
      • w

        public float w
    • Constructor Detail

      • Quaternion

        public Quaternion()
        Construct Quaternion and set to Identity
      • Quaternion

        public Quaternion​(float x,
                          float y,
                          float z,
                          float w)
        Construct Quaternion and set each value. The Quaternion will be normalized during construction
      • Quaternion

        public Quaternion​(Quaternion q)
        Construct Quaternion using values from another Quaternion
      • Quaternion

        public Quaternion​(Vector3 axis,
                          float angle)
        Construct Quaternion using an axis/angle to define the rotation
        Parameters:
        axis - Sets rotation direction
        angle - Angle size in degrees
      • Quaternion

        public Quaternion​(Vector3 eulerAngles)
        Construct Quaternion based on eulerAngles.
        Parameters:
        eulerAngles - - the angle in degrees for each axis.
        See Also:
        eulerAngles(Vector3 eulerAngles)
    • Method Detail

      • set

        public void set​(Quaternion q)
        Copy values from another Quaternion into this one
      • set

        public void set​(Vector3 axis,
                        float angle)
        Update this Quaternion using an axis/angle to define the rotation
      • set

        public void set​(float qx,
                        float qy,
                        float qz,
                        float qw)
        Set each value and normalize the Quaternion
      • setIdentity

        public void setIdentity()
        Set the Quaternion to identity
      • normalize

        public boolean normalize()
        Rescales the quaternion to the unit length.

        If the Quaternion can not be scaled, it is set to identity and false is returned.

        Returns:
        true if the Quaternion was non-zero
      • normalized

        public Quaternion normalized()
        Get a Quaternion with a matching rotation but scaled to unit length.
        Returns:
        the quaternion scaled to the unit length, or zero if that can not be done.
      • inverted

        public Quaternion inverted()
        Get a Quaternion with the opposite rotation
        Returns:
        the opposite rotation
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • rotateVector

        public static Vector3 rotateVector​(Quaternion q,
                                           Vector3 src)
        Rotates a Vector3 by a Quaternion
        Returns:
        The rotated vector
      • multiply

        public static Quaternion multiply​(Quaternion lhs,
                                          Quaternion rhs)
        Create a Quaternion by combining two Quaternions multiply(lhs, rhs) is equivalent to performing the rhs rotation then lhs rotation Ordering is important for this operation.
        Returns:
        The combined rotation
      • axisAngle

        public static Quaternion axisAngle​(Vector3 axis,
                                           float degrees)
        Get a new Quaternion using an axis/angle to define the rotation
        Parameters:
        axis - Sets rotation direction
        degrees - Angle size in degrees
      • eulerAngles

        public static Quaternion eulerAngles​(Vector3 eulerAngles)
        Get a new Quaternion using eulerAngles to define the rotation.

        The rotations are applied in Z, Y, X order. This is consistent with other graphics engines. One thing to note is the coordinate systems are different between Sceneform and Unity, so the same angles used here will have cause a different orientation than Unity. Carefully check your parameter values to get the same effect as in other engines.

        Parameters:
        eulerAngles - - the angles in degrees.
      • rotationBetweenVectors

        public static Quaternion rotationBetweenVectors​(Vector3 start,
                                                        Vector3 end)
        Get a new Quaternion representing the rotation from one vector to another.
      • lookRotation

        public static Quaternion lookRotation​(Vector3 forwardInWorld,
                                              Vector3 desiredUpInWorld)
        Get a new Quaternion representing a rotation towards a specified forward direction. If upInWorld is orthogonal to forwardInWorld, then the Y axis is aligned with desiredUpInWorld.
      • equals

        public static boolean equals​(Quaternion lhs,
                                     Quaternion rhs)
        Compare two Quaternions

        Tests for equality by calculating the dot product of lhs and rhs. lhs and -lhs will not be equal according to this function.

      • equals

        public boolean equals​(java.lang.Object other)
        Returns true if the other object is a Quaternion and the dot product is 1.0 +/- a tolerance.
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • identity

        public static Quaternion identity()
        Get a Quaternion set to identity