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

Function ConvertEulerToAxisAmount

physics/collide.cpp:1523–1568  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1521}
1522
1523void ConvertEulerToAxisAmount(vector *e, vector *n, float *w) {
1524 float rotspeed = vm_GetMagnitude(e);
1525 matrix rotmat;
1526 vector e_n;
1527 float scale = rotspeed / .0001f;
1528
1529 // If there isn't a rotation, return something valid
1530 if (rotspeed == 0.0f || scale == 0.0f) {
1531 *n = Zero_vector;
1532 n->y = 1.0f;
1533 *w = 0.0f;
1534
1535 return;
1536 }
1537
1538 e_n = *e / scale;
1539
1540 CollideAnglesToMatrix(&rotmat, e_n.x, e_n.y, e_n.z);
1541
1542 // This is from Graphics Gems 1 p.467 I am converting from a angle vector
1543 // to the normal of that rotation (you can also get the angle about that normal, but
1544 // we don't need it)
1545 n->x = rotmat.uvec.z - rotmat.fvec.y;
1546 n->y = rotmat.fvec.x - rotmat.rvec.z;
1547 n->z = rotmat.rvec.y - rotmat.uvec.x;
1548
1549 if (*n != Zero_vector) {
1550 vm_NormalizeVector(n);
1551
1552 float ct = (rotmat.rvec.x + rotmat.uvec.y + rotmat.fvec.z - 1.0f) / 2.0f;
1553 if (ct < -1.0f)
1554 ct = -1.0f;
1555 else if (ct > 1.0f)
1556 ct = 1.0f;
1557
1558 float v = acos(ct);
1559 float z = sin(v);
1560
1561 *w = rotspeed * ((2.0f * PI) / (65535.0f));
1562
1563 if (z >= 0.0f)
1564 *n *= -1.0f;
1565 } else {
1566 *w = 0.0f;
1567 }
1568}
1569
1570void ConvertAxisAmountToEuler(vector *n, float *w, vector *e) {
1571 float s;

Callers 3

bump_obj_against_fixedFunction · 0.85
bump_two_objectsFunction · 0.85
PointSpeedFunction · 0.85

Calls 3

CollideAnglesToMatrixFunction · 0.85
vm_NormalizeVectorFunction · 0.85
vm_GetMagnitudeFunction · 0.50

Tested by

no test coverage detected