Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::Quaternion Class Reference

Public Member Functions

 Quaternion ()=default
 Default constructor, components are uninitialized.
 
 Quaternion (const Quaternion &q)
 Copy constructor, clones the provided quaternion.
 
 Quaternion (float x)
 Constructs quaternion with all components set to the same specified value.
 
 Quaternion (float x, float y, float z, float w)
 Constructs quaternion with all components set to the provided values.
 
 Quaternion (const Vector3 &v, float w)
 Constructs quaternion from a vector3 and scalar w value.
 
 Quaternion (Simd::Vec4::FloatArgType value)
 
void StoreToFloat4 (float *values) const
 Stores the vector to an array of 4 floats. The floats need only be 4 byte aligned, 16 byte alignment is not required.
 
float GetElement (int index) const
 We recommend using GetX,Y,Z,W. GetElement can be slower.
 
void SetElement (int index, float v)
 We recommend using SetX,Y,Z,W. SetElement can be slower.
 
float operator() (int index) const
 
void Set (float x)
 
void Set (float x, float y, float z, float w)
 
void Set (const Vector3 &v, float w)
 
void Set (const float values[])
 
Quaternion GetConjugate () const
 The conjugate of a quaternion is (-x, -y, -z, w).
 
float Dot (const Quaternion &q) const
 Dot product.
 
float GetLengthSq () const
 
float GetLength () const
 Returns length of the quaternion, full accuracy.
 
float GetLengthEstimate () const
 Returns length of the quaternion, fast but low accuracy, uses raw estimate instructions.
 
float GetLengthReciprocal () const
 Returns 1/length, full accuracy.
 
float GetLengthReciprocalEstimate () const
 Returns 1/length of the quaternion, fast but low accuracy, uses raw estimate instructions.
 
Quaternion GetNormalized () const
 Returns normalized quaternion, full accuracy.
 
Quaternion GetNormalizedEstimate () const
 Returns normalized quaternion, fast but low accuracy, uses raw estimate instructions.
 
void Normalize ()
 Normalizes the quaternion in-place, full accuracy.
 
void NormalizeEstimate ()
 Normalizes the quaternion in-place, fast but low accuracy, uses raw estimate instructions.
 
Quaternion Lerp (const Quaternion &dest, float t) const
 
Quaternion NLerp (const Quaternion &dest, float t) const
 
Quaternion Slerp (const Quaternion &dest, float t) const
 Spherical linear interpolation. Result is not normalized.
 
Quaternion Squad (const Quaternion &dest, const Quaternion &in, const Quaternion &out, float t) const
 
bool IsClose (const Quaternion &q, float tolerance=Constants::Tolerance) const
 Checks if the quaternion is close to another quaternion with a given floating point tolerance.
 
bool IsIdentity (float tolerance=Constants::Tolerance) const
 
bool IsZero (float tolerance=Constants::FloatEpsilon) const
 
Quaternionoperator= (const Quaternion &rhs)
 
Quaternion operator- () const
 
Quaternion operator+ (const Quaternion &q) const
 
Quaternion operator- (const Quaternion &q) const
 
Quaternion operator* (const Quaternion &q) const
 
Quaternion operator* (float multiplier) const
 
Quaternion operator/ (float divisor) const
 
Quaternionoperator+= (const Quaternion &q)
 
Quaternionoperator-= (const Quaternion &q)
 
Quaternionoperator*= (const Quaternion &q)
 
Quaternionoperator*= (float multiplier)
 
Quaternionoperator/= (float divisor)
 
bool operator== (const Quaternion &rhs) const
 
bool operator!= (const Quaternion &rhs) const
 
Vector3 TransformVector (const Vector3 &v) const
 Transforms a vector using the rotation described by this quaternion.
 
Vector3 GetEulerDegrees () const
 
Vector3 GetEulerRadians () const
 
void SetFromEulerRadians (const Vector3 &eulerRadians)
 
void SetFromEulerDegrees (const Vector3 &eulerDegrees)
 
void ConvertToAxisAngle (Vector3 &outAxis, float &outAngle) const
 
Vector3 ConvertToScaledAxisAngle () const
 Convert the quaternion into scaled axis-angle representation.
 
Vector3 GetImaginary () const
 Returns the imaginary (X/Y/Z) portion of the quaternion.
 
float GetAngle () const
 Return angle in radians.
 
