MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / vm_Orthogonalize

Function vm_Orthogonalize

scripts/osiris_vector.h:598–615  ·  view source on GitHub ↗

Ensure that a matrix is orthogonal

Source from the content-addressed store, hash-verified

596
597// Ensure that a matrix is orthogonal
598void vm_Orthogonalize(matrix *m) {
599 // Normalize forward vector
600 if (vm_VectorNormalize(&m->fvec) == 0) {
601 return;
602 }
603
604 // Generate right vector from forward and up vectors
605 m->rvec = m->uvec ^ m->fvec;
606
607 // Normaize new right vector
608 if (vm_VectorNormalize(&m->rvec) == 0) {
609 vm_VectorToMatrix(m, &m->fvec, NULL, NULL); // error, so generate from forward vector only
610 return;
611 }
612
613 // Recompute up vector, in case it wasn't entirely perpendiclar
614 m->uvec = m->fvec ^ m->rvec;
615}
616
617// do the math for vm_VectorToMatrix()
618void DoVectorToMatrix(matrix *m, vector *fvec, vector *uvec, vector *rvec) {

Callers

nothing calls this directly

Calls 2

vm_VectorNormalizeFunction · 0.70
vm_VectorToMatrixFunction · 0.70

Tested by

no test coverage detected