Package org.lwjgl.util.vector

# Class Quaternion

java.lang.Object
org.lwjgl.util.vector.Vector
org.lwjgl.util.vector.Quaternion

All Implemented Interfaces:
  `Serializable`, `ReadableVector`, `ReadableVector2f`, `ReadableVector3f`, `ReadableVector4f`

public class Quaternion extends Vector implements ReadableVector4f

See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`float`
`w`
`float`
`x`
`float`
`y`
`float`
`z`

## Constructor Summary

Constructors
Constructor
Description
`Quaternion()`
C'tor.
`Quaternion(float x, float y, float z, float w)`
C'tor
`Quaternion(ReadableVector4f src)`
C'tor

## Method Summary

Modifier and Type
Method
Description
`static float`
`dot(Quaternion left, Quaternion right)`
The dot product of two quaternions
`float`
`getW()`
`final float`
`getX()`
`final float`
`getY()`
`float`
`getZ()`
`float`
`lengthSquared()`
`Vector`
`load(FloatBuffer buf)`
Load this vector from a FloatBuffer
`static Quaternion`
`mul(Quaternion left, Quaternion right, Quaternion dest)`
Sets the value of this quaternion to the quaternion product of quaternions left and right (this = left * right).
`static Quaternion`
`mulInverse(Quaternion left, Quaternion right, Quaternion dest)`
Multiplies quaternion left by the inverse of quaternion right and places the value into this quaternion.
`Vector`
`negate()`
Calculate the conjugate of this quaternion
`Quaternion`
`negate(Quaternion dest)`
Calculate the conjugate of this quaternion and put it into the given one
`static Quaternion`
`negate(Quaternion src, Quaternion dest)`
Calculate the conjugate of this quaternion and put it into the given one
`Quaternion`
`normalise(Quaternion dest)`
Normalise this quaternion and place the result in another quaternion.
`static Quaternion`
`normalise(Quaternion src, Quaternion dest)`
Normalise the source quaternion and place the result in another quaternion.
`Vector`
`scale(float scale)`
Scale this vector
`static Quaternion`
`scale(float scale, Quaternion src, Quaternion dest)`
Scale the source quaternion by scale and put the result in the destination
`void`
`set(float x, float y)`
`void`
`set(float x, float y, float z)`
`void`
`set(float x, float y, float z, float w)`
`Quaternion`
`set(ReadableVector4f src)`
Load from another Vector4f
`final void`
`setFromAxisAngle(Vector4f a1)`
Sets the value of this quaternion to the equivalent rotation of the Axis-Angle argument.
`final Quaternion`
`setFromMatrix(Matrix3f m)`
Sets the value of this quaternion using the rotational component of the passed matrix.
`static Quaternion`
`setFromMatrix(Matrix3f m, Quaternion q)`
Sets the value of the source quaternion using the rotational component of the passed matrix.
`final Quaternion`
`setFromMatrix(Matrix4f m)`
Sets the value of this quaternion using the rotational component of the passed matrix.
`static Quaternion`
`setFromMatrix(Matrix4f m, Quaternion q)`
Sets the value of the source quaternion using the rotational component of the passed matrix.
`Quaternion`
`setIdentity()`
Set this quaternion to the multiplication identity.
`static Quaternion`
`setIdentity(Quaternion q)`
Set the given quaternion to the multiplication identity.
`void`
`setW(float w)`
Set W
`final void`
`setX(float x)`
Set X
`final void`
`setY(float y)`
Set Y
`void`
`setZ(float z)`
Set Z
`Vector`
`store(FloatBuffer buf)`
Store this vector in a FloatBuffer
`String`
`toString()`

### Methods inherited from class org.lwjgl.util.vector.Vector

`length, normalise`

### Methods inherited from class java.lang.Object

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

### Methods inherited from interface org.lwjgl.util.vector.ReadableVector

`length`

## Field Details

### x

public float x

### y

public float y

### z

public float z

### w

public float w

## Constructor Details

### Quaternion

public Quaternion()
C'tor. The quaternion will be initialized to the identity.

### Quaternion

public Quaternion(ReadableVector4f src)
C'tor

Parameters:
  `src` -

### Quaternion

public Quaternion(float x, float y, float z, float w)
C'tor

## Method Details

### set

public void set(float x, float y)

### set

public void set(float x, float y, float z)

### set

public void set(float x, float y, float z, float w)

### set

public Quaternion set(ReadableVector4f src)
Load from another Vector4f

Parameters:
  `src` - The source vector
Returns:
  this

### setIdentity

public Quaternion setIdentity()
Set this quaternion to the multiplication identity.

Returns:
  this

### setIdentity

public static Quaternion setIdentity(Quaternion q)
Set the given quaternion to the multiplication identity.

Parameters:
  `q` - The quaternion
Returns:
  q

### lengthSquared

public float lengthSquared()

Specified by:
  `lengthSquared` in interface `ReadableVector`
Specified by:
  `lengthSquared` in class `Vector`
Returns:
  the length squared of the quaternion

### normalise

