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

Function vm_ExtractAnglesFromMatrix

vecmat/vector.cpp:680–707  ·  view source on GitHub ↗

extract angles from a matrix

Source from the content-addressed store, hash-verified

678
679// extract angles from a matrix
680angvec *vm_ExtractAnglesFromMatrix(angvec *a, matrix *m) {
681 float sinh, cosh, cosp, sinb, cosb;
682
683 // Deal with straight up or straight down
684 if (IS_ZERO(m->fvec.x) && IS_ZERO(m->fvec.z)) {
685 a->p = (m->fvec.y > 0) ? 0xc000 : 0x4000;
686 a->b = 0.0;
687 a->h = FixAtan2(m->rvec.x, -m->rvec.z);
688 return a;
689 }
690
691 a->h = FixAtan2(m->fvec.z, m->fvec.x);
692
693 sinh = FixSin(a->h);
694 cosh = FixCos(a->h);
695
696 if (fabs(sinh) > fabs(cosh)) // sine is larger, so use it
697 cosp = (m->fvec.x / sinh);
698 else // cosine is larger, so use it
699 cosp = (m->fvec.z / cosh);
700 a->p = FixAtan2(cosp, -m->fvec.y);
701
702 sinb = (m->rvec.y / cosp);
703 cosb = (m->uvec.y / cosp);
704 a->b = FixAtan2(cosb, sinb);
705
706 return a;
707}
708
709// returns the value of a determinant
710float calc_det_value(matrix *det) {

Callers 15

SetModelAnglesFunction · 0.50
PhysicsDoSimRotFunction · 0.50
GetUVLForRoomPointFunction · 0.50
UpdateOrientationMethod · 0.50
BuildObjectLightmapUVsFunction · 0.50

Calls 3

FixAtan2Function · 0.50
FixSinFunction · 0.50
FixCosFunction · 0.50

Tested by

no test coverage detected