Matching in Ratatouille, minus debug stuff: https://decomp.me/scratch/VthMZ
| 551 | |
| 552 | // Matching in Ratatouille, minus debug stuff: https://decomp.me/scratch/VthMZ |
| 553 | void xQuatFromMat(xQuat* q, const xMat3x3* m) |
| 554 | { |
| 555 | F32* mp = (F32*)m; |
| 556 | F32* qvp = (F32*)q; |
| 557 | F32 tr = m->right.x + m->up.y + m->at.z; |
| 558 | F32 root; |
| 559 | |
| 560 | if (tr > 0.0f) |
| 561 | { |
| 562 | root = xsqrt(1.0f + tr); |
| 563 | q->s = 0.5f * root; |
| 564 | root = 0.5f / root; |
| 565 | q->v.x = root * (m->at.y - m->up.z); |
| 566 | q->v.y = root * (m->right.z - m->at.x); |
| 567 | q->v.z = root * (m->up.x - m->right.y); |
| 568 | } |
| 569 | else |
| 570 | { |
| 571 | static S32 nxt[3] = { 1, 2, 0 }; |
| 572 | |
| 573 | S32 i = 0; |
| 574 | if (mp[5] > mp[0]) |
| 575 | i = 1; |
| 576 | if (mp[10] > mp[i * 5]) |
| 577 | i = 2; |
| 578 | |
| 579 | S32 j = nxt[i]; |
| 580 | S32 k = nxt[j]; |
| 581 | |
| 582 | root = xsqrt(mp[i * 5] - mp[j * 5] - mp[k * 5] + 1.0f); |
| 583 | if (xabs(root) < 1e-5f) |
| 584 | { |
| 585 | xQuatCopy(q, &g_IQ); |
| 586 | return; |
| 587 | } |
| 588 | |
| 589 | qvp[i] = 0.5f * root; |
| 590 | root = 0.5f / root; |
| 591 | q->s = root * (mp[j + k * 4] - mp[k + j * 4]); |
| 592 | qvp[j] = root * (mp[i + j * 4] + mp[j + i * 4]); |
| 593 | qvp[k] = root * (mp[i + k * 4] + mp[k + i * 4]); |
| 594 | |
| 595 | if (q->s < 0.0f) |
| 596 | { |
| 597 | xQuatFlip(q, q); |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | void xQuatFromAxisAngle(xQuat* q, const xVec3* a, F32 t) |
| 603 | { |
no test coverage detected