record TQuaternion

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TQuaternion = record

Description

A quaternion.

TQuaternion is compatible with TQuaternion3D in the Delphi RTL. You can typecast between these two types or implicitly convert from one to the other through assignment (eg. MyQuaternion := MyQuaternion3D).

Overview

Fields

X: Single
Y: Single
Z: Single
W: Single
C: array [0..3] of Single

Methods

procedure Init; overload; inline;
procedure Init(const AX, AY, AZ, AW: Single); overload; inline;
procedure Init(const AAxis: TVector3; const AAngleRadians: Single); overload;
procedure Init(const AYaw, APitch, ARoll: Single); overload;
procedure Init(const AMatrix: TMatrix4); overload;
function ToMatrix: TMatrix4;
class operator Implicit(const A: TQuaternion3D): TQuaternion; inline;
class operator Implicit(const A: TQuaternion): TQuaternion3D; inline;
class operator Add(const A, B: TQuaternion): TQuaternion;
class operator Multiply(const A: TQuaternion; const B: Single): TQuaternion;
class operator Multiply(const A: Single; const B: TQuaternion): TQuaternion;
class operator Multiply(const A, B: TQuaternion): TQuaternion;
function IsIdentity: Boolean; overload; inline;
function IsIdentity(const AErrorMargin: Single): Boolean; overload;
function Normalize: TQuaternion; inline;
procedure SetNormalized; inline;
function NormalizeFast: TQuaternion;
procedure SetNormalizedFast;
function Conjugate: TQuaternion;
procedure SetConjugate; inline;

Properties

property Length: Single read GetLength;
property LengthSquared: Single read GetLengthSquared;

Description

Fields

X: Single

X, Y, Z and W components of the quaternion

Y: Single

X, Y, Z and W components of the quaternion

Z: Single

X, Y, Z and W components of the quaternion

W: Single

X, Y, Z and W components of the quaternion

C: array [0..3] of Single

The four components of the quaternion.

Methods

procedure Init; overload; inline;

Initializes the quaternion to an identity quaternion. Sets the X, Y and Z components to 0 and the W component to 1.

procedure Init(const AX, AY, AZ, AW: Single); overload; inline;

Sets the four components of the quaternion.

Parameters
AX
the X-component.
AY
the Y-component.
AZ
the Z-component.
AW
the W-component.
procedure Init(const AAxis: TVector3; const AAngleRadians: Single); overload;

Sets the quaternion from the given axis vector and the angle around that axis in radians.

Parameters
AAxis
The axis.
AAngleRadians
The angle in radians.
procedure Init(const AYaw, APitch, ARoll: Single); overload;

Sets the quaternion to the given euler angles in radians.

Parameters
AYaw
the rotation around the Y axis in radians.
APitch
the rotation around the X axis in radians.
ARoll
the rotation around the Z axis in radians.
procedure Init(const AMatrix: TMatrix4); overload;

Sets the quaternion from a matrix.

Parameters
AMatrix
the matrix.
function ToMatrix: TMatrix4;

Creates a rotation matrix that represents this quaternion.

Returns

A rotation matrix that represents this quaternion.

class operator Implicit(const A: TQuaternion3D): TQuaternion; inline;

Implicitly converts a TQuaternion3D to a TQuaternion.

class operator Implicit(const A: TQuaternion): TQuaternion3D; inline;

Implicitly converts a TQuaternion to a TQuaternion3D.

class operator Add(const A, B: TQuaternion): TQuaternion;

Adds to quaternions together.

Returns

A + B

class operator Multiply(const A: TQuaternion; const B: Single): TQuaternion;

Multiplies a vector with a scalar value.

Returns

(A.X * B, A.Y * B, A.Z * B, A.W * B)

class operator Multiply(const A: Single; const B: TQuaternion): TQuaternion;

Multiplies a vector with a scalar value.

Returns

(A * B.X, A * B.Y, A * B.Z, A * B.W)

class operator Multiply(const A, B: TQuaternion): TQuaternion;

Multiplies two quaternions.

Returns

A * B

function IsIdentity: Boolean; overload; inline;

Whether this is an identity quaternion.

Returns

True if X, Y and Z are exactly 0.0 and W is exactly 1.0

function IsIdentity(const AErrorMargin: Single): Boolean; overload;

Whether this is an identity quaternion within a given margin of error.

Parameters
AErrorMargin
the allowed margin of error.
Returns

True if this is an identity quaternion within the error margin.

function Normalize: TQuaternion; inline;

Calculates a normalized version of this quaternion.

Note: for a faster, less accurate version, use NormalizeFast.

Note: Does not change this quaternion. To update this quaternion itself, use SetNormalized.

Returns

The normalized quaternion of of this vector (with a length of 1).

procedure SetNormalized; inline;

Normalizes this quaternion to a length of 1.

Note: The SIMD optimized versions of this method use an approximation, resulting in a very small error.

Note: If you do not want to change this quaternion, but get a normalized version instead, then use Normalize.

function NormalizeFast: TQuaternion;

Calculates a normalized version of this quaternion.

Note: this is an SIMD optimized version that uses an approximation, resulting in a small error. For an accurate version, use Normalize.

Note: Does not change this quaternion. To update this quaternion itself, use SetNormalizedFast.

Returns

The normalized version of of this quaternion (with a length of 1).

procedure SetNormalizedFast;

Normalizes this quaternion to a length of 1.

Note: this is an SIMD optimized version that uses an approximation, resulting in a small error. For an accurate version, use SetNormalized.

Note: If you do not want to change this quaternion, but get a normalized version instead, then use NormalizeFast.

function Conjugate: TQuaternion;

Creates a conjugate of the quaternion.

Note: Does not change this quaterion. To update this quaterion itself, use SetConjugate.

Returns

The conjugate (eg. (-X, -Y, -Z, W))

procedure SetConjugate; inline;

Conjugate this quaternion.

Note: If you do not want to change this quaternion, but get a conjugate version instead, then use Conjugate.

Properties

property Length: Single read GetLength;

The euclidean length of this quaternion.

Note: If you only want to compare lengths of quaternion, you should use LengthSquared instead, which is faster.

property LengthSquared: Single read GetLengthSquared;

The squared length of the quaternion.

Note: This property is faster than Length because it avoids calculating a square root. It is useful for comparing lengths instead of calculating actual lengths.


Generated by PasDocEx, based on PasDoc 0.14.0.