Open 3D Engine EMotionFX Gem 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.
MCore::DualQuaternion Class Reference

#include <DualQuaternion.h>

Public Member Functions

MCORE_INLINE DualQuaternion ()
 
MCORE_INLINE DualQuaternion (const DualQuaternion &other)
 
MCORE_INLINE DualQuaternion (const AZ::Quaternion &real, const AZ::Quaternion &dual)
 
MCORE_INLINE DualQuaternion (const AZ::Transform &transform)
 
MCORE_INLINE DualQuaternion (const AZ::Quaternion &rotation, const AZ::Vector3 &translation)
 
MCORE_INLINE void Set (const AZ::Quaternion &real, const AZ::Quaternion &dual)
 
DualQuaternionNormalize ()
 
MCORE_INLINE DualQuaternion Normalized () const
 
MCORE_INLINE DualQuaternionIdentity ()
 
MCORE_INLINE AZ::Vector2 Dot (const DualQuaternion &other) const
 
MCORE_INLINE AZ::Vector2 Length () const
 
DualQuaternionInverse ()
 
DualQuaternion Inversed () const
 
MCORE_INLINE DualQuaternionConjugate ()
 
MCORE_INLINE DualQuaternion Conjugated () const
 
MCORE_INLINE void FromTransform (const AZ::Transform &transform)
 
MCORE_INLINE void FromRotationTranslation (const AZ::Quaternion &rot, const AZ::Vector3 &pos)
 
AZ::Transform ToTransform () const
 
MCORE_INLINE AZ::Vector3 TransformPoint (const AZ::Vector3 &point) const
 
MCORE_INLINE AZ::Vector3 TransformVector (const AZ::Vector3 &v) const
 
void ToRotationTranslation (AZ::Quaternion *outRot, AZ::Vector3 *outPos) const
 
void NormalizedToRotationTranslation (AZ::Quaternion *outRot, AZ::Vector3 *outPos) const
 
MCORE_INLINE const DualQuaternionoperator= (const AZ::Transform &transform)
 
MCORE_INLINE const DualQuaternionoperator= (const DualQuaternion &other)
 
MCORE_INLINE DualQuaternion operator- () const
 
MCORE_INLINE const DualQuaternionoperator+= (const DualQuaternion &q)
 
MCORE_INLINE const DualQuaternionoperator-= (const DualQuaternion &q)
 
MCORE_INLINE const DualQuaternionoperator*= (const DualQuaternion &q)
 
MCORE_INLINE const DualQuaternionoperator*= (float f)
 

Static Public Member Functions

static DualQuaternion ConvertFromTransform (const AZ::Transform &transform)
 
static DualQuaternion ConvertFromRotationTranslation (const AZ::Quaternion &rotation, const AZ::Vector3 &translation)
 

Public Attributes

AZ::Quaternion m_real
 
AZ::Quaternion m_dual
 

Detailed Description

The dual quaternion class. Dual quaternions contain two internal vectors. The real and dual part. They behave very similar to regular quaternions in usage. The difference is that the dual quaternion can represent both a rotation and translation or displacement. The dual quaternion consists of a real part, which you can see as the rotation quaternion, and a dual part, which you can see as the translation part. One of the advantages of dual quaternions is that they can be used to replace the linear skin deformations with a volume preserving method. Using dual quaternions in skinning fixes issues such as the famous candy-wrapper effect. It handles twisting of bones much nicer compared to the linear method. This is often referred to as dual quaternion skinning.

Constructor & Destructor Documentation

◆ DualQuaternion() [1/5]

MCORE_INLINE MCore::DualQuaternion::DualQuaternion ( )
inline

The default constructor. This automatically initializes the dual quaternion to identity.

◆ DualQuaternion() [2/5]

MCORE_INLINE MCore::DualQuaternion::DualQuaternion ( const DualQuaternion other)
inline

Copy constructor.

Parameters
otherThe dual quaternion to copy the data from.

◆ DualQuaternion() [3/5]

MCORE_INLINE MCore::DualQuaternion::DualQuaternion ( const AZ::Quaternion &  real,
const AZ::Quaternion &  dual 
)
inline

Extended constructor.

Parameters
realThe real part, which is the rotation part.
dualThe dual part, which is you can see as the translation part.
Note
Do not directly put in the translation into the dual part, if you want to convert from a rotation and translation, please use the other constructor or use the FromRotationTranslation method.