bool IsFinite () const
 
Simd::Vec4::FloatType GetSimdValue () const
 
float GetX () const
 
float GetY () const
 
float GetZ () const
 
float GetW () const
 
void SetX (float x)
 
void SetY (float y)
 
void SetZ (float z)
 
void SetW (float w)
 
Quaternion GetInverseFast () const
 
void InvertFast ()
 
Quaternion GetInverseFull () const
 
void InvertFull ()
 
float NormalizeWithLength ()
 
float NormalizeWithLengthEstimate ()
 
Quaternion GetShortestEquivalent () const
 
void ShortestEquivalent ()
 

Static Public Member Functions

static void Reflect (ReflectContext *context)
 
static Quaternion CreateIdentity ()
 
static Quaternion CreateZero ()
 
static Quaternion CreateFromFloat4 (const float *values)
 Sets components from an array of 4 floats, stored in xyzw order.
 
static Quaternion CreateFromVector3 (const Vector3 &v)
 Sets components using a Vector3 for the imaginary part and setting the real part to zero.
 
static Quaternion CreateFromVector3AndValue (const Vector3 &v, float w)
 Sets components using a Vector3 for the imaginary part and a float for the real part.
 
static Quaternion CreateFromEulerRadiansXYZ (const Vector3 &eulerRadians)
 
static Quaternion CreateFromEulerRadiansYXZ (const Vector3 &eulerRadians)
 
static Quaternion CreateFromEulerRadiansZYX (const Vector3 &eulerRadians)
 
static Quaternion CreateFromEulerDegreesXYZ (const Vector3 &eulerDegrees)
 
static Quaternion CreateFromEulerDegreesYXZ (const Vector3 &eulerDegrees)
 
static Quaternion CreateFromEulerDegreesZYX (const Vector3 &eulerDegrees)
 
static Quaternion CreateFromMatrix3x3 (const class Matrix3x3 &m)
 Creates a quaternion from a Matrix3x3.
 
static Quaternion CreateFromMatrix3x4 (const class Matrix3x4 &m)
 
static Quaternion CreateFromMatrix4x4 (const class Matrix4x4 &m)
 Creates a quaternion using the rotation part of a Matrix4x4.
 
static Quaternion CreateFromBasis (const Vector3 &basisX, const Vector3 &basisY, const Vector3 &basisZ)
 Creates a quaternion from a set of basis vectors.
 
static Quaternion CreateFromAxisAngle (const Vector3 &axis, float angle)
 
static Quaternion CreateFromScaledAxisAngle (const Vector3 &scaledAxisAngle)
 Create a quaternion from a scaled axis-angle representation.
 
static Quaternion CreateShortestArc (const Vector3 &v1, const Vector3 &v2)
 
static const Quaternion CreateFromEulerAnglesDegrees (const Vector3 &anglesInDegrees)
 Creates a quaternion using rotation in degrees about the axes. First rotated about the X axis, followed by the Y axis, then the Z axis.
 
static const Quaternion CreateFromEulerAnglesRadians (const Vector3 &anglesInRadians)
 Creates a quaternion using rotation in radians about the axes. First rotated about the X axis, followed by the Y axis, then the Z axis.
 
static Quaternion CreateRotationX (float angleInRadians)
 
static Quaternion CreateRotationY (float angleInRadians)
 
static Quaternion CreateRotationZ (float angleInRadians)
 

Constructor & Destructor Documentation

◆ Quaternion()

AZ_MATH_INLINE AZ::Quaternion::Quaternion ( Simd::Vec4::FloatArgType  value)
explicit

Constructs quaternion from a SIMD type. For internal use only, arrangement of values in SIMD type is not guaranteed.

Member Function Documentation

◆ ConvertToAxisAngle()

void AZ::Quaternion::ConvertToAxisAngle ( Vector3 outAxis,
float &  outAngle 
) const

Populate axis and angle of rotation from Quaternion

Parameters
[out]outAxisA Vector3 defining the rotation axis.
[out]outAngleA float rotation angle around the axis in radians.

◆ CreateFromMatrix3x4()

static Quaternion AZ::Quaternion::CreateFromMatrix3x4 ( const class Matrix3x4 m)
static

Creates a quaternion using the left 3x3 part of a Matrix3x4.

