com.badlogic.gdx.math
Class Quaternion

java.lang.Object
  extended by com.badlogic.gdx.math.Quaternion
All Implemented Interfaces:
Serializable

public class Quaternion
extends Object
implements Serializable

A simple quaternion class. See http://en.wikipedia.org/wiki/Quaternion for more information.

Author:
[email protected], vesuvio
See Also:
Serialized Form

Field Summary
 float w
           
 float x
           
 float y
           
 float z
           
 
Constructor Summary
Quaternion()
           
Quaternion(float x, float y, float z, float w)
          Constructor, sets the four components of the quaternion.
Quaternion(Quaternion quaternion)
          Constructor, sets the quaternion components from the given quaternion.
Quaternion(Vector3 axis, float angle)
          Constructor, sets the quaternion from the given axis vector and the angle around that axis in degrees.
 
Method Summary
 Quaternion conjugate()
          Conjugate the quaternion.
 Quaternion cpy()
           
 float dot(Quaternion other)
          Dot product between this and the other quaternion.
 boolean equals(Object o)
           
 float getAxisAngle(Vector3 axis)
          Get the angle and the axis of rotation
 Quaternion idt()
          Sets the quaternion to an identity Quaternion
 float len()
           
 float len2()
           
 Quaternion mul(float scalar)
          Multiplies the components of this quaternion with the given scalar.
 Quaternion mul(Quaternion q)
          Multiplies this quaternion with another one
 Quaternion mulLeft(Quaternion q)
          Multiplies this quaternion with another one in the form of q * this
 Quaternion nor()
          Normalizes this quaternion to unit length
 Quaternion set(float x, float y, float z, float w)
          Sets the components of the quaternion
 Quaternion set(Quaternion quaternion)
          Sets the quaternion components from the given quaternion.
 Quaternion set(Vector3 axis, float angle)
          Sets the quaternion components from the given axis and angle around that axis.
 Quaternion setEulerAngles(float yaw, float pitch, float roll)
          Sets the quaternion to the given euler angles.
 Quaternion setFromAxes(float xx, float xy, float xz, float yx, float yy, float yz, float zx, float zy, float zz)
           Sets the Quaternion from the given x-, y- and z-axis which have to be orthonormal.
 Quaternion setFromAxis(float x, float y, float z, float angle)
          Sets the quaternion components from the given axis and angle around that axis.
 Quaternion setFromAxis(Vector3 axis, float angle)
          Sets the quaternion components from the given axis and angle around that axis.
 Quaternion setFromCross(float x1, float y1, float z1, float x2, float y2, float z2)
          Set this quaternion to the rotation between two vectors.
 Quaternion setFromCross(Vector3 v1, Vector3 v2)
          Set this quaternion to the rotation between two vectors.
 Quaternion setFromMatrix(Matrix4 matrix)
           
 Quaternion slerp(Quaternion end, float alpha)
          Spherical linear interpolation between this quaternion and the other quaternion, based on the alpha value in the range [0,1].
 void toMatrix(float[] matrix)
          Fills a 4x4 matrix with the rotation matrix represented by this quaternion.
 String toString()
          
 Vector3 transform(Vector3 v)
          Transforms the given vector using this quaternion
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public float x

y

public float y

z

public float z

w

public float w
Constructor Detail

Quaternion

public Quaternion(float x,
                  float y,
                  float z,
                  float w)
Constructor, sets the four components of the quaternion.

Parameters:
x - The x-component
y - The y-component
z - The z-component
w - The w-component

Quaternion

public Quaternion()

Quaternion

public Quaternion(Quaternion quaternion)
Constructor, sets the quaternion components from the given quaternion.

Parameters:
quaternion - The quaternion to copy.

Quaternion

public Quaternion(Vector3 axis,
                  float angle)
Constructor, sets the quaternion from the given axis vector and the angle around that axis in degrees.

Parameters:
axis - The axis
angle - The angle in degrees.
Method Detail

set

public Quaternion set(float x,
                      float y,
                      float z,
                      float w)
Sets the components of the quaternion

Parameters:
x - The x-component
y - The y-component
z - The z-component
w - The w-component
Returns:
This quaternion for chaining

set

public Quaternion set(Quaternion quaternion)
Sets the quaternion components from the given quaternion.

Parameters:
quaternion - The quaternion.
Returns:
This quaternion for chaining.

set

public Quaternion set(Vector3 axis,
                      float angle)
Sets the quaternion components from the given axis and angle around that axis.

Parameters:
axis - The axis
angle - The angle in degrees
Returns:
This quaternion for chaining.

cpy

public Quaternion cpy()
Returns:
a copy of this quaternion

len

public float len()
Returns:
the euclidian length of this quaternion

toString

public String toString()