◆ DualQuaternion() [4/5]

MCORE_INLINE MCore::DualQuaternion::DualQuaternion ( const AZ::Transform &  transform)
inline

Constructor which takes a matrix as input parameter. This converts the rotation of the specified matrix into a quaternion. Please keep in mind that the matrix may NOT contain any scaling, so if it does, please normalize your matrix first!

Parameters
matrixThe matrix to initialize the quaternion from.

◆ DualQuaternion() [5/5]

MCORE_INLINE DualQuaternion::DualQuaternion ( const AZ::Quaternion &  rotation,
const AZ::Vector3 &  translation 
)

Extended constructor, which initializes this dual quaternion from a rotation and translation.

Parameters
rotationThe rotation quaternion, which does not need to be normalized, unless you want this to be a normalized dual quaternion.
translationThe translation vector.

Member Function Documentation

◆ Conjugate()

MCORE_INLINE DualQuaternion & MCore::DualQuaternion::Conjugate ( )
inline

Conjugate this dual quaternion.

Returns
A reference to this dual quaternion, but now conjugaged.
Note
If you want to inverse a unit quaternion, you can use the conjugate instead, as that gives the same result, but is much faster to calculate.

◆ Conjugated()

MCORE_INLINE DualQuaternion MCore::DualQuaternion::Conjugated ( ) const
inline

Calculate a conjugated version of this dual quaternion.

Returns
A copy of this dual quaternion, but conjugated.
Note
If you want to inverse a unit quaternion, you can use the conjugate instead, as that gives the same result, but is much faster to calculate.

◆ ConvertFromRotationTranslation()

static DualQuaternion MCore::DualQuaternion::ConvertFromRotationTranslation ( const AZ::Quaternion &  rotation,
const AZ::Vector3 &  translation 
)
static

Convert a rotation and translation into a dual quaternion.

Parameters
rotationThe rotation quaternion, which does not need to be normalized.
translationThe translation.
Returns
A dual quaternion representing the same rotation and translation.
Note
If your input quaternion is not normalized, then the dual quaternion will also not be normalized.

◆ ConvertFromTransform()

static DualQuaternion MCore::DualQuaternion::ConvertFromTransform ( const AZ::Transform &  transform)
static

Convert a matrix into a quaternion. Please keep in mind that the specified matrix may NOT contain any scaling! So make sure the matrix has been normalized before, if it contains any scale.

Parameters
mThe matrix to extract the rotation from.
Returns
The quaternion, now containing the rotation of the given matrix, in quaternion form.

◆ Dot()

MCORE_INLINE AZ::Vector2 MCore::DualQuaternion::Dot ( const DualQuaternion other) const
inline

Get the dot product between the two dual quaternions. This basically performs two dot products: One on the real part and one on the dual part. That means that it also results in two float values, which is why a Vector2 is returned.

Parameters
otherThe other dual quaternion to perform the dot product with.
Returns
A 2D vector containing the result of the dot products. The x component contains the result of the dot between the real part and the y component contains the result of the dot product between the dual parts.

◆ FromRotationTranslation()

MCORE_INLINE void MCore::DualQuaternion::FromRotationTranslation ( const AZ::Quaternion &  rot,
const AZ::Vector3 &  pos 
)
inline

Initialize this dual quaternion from a rotation and translation.

Parameters
rotThe rotation quaternion.
posThe translation vector.
Note
It is allowed to pass an un-normalized quaternion to the rotation parameter. This however will also result in a non-normalized dual quaternion.

◆ FromTransform()

MCORE_INLINE void MCore::DualQuaternion::FromTransform ( const AZ::Transform &  transform)
inline

Initialize the current quaternion from a specified matrix. Please note that the matrix may not contain any scaling! So make sure the matrix has been normalized before, if it contains any scale.

Parameters
mThe matrix to initialize the quaternion from.

◆ Identity()

MCORE_INLINE DualQuaternion & MCore::DualQuaternion::Identity ( )
inline

Set the dual quaternion to identity, so that it has basically no transform. The default constructor already puts the dual quaternion in its identity transform.

Returns
A reference to this quaternion, but now having an identity transform.

◆ Inverse()

DualQuaternion & MCore::DualQuaternion::Inverse ( )

