Changeset 13041 for OpenSceneGraph/trunk/include/osg/Matrixf
 Timestamp:
 03/21/12 18:36:20 (4 years ago)
 Files:

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/include/osg/Matrixf
r13008 r13041 1 /* *c++* OpenSceneGraph  Copyright (C) 19982004 Robert Osfield 1 /* *c++* OpenSceneGraph  Copyright (C) 19982004 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 */ … … 27 27 { 28 28 public: 29 29 30 30 typedef float value_type; 31 31 typedef double other_value_type; … … 66 66 return *this; 67 67 } 68 68 69 69 Matrixf& operator = (const Matrixd& other); 70 70 … … 78 78 for(int i=0;i<16;++i) local_ptr[i]=(value_type)ptr[i]; 79 79 } 80 80 81 81 inline void set(double const * const ptr) 82 82 { … … 89 89 value_type a20, value_type a21, value_type a22,value_type a23, 90 90 value_type a30, value_type a31, value_type a32,value_type a33); 91 91 92 92 value_type * ptr() { return (value_type*)_mat; } 93 93 const value_type * ptr() const { return (const value_type *)_mat; } … … 102 102 103 103 void makeIdentity(); 104 104 105 105 void makeScale( const Vec3f& ); 106 106 void makeScale( const Vec3d& ); 107 107 void makeScale( value_type, value_type, value_type ); 108 108 109 109 void makeTranslate( const Vec3f& ); 110 110 void makeTranslate( const Vec3d& ); 111 111 void makeTranslate( value_type, value_type, value_type ); 112 112 113 113 void makeRotate( const Vec3f& from, const Vec3f& to ); 114 114 void makeRotate( const Vec3d& from, const Vec3d& to ); … … 117 117 void makeRotate( value_type angle, value_type x, value_type y, value_type z ); 118 118 void makeRotate( const Quat& ); 119 void makeRotate( value_type angle1, const Vec3f& axis1, 119 void makeRotate( value_type angle1, const Vec3f& axis1, 120 120 value_type angle2, const Vec3f& axis2, 121 121 value_type angle3, const Vec3f& axis3); 122 void makeRotate( value_type angle1, const Vec3d& axis1, 122 void makeRotate( value_type angle1, const Vec3d& axis1, 123 123 value_type angle2, const Vec3d& axis2, 124 124 value_type angle3, const Vec3d& axis3); 125 125 126 127 /** decompose the matrix into translation, rotation, scale and scale orientation.*/ 126 127 /** decompose the matrix into translation, rotation, scale and scale orientation.*/ 128 128 void decompose( osg::Vec3f& translation, 129 osg::Quat& rotation, 130 osg::Vec3f& scale, 129 osg::Quat& rotation, 130 osg::Vec3f& scale, 131 131 osg::Quat& so ) const; 132 132 133 /** decompose the matrix into translation, rotation, scale and scale orientation.*/ 133 /** decompose the matrix into translation, rotation, scale and scale orientation.*/ 134 134 void decompose( osg::Vec3d& translation, 135 osg::Quat& rotation, 136 osg::Vec3d& scale, 135 osg::Quat& rotation, 136 osg::Vec3d& scale, 137 137 osg::Quat& so ) const; 138 138 … … 243 243 bool invert_4x4( const Matrixf& rhs); 244 244 245 /** orthonormalize the 3x3 rotation & scale matrix */ 246 void orthoNormalize(const Matrixf& rhs); 245 /** orthonormalize the 3x3 rotation & scale matrix */ 246 void orthoNormalize(const Matrixf& rhs); 247 247 248 248 //basic utility functions to create new matrices … … 259 259 inline static Matrixf rotate( value_type angle, const Vec3f& axis); 260 260 inline static Matrixf rotate( value_type angle, const Vec3d& axis); 261 inline static Matrixf rotate( value_type angle1, const Vec3f& axis1, 261 inline static Matrixf rotate( value_type angle1, const Vec3f& axis1, 262 262 value_type angle2, const Vec3f& axis2, 263 263 value_type angle3, const Vec3f& axis3); 264 inline static Matrixf rotate( value_type angle1, const Vec3d& axis1, 264 inline static Matrixf rotate( value_type angle1, const Vec3d& axis1, 265 265 value_type angle2, const Vec3d& axis2, 266 266 value_type angle3, const Vec3d& axis3); 267 267 inline static Matrixf rotate( const Quat& quat); 268 268 inline static Matrixf inverse( const Matrixf& matrix); 269 inline static Matrixf orthoNormal(const Matrixf& matrix); 270 269 inline static Matrixf orthoNormal(const Matrixf& matrix); 270 271 271 /** Create an orthographic projection matrix. 272 272 * See glOrtho for further details. … … 339 339 void setTrans( const Vec3f& v ); 340 340 void setTrans( const Vec3d& v ); 341 342 inline Vec3d getTrans() const { return Vec3d(_mat[3][0],_mat[3][1],_mat[3][2]); } 343 341 342 inline Vec3d getTrans() const { return Vec3d(_mat[3][0],_mat[3][1],_mat[3][2]); } 343 344 344 inline Vec3d getScale() const { 345 Vec3d x_vec(_mat[0][0],_mat[1][0],_mat[2][0]); 346 Vec3d y_vec(_mat[0][1],_mat[1][1],_mat[2][1]); 347 Vec3d z_vec(_mat[0][2],_mat[1][2],_mat[2][2]); 348 return Vec3d(x_vec.length(), y_vec.length(), z_vec.length()); 349 } 350 345 Vec3d x_vec(_mat[0][0],_mat[1][0],_mat[2][0]); 346 Vec3d y_vec(_mat[0][1],_mat[1][1],_mat[2][1]); 347 Vec3d z_vec(_mat[0][2],_mat[1][2],_mat[2][2]); 348 return Vec3d(x_vec.length(), y_vec.length(), z_vec.length()); 349 } 350 351 351 /** apply a 3x3 transform of v*M[0..2,0..2]. */ 352 352 inline static Vec3f transform3x3(const Vec3f& v,const Matrixf& m); … … 385 385 inline void postMultRotate( const Quat& q ); 386 386 387 inline void operator *= ( const Matrixf& other ) 387 inline void operator *= ( const Matrixf& other ) 388 388 { if( this == &other ) { 389 389 Matrixf temp(other); 390 390 postMult( temp ); 391 391 } 392 else postMult( other ); 392 else postMult( other ); 393 393 } 394 394 … … 430 430 _mat[3][3]*=rhs; 431 431 return *this; 432 } 432 } 433 433 434 434 /** Divide by scalar. */ … … 462 462 _mat[3][3]/=rhs; 463 463 return *this; 464 } 464 } 465 465 466 466 /** Binary vector add. */ … … 483 483 _mat[3][1] + rhs._mat[3][1], 484 484 _mat[3][2] + rhs._mat[3][2], 485 _mat[3][3] + rhs._mat[3][3]); 485 _mat[3][3] + rhs._mat[3][3]); 486 486 } 487 487 … … 508 508 _mat[3][3] += rhs._mat[3][3]; 509 509 return *this; 510 } 510 } 511 511 512 512 protected: … … 518 518 { 519 519 public: 520 520 521 521 RefMatrixf():Object(false), Matrixf() {} 522 522 RefMatrixf( const Matrixf& other) : Object(false), Matrixf(other) {} … … 528 528 Matrixf::value_type a20, Matrixf::value_type a21, Matrixf::value_type a22, Matrixf::value_type a23, 529 529 Matrixf::value_type a30, Matrixf::value_type a31, Matrixf::value_type a32, Matrixf::value_type a33): 530 Object(false), 530 Object(false), 531 531 Matrixf(a00, a01, a02, a03, 532 532 a10, a11, a12, a13, … … 534 534 a30, a31, a32, a33) {} 535 535 536 virtual Object* cloneType() const { return new RefMatrixf(); } 536 virtual Object* cloneType() const { return new RefMatrixf(); } 537 537 virtual Object* clone(const CopyOp&) const { return new RefMatrixf(*this); } 538 538 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const RefMatrixf*>(obj)!=NULL; } 539 539 virtual const char* libraryName() const { return "osg"; } 540 540 virtual const char* className() const { return "Matrix"; } 541 542 541 542 543 543 protected: 544 544 545 545 virtual ~RefMatrixf() {} 546 546 }; … … 611 611 return m; 612 612 } 613 inline Matrixf Matrixf::rotate( value_type angle1, const Vec3f& axis1, 613 inline Matrixf Matrixf::rotate( value_type angle1, const Vec3f& axis1, 614 614 value_type angle2, const Vec3f& axis2, 615 615 value_type angle3, const Vec3f& axis3) … … 619 619 return m; 620 620 } 621 inline Matrixf Matrixf::rotate( value_type angle1, const Vec3d& axis1, 621 inline Matrixf Matrixf::rotate( value_type angle1, const Vec3d& axis1, 622 622 value_type angle2, const Vec3d& axis2, 623 623 value_type angle3, const Vec3d& axis3) … … 651 651 Matrixf m; 652 652 m.orthoNormalize(matrix); 653 return m; 653 return m; 654 654 } 655 655