Ensure that a matrix is orthogonal
| 552 | |
| 553 | // Ensure that a matrix is orthogonal |
| 554 | void vm_Orthogonalize(matrix *m) { |
| 555 | // Normalize forward vector |
| 556 | if (vm_NormalizeVector(&m->fvec) == 0) { |
| 557 | Int3(); // forward vec should not be zero-length |
| 558 | return; |
| 559 | } |
| 560 | |
| 561 | // Generate right vector from forward and up vectors |
| 562 | m->rvec = m->uvec ^ m->fvec; |
| 563 | |
| 564 | // Normaize new right vector |
| 565 | if (vm_NormalizeVector(&m->rvec) == 0) { |
| 566 | vm_VectorToMatrix(m, &m->fvec, NULL, NULL); // error, so generate from forward vector only |
| 567 | return; |
| 568 | } |
| 569 | |
| 570 | // Recompute up vector, in case it wasn't entirely perpendiclar |
| 571 | m->uvec = m->fvec ^ m->rvec; |
| 572 | } |
| 573 | |
| 574 | // do the math for vm_VectorToMatrix() |
| 575 | void DoVectorToMatrix(matrix *m, vector *fvec, vector *uvec, vector *rvec) { |
no test coverage detected