Ensure that a matrix is orthogonal
| 596 | |
| 597 | // Ensure that a matrix is orthogonal |
| 598 | void 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() |
| 618 | void DoVectorToMatrix(matrix *m, vector *fvec, vector *uvec, vector *rvec) { |
nothing calls this directly
no test coverage detected