| 578 | |
| 579 | |
| 580 | Matrix* TriMatrixArcFromForward( |
| 581 | Matrix* out, |
| 582 | const Vector3* v ) |
| 583 | { |
| 584 | Vector3 norm = Normalize( *v ); |
| 585 | *out = IdentityMatrix(); |
| 586 | if( norm.z < -0.99999f ) |
| 587 | { |
| 588 | return out; |
| 589 | } |
| 590 | if( norm.z > 0.99999f ) |
| 591 | { |
| 592 | out->_22 = -1.0f; |
| 593 | out->_33 = -1.0f; |
| 594 | return out; |
| 595 | } |
| 596 | const float h = ( 1.0f + norm.z ) / ( norm.x * norm.x + norm.y * norm.y ); |
| 597 | out->_11 = h * norm.y * norm.y - norm.z; |
| 598 | out->_12 = -h * norm.x * norm.y; |
| 599 | out->_13 = norm.x; |
| 600 | |
| 601 | out->_21 = out->_12; |
| 602 | out->_22 = h * norm.x * norm.x - norm.z; |
| 603 | out->_23 = norm.y; |
| 604 | |
| 605 | out->_31 = -norm.x; |
| 606 | out->_32 = -norm.y; |
| 607 | out->_33 = -norm.z; |
| 608 | ; |
| 609 | //*out = tempMat; |
| 610 | return out; |
| 611 | } |
| 612 | |
| 613 | Matrix* TriMatrixTranslate( Matrix* out, const Matrix* m, const Vector3* v ) |
| 614 | { |