public static Quaternion normalise(Quaternion src, Quaternion dest)
Normalise the source quaternion and place the result in another quaternion.

Parameters:
  `src` - The source quaternion
  `dest` - The destination quaternion, or null if a new quaternion is to be created
Returns:
  The normalised quaternion

### normalise

public Quaternion normalise(Quaternion dest)
Normalise this quaternion and place the result in another quaternion.

Parameters:
  `dest` - The destination quaternion, or null if a new quaternion is to be created
Returns:
  the normalised quaternion

### dot

public static float dot(Quaternion left, Quaternion right)
The dot product of two quaternions

Parameters:
  `left` - The LHS quat
  `right` - The RHS quat
Returns:
  left dot right

### negate

public Quaternion negate(Quaternion dest)
Calculate the conjugate of this quaternion and put it into the given one

Parameters:
  `dest` - The quaternion which should be set to the conjugate of this quaternion

### negate

public static Quaternion negate(Quaternion src, Quaternion dest)
Calculate the conjugate of this quaternion and put it into the given one

Parameters:
  `src` - The source quaternion
  `dest` - The quaternion which should be set to the conjugate of this quaternion

### negate

public Vector negate()
Calculate the conjugate of this quaternion

Specified by:
  `negate` in class `Vector`
Returns:
  this

### load

public Vector load(FloatBuffer buf)
Description copied from class: `Vector`
Load this vector from a FloatBuffer

Specified by:
  `load` in class `Vector`
Parameters:
  `buf` - The buffer to load it from, at the current position
Returns:
  this

### scale

public Vector scale(float scale)
Description copied from class: `Vector`
Scale this vector

Specified by:
  `scale` in class `Vector`
Parameters:
  `scale` - The scale factor
Returns:
  this

### scale

public static Quaternion scale(float scale, Quaternion src, Quaternion dest)
Scale the source quaternion by scale and put the result in the destination

Parameters:
  `scale` - The amount to scale by
  `src` - The source quaternion
  `dest` - The destination quaternion, or null if a new quaternion is to be created
Returns:
  The scaled quaternion

### store

public Vector store(FloatBuffer buf)
Description copied from class: `Vector`
Store this vector in a FloatBuffer

Specified by:
  `store` in interface `ReadableVector`
Specified by:
  `store` in class `Vector`
Parameters:
  `buf` - The buffer to store it in, at the current position
Returns:
  this

### getX

public final float getX()

Specified by:
  `getX` in interface `ReadableVector2f`
Returns:
  x

### getY

public final float getY()

Specified by:
  `getY` in interface `ReadableVector2f`
Returns:
  y

### setX

public final void setX(float x)
Set X

Parameters:
  `x` -

### setY

public final void setY(float y)
Set Y

Parameters:
  `y` -

### setZ

public void setZ(float z)
Set Z

Parameters:
  `z` -

### getZ

public float getZ()

Specified by:
  `getZ` in interface `ReadableVector3f`
Returns:
  z

### setW

public void setW(float w)
Set W

Parameters:
  `w` -

### getW

public float getW()

Specified by:
  `getW` in interface `ReadableVector4f`
Returns:
  w

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### mul

public static Quaternion mul(Quaternion left, Quaternion right, Quaternion dest)
Sets the value of this quaternion to the quaternion product of quaternions left and right (this = left * right). Note that this is safe for aliasing (e.g. this can be left or right).

Parameters:
  `left` - the first quaternion
  `right` - the second quaternion

### mulInverse

public static Quaternion mulInverse(Quaternion left, Quaternion right, Quaternion dest)
Multiplies quaternion left by the inverse of quaternion right and places the value into this quaternion. The value of both argument quaternions is preservered (this = left * right^-1).

Parameters:
  `left` - the left quaternion
  `right` - the right quaternion

### setFromAxisAngle

public final void setFromAxisAngle(Vector4f a1)
Sets the value of this quaternion to the equivalent rotation of the Axis-Angle argument.

Parameters:
  `a1` - the axis-angle: (x,y,z) is the axis and w is the angle

### setFromMatrix

public final Quaternion setFromMatrix(Matrix4f m)
Sets the value of this quaternion using the rotational component of the passed matrix.

Parameters:
  `m` - The matrix
Returns:
  this

### setFromMatrix

public static Quaternion setFromMatrix(Matrix4f m, Quaternion q)
Sets the value of the source quaternion using the rotational component of the passed matrix.

Parameters:
  `m` - The source matrix
  `q` - The destination quaternion, or null if a new quaternion is to be created
Returns:
  q

### setFromMatrix

public final Quaternion setFromMatrix(Matrix3f m)
Sets the value of this quaternion using the rotational component of the passed matrix.

Parameters:
  `m` - The source matrix

### setFromMatrix

public static Quaternion setFromMatrix(Matrix3f m, Quaternion q)
Sets the value of the source quaternion using the rotational component of the passed matrix.

Parameters:
  `m` - The source matrix
  `q` - The destination quaternion, or null if a new quaternion is to be created
Returns:
  q