resonance 1.0.1
Loading...
Searching...
No Matches
quaternion.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Quat
 Rotation quaternion, stored as the vector part followed by the scalar part. More...

Namespaces

namespace  Rnd
 The rendering engine.

Functions

void Rnd::MakeAxisAngle (const Quat &quat, float *pAxis, float *pflAngle)
 Recover the axis and angle of a rotation quaternion.
Quat EulerAnglesToQuat (const float *pAngles)
 Build a rotation quaternion from three Euler angles.
void QuatMultiply (const Quat &a, const Quat &b, Quat &out)
 Compose two rotation quaternions.
Quat QuatRotateByVector (const Quat &quat, const float *pRotVec)
 Compose a rotation quaternion with a rotation vector.
void QuatSlerp (const Quat &from, const Quat &to, Quat &out, float flT)
 Interpolate between two rotation quaternions along the shorter arc.
void Rnd::MakeRotMatrix (const Quat &quat, float *pMat3Rows)
 Convert a rotation quaternion to a rotation matrix.
void Rnd::MakeEuler (const float *pMat3Rows, float *pAngles)
 Extract Euler angles from a rotation matrix, inverting MakeRotMatrix() from three angles.
void Mat33ExtractScale (const float *pMat3Rows, float *pScale)
 Report the scale each basis row carries.
void LerpEulerAngles (const float *pFrom, const float *pTo, float *pOut, float flT)
 Interpolate between two sets of Euler angles the shorter way round each axis.

Function Documentation

◆ EulerAnglesToQuat()

Quat EulerAnglesToQuat ( const float * pAngles)

Build a rotation quaternion from three Euler angles.

The composition is the same one Rnd::MakeRotMatrix() produces from three angles. That is, the product is qz * qx * qy, with each factor a rotation about one axis by the matching component.

Parameters
pAnglesThe three angles in radians, ordered X, Y, and Z.
Returns
The quaternion.
Ghidra address:
NTSC-U/C: 0x004f0230
Ghidra address:
PAL: 0x0052ee20

◆ QuatMultiply()

void QuatMultiply ( const Quat & a,
const Quat & b,
Quat & out )

Compose two rotation quaternions.

The product is the Hamilton product of a and b in that order.

Parameters
aThe left factor.
bThe right factor.
outReceives the product. Every component of both factors is loaded before the first store, which permits the destination to alias either factor.
Ghidra address:
NTSC-U/C: 0x004f06a0
Ghidra address:
PAL: 0x0052f290

◆ QuatRotateByVector()

Quat QuatRotateByVector ( const Quat & quat,
const float * pRotVec )

Compose a rotation quaternion with a rotation vector.

The rotation vector encodes its axis by direction and its angle by length. The result is the Hamilton product of the quaternion with the vector's own quaternion, in that order. A zero-length vector divides by zero and is not guarded against.

Parameters
quatThe rotation to start from.
pRotVecThe rotation vector, three floats.
Returns
The composed rotation.
Ghidra address:
NTSC-U/C: 0x004f0178
Ghidra address:
PAL: 0x0052ed68

◆ QuatSlerp()

void QuatSlerp ( const Quat & from,
const Quat & to,
Quat & out,
float flT )

Interpolate between two rotation quaternions along the shorter arc.

A negative dot product flips the second quaternion. The interpolation therefore never takes the long way round. Both endpoint values of the parameter are special cased and copy an endpoint verbatim. Two nearly parallel inputs fall back to a component-wise linear blend, because the sine of the half angle underflows there.

The scale factors and the accumulation are double precision. This target has no double precision unit, and the compiler expands them into software calls. The arithmetic is genuinely slower than the surrounding single precision code. The trigonometry is single precision throughout.

Parameters
fromThe rotation at a parameter of zero.
toThe rotation at a parameter of one.
outReceives the interpolation.
flTThe interpolation parameter.
Ghidra address:
NTSC-U/C: 0x004eec20
Ghidra address:
PAL: 0x0052d7c8

◆ Mat33ExtractScale()

void Mat33ExtractScale ( const float * pMat3Rows,
float * pScale )

Report the scale each basis row carries.

Each scale is the length of its row. The Z scale is negated unless the dot product of the Z row with the cross product of the X and Y rows is positive. Rnd::Transformable::GetDrawXfm() and the routine at 0x00483030 call it.

Parameters
pMat3RowsThe basis, three rows of four floats.
pScaleReceives the three scales.
Ghidra address:
NTSC-U/C: 0x004efed8
Ghidra address:
PAL: 0x0052eac8

◆ LerpEulerAngles()

void LerpEulerAngles ( const float * pFrom,
const float * pTo,
float * pOut,
float flT )

Interpolate between two sets of Euler angles the shorter way round each axis.

Each component's difference is wrapped into the half-open range from minus one half turn to one half turn with fmodf(), scaled by flT, and added to the starting angle. No call site survives in the shipped program.

Parameters
pFromThe angles at a parameter of zero, three floats.
pToThe angles at a parameter of one, three floats.
pOutReceives the interpolated angles, three floats.
flTThe interpolation parameter.
Ghidra address:
NTSC-U/C: 0x004effe0
Ghidra address:
PAL: 0x0052ebd0