| 1521 | } |
| 1522 | |
| 1523 | void 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 | |
| 1570 | void ConvertAxisAmountToEuler(vector *n, float *w, vector *e) { |
| 1571 | float s; |
no test coverage detected