Overrides:
toString in class Object

setEulerAngles

public Quaternion setEulerAngles(float yaw,
                                 float pitch,
                                 float roll)
Sets the quaternion to the given euler angles.

Parameters:
yaw - the yaw in degrees
pitch - the pitch in degress
roll - the roll in degess
Returns:
this quaternion

len2

public float len2()
Returns:
the length of this quaternion without square root

nor

public Quaternion nor()
Normalizes this quaternion to unit length

Returns:
the quaternion for chaining

conjugate

public Quaternion conjugate()
Conjugate the quaternion.

Returns:
This quaternion for chaining

transform

public Vector3 transform(Vector3 v)
Transforms the given vector using this quaternion

Parameters:
v - Vector to transform

mul

public Quaternion mul(Quaternion q)
Multiplies this quaternion with another one

Parameters:
q - Quaternion to multiply with
Returns:
This quaternion for chaining

mulLeft

public Quaternion mulLeft(Quaternion q)
Multiplies this quaternion with another one in the form of q * this

Parameters:
q - Quaternion to multiply with
Returns:
This quaternion for chaining

toMatrix

public void toMatrix(float[] matrix)
Fills a 4x4 matrix with the rotation matrix represented by this quaternion.

Parameters:
matrix - Matrix to fill

idt

public Quaternion idt()
Sets the quaternion to an identity Quaternion

Returns:
this quaternion for chaining

setFromAxis

public Quaternion setFromAxis(Vector3 axis,
                              float angle)
Sets the quaternion components from the given axis and angle around that axis.

Parameters:
axis - The axis
angle - The angle in degrees
Returns:
This quaternion for chaining.

setFromAxis

public Quaternion setFromAxis(float x,
                              float y,
                              float z,
                              float angle)
Sets the quaternion components from the given axis and angle around that axis.

Parameters:
x - X direction of the axis
y - Y direction of the axis
z - Z direction of the axis
angle - The angle in degrees
Returns:
This quaternion for chaining.

setFromMatrix

public Quaternion setFromMatrix(Matrix4 matrix)

setFromAxes

public Quaternion setFromAxes(float xx,
                              float xy,
                              float xz,
                              float yx,
                              float yy,
                              float yz,
                              float zx,
                              float zy,
                              float zz)

Sets the Quaternion from the given x-, y- and z-axis which have to be orthonormal.

Taken from Bones framework for JPCT, see http://www.aptalkarga.com/bones/ which in turn took it from Graphics Gem code at ftp://ftp.cis.upenn.edu/pub/graphics/shoemake/quatut.ps.Z.

Parameters:
xx - x-axis x-coordinate
xy - x-axis y-coordinate
xz - x-axis z-coordinate
yx - y-axis x-coordinate
yy - y-axis y-coordinate
yz - y-axis z-coordinate
zx - z-axis x-coordinate
zy - z-axis y-coordinate
zz - z-axis z-coordinate

setFromCross

public Quaternion setFromCross(Vector3 v1,
                               Vector3 v2)
Set this quaternion to the rotation between two vectors.

Parameters:
v1 - The base vector, which should be normalized.
v2 - The target vector, which should be normalized.
Returns:
This quaternion for chaining

setFromCross

public Quaternion setFromCross(float x1,
                               float y1,
                               float z1,
                               float x2,
                               float y2,
                               float z2)
Set this quaternion to the rotation between two vectors.

Parameters:
x1 - The base vectors x value, which should be normalized.
y1 - The base vectors y value, which should be normalized.
z1 - The base vectors z value, which should be normalized.
x2 - The target vector x value, which should be normalized.
y2 - The target vector y value, which should be normalized.
z2 - The target vector z value, which should be normalized.
Returns:
This quaternion for chaining

slerp

public Quaternion slerp(Quaternion end,
                        float alpha)
Spherical linear interpolation between this quaternion and the other quaternion, based on the alpha value in the range [0,1]. Taken from. Taken from Bones framework for JPCT, see http://www.aptalkarga.com/bones/

Parameters:
end - the end quaternion
alpha - alpha in the range [0,1]
Returns:
this quaternion for chaining

equals

public boolean equals(Object o)
Overrides:
equals in class Object

dot

public float dot(Quaternion other)
Dot product between this and the other quaternion.

Parameters:
other - the other quaternion.
Returns:
this quaternion for chaining.

mul

public Quaternion mul(float scalar)
Multiplies the components of this quaternion with the given scalar.

Parameters:
scalar - the scalar.
Returns:
this quaternion for chaining.

getAxisAngle

public float getAxisAngle(Vector3 axis)
Get the angle and the axis of rotation

Parameters:
axis - axis to get
Returns:
the angle


Copyright © 2013. All Rights Reserved.