benilla-re systems structs docs

MatrixToQuaternion

function · cmath · primitive

Address
0x7c0190 · 293 bytes, up to 0x7c02b4
Signature
void __thiscall (NTempest::C4Quaternion *this, const NTempest::C33Matrix *m)
Meaning
Converts a row-major 3x3 rotation matrix to a quaternion by the trace and the largest diagonal
Confidence
verified, proof two
Finding
cmath/quaternions#matrix-to-quaternion
Test
cmath::matrix_quat_difftest

Finding: Matrix to quaternion in cmath: quaternions

0x7c0190(m) converts a 3×3 row-major rotation matrix (nine packed floats, m[r*3+c]) to a quaternion in ecx. With the trace t = (m11 + m00) + m22 above 0: s = √(t + 1), w = 0.5·s, k = 0.5/s and x = (m21 − m12)·k, y = (m02 − m20)·k, z = (m10 − m01)·k. Otherwise i is the index of the largest diagonal entry, the later index winning only when strictly greater, j = next[i], k = next[j] with next = {1, 2, 0}; s = √(1 + m_ii − m_jj − m_kk), q[i] = 0.5·s, w = (m_kj − m_jk)·(0.5/s), q[j] = (m_ij + m_ji)·(0.5/s), q[k] = (m_ik + m_ki)·(0.5/s).

The derivation is in the doc.

Callers 1

Callees 0

None by a direct call or jump.

Calls and jumps by a bare address, from tables/calls.tsv.