Changeset 13041 for OpenSceneGraph/trunk/src/osg/Matrix_implementation.cpp
 Timestamp:
 03/21/12 18:36:20 (5 years ago)
 Files:

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/src/osg/Matrix_implementation.cpp
r13008 r13041 1 /* *c++* OpenSceneGraph  Copyright (C) 19982006 Robert Osfield 1 /* *c++* OpenSceneGraph  Copyright (C) 19982006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 88 88 rlength2 = 2.0; 89 89 } 90 90 91 91 // Source: Gamasutra, Rotating Objects Using Quaternions 92 92 // 93 93 //http://www.gamasutra.com/features/19980703/quaternions_01.htm 94 94 95 95 double wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2; 96 96 97 97 // calculate coefficients 98 98 x2 = rlength2*QX; 99 99 y2 = rlength2*QY; 100 100 z2 = rlength2*QZ; 101 101 102 102 xx = QX * x2; 103 103 xy = QX * y2; 104 104 xz = QX * z2; 105 105 106 106 yy = QY * y2; 107 107 yz = QY * z2; 108 108 zz = QZ * z2; 109 109 110 110 wx = QW * x2; 111 111 wy = QW * y2; 112 112 wz = QW * z2; 113 113 114 114 // Note. Gamasutra gets the matrix assignments inverted, resulting 115 // in lefthanded rotations, which is contrary to OpenGL and OSG's 115 // in lefthanded rotations, which is contrary to OpenGL and OSG's 116 116 // methodology. The matrix assignment has been altered in the next 117 117 // few lines of code to do the right thing. … … 120 120 _mat[1][0] = xy  wz; 121 121 _mat[2][0] = xz + wy; 122 123 122 123 124 124 _mat[0][1] = xy + wz; 125 125 _mat[1][1] = 1.0  (xx + zz); 126 126 _mat[2][1] = yz  wx; 127 127 128 128 _mat[0][2] = xz  wy; 129 129 _mat[1][2] = yz + wx; … … 172 172 /* perform instant calculation */ 173 173 QW = tq[0]; 174 QX = _mat[1][2]_mat[2][1]; 175 QY = _mat[2][0]_mat[0][2]; 176 QZ = _mat[0][1]_mat[1][0]; 174 QX = _mat[1][2]_mat[2][1]; 175 QY = _mat[2][0]_mat[0][2]; 176 QZ = _mat[0][1]_mat[1][0]; 177 177 } 178 178 else if (j==1) 179 179 { 180 QW = _mat[1][2]_mat[2][1]; 180 QW = _mat[1][2]_mat[2][1]; 181 181 QX = tq[1]; 182 QY = _mat[0][1]+_mat[1][0]; 183 QZ = _mat[2][0]+_mat[0][2]; 182 QY = _mat[0][1]+_mat[1][0]; 183 QZ = _mat[2][0]+_mat[0][2]; 184 184 } 185 185 else if (j==2) 186 186 { 187 QW = _mat[2][0]_mat[0][2]; 188 QX = _mat[0][1]+_mat[1][0]; 187 QW = _mat[2][0]_mat[0][2]; 188 QX = _mat[0][1]+_mat[1][0]; 189 189 QY = tq[2]; 190 QZ = _mat[1][2]+_mat[2][1]; 190 QZ = _mat[1][2]+_mat[2][1]; 191 191 } 192 192 else /* if (j==3) */ 193 193 { 194 QW = _mat[0][1]_mat[1][0]; 195 QX = _mat[2][0]+_mat[0][2]; 196 QY = _mat[1][2]+_mat[2][1]; 194 QW = _mat[0][1]_mat[1][0]; 195 QX = _mat[2][0]+_mat[0][2]; 196 QY = _mat[1][2]+_mat[2][1]; 197 197 QZ = tq[3]; 198 198 } … … 409 409 } 410 410 411 void Matrix_implementation::makeRotate( value_type angle, value_type x, value_type y, value_type z ) 411 void Matrix_implementation::makeRotate( value_type angle, value_type x, value_type y, value_type z ) 412 412 { 413 413 makeIdentity(); … … 425 425 } 426 426 427 void Matrix_implementation::makeRotate( value_type angle1, const Vec3f& axis1, 427 void Matrix_implementation::makeRotate( value_type angle1, const Vec3f& axis1, 428 428 value_type angle2, const Vec3f& axis2, 429 429 value_type angle3, const Vec3f& axis3) … … 432 432 433 433 Quat quat; 434 quat.makeRotate(angle1, axis1, 434 quat.makeRotate(angle1, axis1, 435 435 angle2, axis2, 436 436 angle3, axis3); … … 438 438 } 439 439 440 void Matrix_implementation::makeRotate( value_type angle1, const Vec3d& axis1, 440 void Matrix_implementation::makeRotate( value_type angle1, const Vec3d& axis1, 441 441 value_type angle2, const Vec3d& axis2, 442 442 value_type angle3, const Vec3d& axis3) … … 445 445 446 446 Quat quat; 447 quat.makeRotate(angle1, axis1, 447 quat.makeRotate(angle1, axis1, 448 448 angle2, axis2, 449 449 angle3, axis3); … … 452 452 453 453 void Matrix_implementation::mult( const Matrix_implementation& lhs, const Matrix_implementation& rhs ) 454 { 454 { 455 455 if (&lhs==this) 456 456 { … … 531 531 value_type y_colMag = (rhs._mat[0][1] * rhs._mat[0][1]) + (rhs._mat[1][1] * rhs._mat[1][1]) + (rhs._mat[2][1] * rhs._mat[2][1]); 532 532 value_type z_colMag = (rhs._mat[0][2] * rhs._mat[0][2]) + (rhs._mat[1][2] * rhs._mat[1][2]) + (rhs._mat[2][2] * rhs._mat[2][2]); 533 533 534 534 if(!equivalent((double)x_colMag, 1.0) && !equivalent((double)x_colMag, 0.0)) 535 535 { … … 658 658 if( osg::square(d1.0) > 1.0e6 ) // Involves perspective, so we must 659 659 { // compute the full inverse 660 660 661 661 Matrix_implementation TPinv; 662 662 _mat[3][0] = _mat[3][1] = _mat[3][2] = 0.0; … … 832 832 zNear = (_mat[3][2]+1.0) / _mat[2][2]; 833 833 zFar = (_mat[3][2]1.0) / _mat[2][2]; 834 834 835 835 left = (1.0+_mat[3][0]) / _mat[0][0]; 836 836 right = (1.0_mat[3][0]) / _mat[0][0]; … … 838 838 bottom = (1.0+_mat[3][1]) / _mat[1][1]; 839 839 top = (1.0_mat[3][1]) / _mat[1][1]; 840 840 841 841 return true; 842 } 842 } 843 843 844 844 bool Matrix_implementation::getOrtho(Matrix_implementation::other_value_type& left, Matrix_implementation::other_value_type& right, … … 895 895 top = temp_near * (1.0+_mat[2][1]) / _mat[1][1]; 896 896 bottom = temp_near * (_mat[2][1]1.0) / _mat[1][1]; 897 897 898 898 zNear = temp_near; 899 899 zFar = temp_far; 900 900 901 901 return true; 902 } 902 } 903 903 904 904 bool Matrix_implementation::getFrustum(Matrix_implementation::other_value_type& left, Matrix_implementation::other_value_type& right,