XMQuaternionMultiply

Computes the product of two quaternions.

Syntax

XMVECTOR XMQuaternionMultiply(
         XMVECTOR Q1,
         XMVECTOR Q2
)  

Parameters

Q1
Type: XMVECTOR 

First quaternion.

Q2
Type: XMVECTOR 

Second quaternion.

Return value

Type: XMVECTOR 

Returns the product of two quaternions as Q2*Q1.

Remarks

The DirectXMath quaternion functions use an XMVECTOR 4-vector to represent quaternions, where the X, Y, and Z components are the vector part and the W component is the scalar part.

The result represents the rotation Q1 followed by the rotation Q2 to be consistent with XMMatrixMulplity concatenation since this function is typically used to concatenate quaternions that represent rotations (i.e. it returns Q2*Q1).

This function computes the equivalent to the following pseduo-code:

XMVECTOR Result;
Result.x = (Q2.w * Q1.x) + (Q2.x * Q1.w) + (Q2.y * Q1.z) - (Q2.z * Q1.y);
Result.y = (Q2.w * Q1.y) - (Q2.x * Q1.z) + (Q2.y * Q1.w) + (Q2.z * Q1.x);
Result.z = (Q2.w * Q1.z) + (Q2.x * Q1.y) - (Q2.y * Q1.x) + (Q2.z * Q1.w);
Result.w = (Q2.w * Q1.w) - (Q2.x * Q1.x) - (Q2.y * Q1.y) - (Q2.z * Q1.z);
return Result;  

Requirements

Header: Declared in directxmath.h.