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

Function DoVectorToMatrix

vecmat/vector.cpp:575–639  ·  view source on GitHub ↗

do the math for vm_VectorToMatrix()

Source from the content-addressed store, hash-verified

573
574// do the math for vm_VectorToMatrix()
575void DoVectorToMatrix(matrix *m, vector *fvec, vector *uvec, vector *rvec) {
576 vector *xvec = &m->rvec, *yvec = &m->uvec, *zvec = &m->fvec;
577
578 ASSERT(fvec != NULL);
579
580 *zvec = *fvec;
581 if (vm_NormalizeVector(zvec) == 0) {
582 Int3(); // forward vec should not be zero-length
583 return;
584 }
585
586 if (uvec == NULL) {
587
588 if (rvec == NULL) { // just forward vec
589
590 bad_vector2:;
591
592 if (zvec->x == 0 && zvec->z == 0) { // forward vec is straight up or down
593
594 m->rvec.x = 1.0;
595 m->uvec.z = (zvec->y < 0) ? 1.0 : -1.0;
596
597 m->rvec.y = m->rvec.z = m->uvec.x = m->uvec.y = 0;
598 } else { // not straight up or down
599
600 xvec->x = zvec->z;
601 xvec->y = 0;
602 xvec->z = -zvec->x;
603
604 vm_NormalizeVector(xvec);
605
606 *yvec = *zvec ^ *xvec;
607 }
608
609 } else { // use right vec
610
611 *xvec = *rvec;
612 if (vm_NormalizeVector(xvec) == 0)
613 goto bad_vector2;
614
615 *yvec = *zvec ^ *xvec;
616
617 // normalize new perpendicular vector
618 if (vm_NormalizeVector(yvec) == 0)
619 goto bad_vector2;
620
621 // now recompute right vector, in case it wasn't entirely perpendiclar
622 *xvec = *yvec ^ *zvec;
623 }
624 } else { // use up vec
625
626 *yvec = *uvec;
627 if (vm_NormalizeVector(yvec) == 0)
628 goto bad_vector2;
629
630 *xvec = *yvec ^ *zvec;
631
632 // normalize new perpendicular vector

Callers 1

vm_VectorToMatrixFunction · 0.70

Calls 1

vm_NormalizeVectorFunction · 0.85

Tested by

no test coverage detected