- Timestamp:
- 10/23/08 14:53:23 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.cpp
r2953 r3062 649 649 } 650 650 651 Matrix4x4 652 NormalTransformMatrix(const Matrix4x4 &tform)651 652 Matrix4x4 NormalTransformMatrix(const Matrix4x4 &tform) 653 653 { 654 654 Matrix4x4 m = tform; … … 692 692 return m; 693 693 } 694 /* 695 696 template<class REAL> 697 Matrix4<REAL>& scaleTranslateToFit(Matrix4<REAL>& output, const Vector3<REAL>& vMin, const Vector3<REAL>& vMax) { 698 const REAL diffX = vMax.x()-vMin.x(); 699 output[ 0] = 2/diffX; 700 output[ 4] = 0; 701 output[ 8] = 0; 702 output[12] = -(vMax.x()+vMin.x())/diffX; 703 704 const REAL diffY = vMax.y()-vMin.y(); 705 output[ 1] = 0; 706 output[ 5] = 2/diffY; 707 output[ 9] = 0; 708 output[13] = -(vMax.y()+vMin.y())/diffY; 709 710 const REAL diffZ = vMax.z()-vMin.z(); 711 output[ 2] = 0; 712 output[ 6] = 0; 713 output[10] = 2/diffZ; 714 output[14] = -(vMax.z()+vMin.z())/diffZ; 715 716 output[ 3] = 0; 717 output[ 7] = 0; 718 output[11] = 0; 719 output[15] = 1; 720 return output; 721 } 694 695 696 /** The resultig matrix that is equal to the result of glFrustum 722 697 */ 723 724 725 726 //output is initialized with the same result as glFrustum727 698 Matrix4x4 GetFrustum(float left, float right, 728 699 float bottom, float top, … … 781 752 782 753 783 } 754 /** The resultig matrix that is equal to the result of glOrtho 755 */ 756 Matrix4x4 GetOrtho(float left, float right, float bottom, float top, float far, float near) 757 { 758 Matrix4x4 m; 759 760 const float xDif = 1.0f / (right - left); 761 const float yDif = 1.0f / (top - bottom); 762 const float zDif = 1.0f / (far - near); 763 764 m.x[0][0] = 2.0f * xDif; 765 m.x[0][1] = .0f; 766 m.x[0][2] = .0f; 767 m.x[0][3] = .0f; 768 769 m.x[1][0] = .0f; 770 m.x[1][1] = 2.0f * yDif; 771 m.x[1][2] = .0f; 772 m.x[1][3] = .0f; 773 774 m.x[2][0] = .0f; 775 m.x[2][1] = .0f; 776 m.x[2][2] = -2.0f * zDif; 777 m.x[2][3] = .0f; 778 779 m.x[3][0] = (right + left) * xDif; 780 m.x[3][1] = (top + bottom) * yDif; 781 m.x[3][2] = (far + near) * zDif; 782 m.x[3][3] = 1.0f; 783 784 return m; 785 } 786 787 /** The resultig matrix that is equal to the result of gluPerspective 788 */ 789 Matrix4x4 GetPerspective(float fov, float aspect, float near, float far) 790 { 791 Matrix4x4 m; 792 793 const float x = 1.0f / tan(fov * 0.5f); 794 const float zDif = 1.0f / (near - far); 795 796 m.x[0][0] = x / aspect; 797 m.x[0][1] = .0f; 798 m.x[0][2] = .0f; 799 m.x[0][3] = .0f; 800 801 m.x[1][0] = .0f; 802 m.x[1][1] = x; 803 m.x[1][2] = .0f; 804 m.x[1][3] = .0f; 805 806 m.x[2][0] = .0f; 807 m.x[2][1] = .0f; 808 m.x[2][2] = (far + near) * zDif; 809 m.x[2][3] = -1.0f; 810 811 m.x[3][0] = .0f; 812 m.x[3][1] = .0f; 813 m.x[3][2] = 2.0f *(far * near) * zDif; 814 m.x[3][3] = 0.0f; 815 816 return m; 817 } 818 819 820 }
Note: See TracChangeset
for help on using the changeset viewer.