Inverse this dual quaternion.

Returns
A reference to this dual quaternion, but now inversed.

◆ Inversed()

DualQuaternion MCore::DualQuaternion::Inversed ( ) const

Calculate an inversed version of this dual quaternion.

Returns
A copy of this dual quaternion, but then inversed.

◆ Length()

MCORE_INLINE AZ::Vector2 MCore::DualQuaternion::Length ( ) const
inline

Calculate the length of the dual quaternion. This results in a 2D vector, because it calculates the length for both the real and dual parts. The result of the real part will be stored in the x component of the 2D vector, and the result of the dual part will be stored in the y component.

Returns
The 2D vector containing the length of the real and dual part.

◆ Normalize()

DualQuaternion & MCore::DualQuaternion::Normalize ( )

Normalize the dual quaternion.

Returns
A reference to this same quaternion, but now normalized.
Note
Please keep in mind that zero length quaternions will result in a division by zero!

◆ Normalized()

MCORE_INLINE DualQuaternion MCore::DualQuaternion::Normalized ( ) const
inline

Calculate the normalized version of this dual quaternion.

Returns
A copy of this dual quaternion, but then normalized.
Note
Please keep in mind that zero length quaternions will result in a division by zero!

◆ NormalizedToRotationTranslation()

void MCore::DualQuaternion::NormalizedToRotationTranslation ( AZ::Quaternion *  outRot,
AZ::Vector3 *  outPos 
) const

Extract the rotation and translation from this dual normalized quaternion. This method assumes that this dual quaternion is normalized. If it isn't, the resulting output will be incorrect! If you are not sure this quaternion is not normalized, or if you know it is not, please use the ToRotationTranslation method.

Parameters
outRotA pointer to the quaternion in which we will store the output rotation.
outPosA pointer to the vector in which we will store the output translation.

◆ Set()

MCORE_INLINE void MCore::DualQuaternion::Set ( const AZ::Quaternion &  real,
const AZ::Quaternion &  dual 
)
inline

Set the real and dual part of the dual quaternion.

Parameters
realThe real part, which represents the rotation.
dualThe dual part, which represents the translation.
Note
Please keep in mind that you should not set the translation directly into the dual part. If you want to initialize the dual quaternion from a rotation and translation, please use the special constructor for this, or the FromRotationTranslation method.

◆ ToRotationTranslation()

void MCore::DualQuaternion::ToRotationTranslation ( AZ::Quaternion *  outRot,
AZ::Vector3 *  outPos 
) const

Extract the rotation and translation from this dual quaternion. This method handles non-unit dual quaternions fine. If you are sure your dual quaternion is normalized, you should use the faster version of this method, which is called NormalizedToRotationTranslation.

Parameters
outRotA pointer to the quaternion in which we will store the output rotation.
outPosA pointer to the vector in which we will store the output translation.

◆ ToTransform()

AZ::Transform MCore::DualQuaternion::ToTransform ( ) const

Convert this dual quaternion into a 4x4 matrix.

Returns
A matrix, representing the same transformation as this dual quaternion.

◆ TransformPoint()

MCORE_INLINE AZ::Vector3 DualQuaternion::TransformPoint ( const AZ::Vector3 &  point) const

Transform a 3D point with this dual quaternion. This applies both a rotation and possible translation to the point.

Parameters
pointThe 3D point to transform.
Returns
The transformed point.
Note
If you want to transform a vector instead of a point, please use the TransformVector method.

◆ TransformVector()

MCORE_INLINE AZ::Vector3 DualQuaternion::TransformVector ( const AZ::Vector3 &  v) const

Transform a 3D vector with this dual quaternion. This will apply only the rotation part of this dual quaternion. So it will not apply any displacement caused by the dual part of this dual quaternion. You should use this method when transforming normals and tangents for example. You can use the TransformPoint method to transform 3D points. This vector transform is also faster than the TransformPoint method, as it has to do fewer calculations.

Parameters
vThe input vector.
Returns
The transformed vector.

Member Data Documentation

◆ m_dual

AZ::Quaternion MCore::DualQuaternion::m_dual

The dual part, which you can see as the translation part.

◆ m_real

AZ::Quaternion MCore::DualQuaternion::m_real

The real value, which you can see as the regular rotation quaternion.


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