Note
If the matrix has a scale other than (1, 1, 1) be sure to extract the scale first with AZ::Matrix3x4::ExtractScale or ::ExtractScaleExact.

◆ CreateRotationX()

AZ_MATH_INLINE Quaternion AZ::Quaternion::CreateRotationX ( float  angleInRadians)
static

Sets the quaternion to be a rotation around a specified axis in radians.

◆ GetEulerDegrees()

AZ_MATH_INLINE Vector3 AZ::Quaternion::GetEulerDegrees ( ) const

Create, from the quaternion, a set of Euler angles of rotations around first z-axis, then y-axis and then x-axis.

Returns
Vector3 A vector containing component-wise rotation angles in degrees.

◆ GetEulerRadians()

AZ_MATH_INLINE Vector3 AZ::Quaternion::GetEulerRadians ( ) const

Create, from the quaternion, a set of Euler angles of rotations around first z-axis, then y-axis and then x-axis.

Returns
Vector3 A vector containing component-wise rotation angles in radians.

◆ GetInverseFast()

AZ_MATH_INLINE Quaternion AZ::Quaternion::GetInverseFast ( ) const

For a unit quaternion, the inverse is just the conjugate. This function assumes a unit quaternion.

◆ GetInverseFull()

AZ_MATH_INLINE Quaternion AZ::Quaternion::GetInverseFull ( ) const

This is the inverse for any quaternion, not just unit quaternions.

◆ GetShortestEquivalent()

AZ_MATH_INLINE Quaternion AZ::Quaternion::GetShortestEquivalent ( ) const

Get the shortest equivalent of the rotation. In case the w component of the quaternion is negative the rotation is > 180° and taking the longer path. The quaternion will be inverted in that case to take the shortest path of rotation.

◆ GetX()

AZ_MATH_INLINE float AZ::Quaternion::GetX ( ) const

Component access

◆ Lerp()

AZ_MATH_INLINE Quaternion AZ::Quaternion::Lerp ( const Quaternion dest,
float  t 
) const

Linearly interpolate towards a destination quaternion.

Parameters
[in]destThe quaternion to interpolate towards.
[in]tNormalized interpolation value where 0.0 represents the current and 1.0 the destination value.
Returns
The interpolated quaternion at the given interpolation point.

◆ NLerp()

AZ_MATH_INLINE Quaternion AZ::Quaternion::NLerp ( const Quaternion dest,
float  t 
) const

Linearly interpolate towards a destination quaternion, and normalize afterwards.

Parameters
[in]destThe quaternion to interpolate towards.
[in]tNormalized interpolation value where 0.0 represents the current and 1.0 the destination value.
Returns
The interpolated and normalized quaternion at the given interpolation point.

◆ NormalizeWithLength()

AZ_MATH_INLINE float AZ::Quaternion::NormalizeWithLength ( )

Normalizes the vector in-place and returns the previous length. This takes a few more instructions than calling just Normalize().

◆ operator()()

AZ_MATH_INLINE float AZ::Quaternion::operator() ( int  index) const

Indexed access using operator(). It's just for convenience.

Note
This can be slower than using GetX,GetY, etc.

◆ Reflect()

static void AZ::Quaternion::Reflect ( ReflectContext context)
static

AzCore Reflection.

Parameters
contextreflection context

◆ SetFromEulerDegrees()

AZ_MATH_INLINE void AZ::Quaternion::SetFromEulerDegrees ( const Vector3 eulerDegrees)
Parameters
eulerDegreesA vector containing component-wise rotation angles in degrees. O3DE_DEPRECATION_NOTICE(GHI-10929)
Deprecated:
use CreateFromEulerDegreesXYZ

◆ SetFromEulerRadians()

void AZ::Quaternion::SetFromEulerRadians ( const Vector3 eulerRadians)
Parameters
eulerRadiansA vector containing component-wise rotation angles in radians. O3DE_DEPRECATION_NOTICE(GHI-10929)
Deprecated:
use CreateFromEulerRadiansXYZ

◆ Squad()

AZ_MATH_INLINE Quaternion AZ::Quaternion::Squad ( const Quaternion dest,
const Quaternion in,
const Quaternion out,
float  t 
) const

Spherical linear interpolation, but with in/out tangent quaternions. Squad(p,a,b,q,t) = Slerp(Slerp(p,q,t), Slerp(a,b,t); 2(1-t)t).


The documentation for this class was generated from the following files: