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

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/include/osg/Matrixd
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 double value_type; 31 31 typedef float other_value_type; … … 66 66 return *this; 67 67 } 68 68 69 69 Matrixd& operator = (const Matrixf& 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 126 127 /** decompose the matrix into translation, rotation, scale and scale orientation.*/ 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 Matrixd& rhs); 244 244 245 /** orthonormalize the 3x3 rotation & scale matrix */ 246 void orthoNormalize(const Matrixd& rhs); 245 /** orthonormalize the 3x3 rotation & scale matrix */ 246 void orthoNormalize(const Matrixd& rhs); 247 247 248 248 // basic utility functions to create new matrices … … 259 259 inline static Matrixd rotate( value_type angle, const Vec3f& axis); 260 260 inline static Matrixd rotate( value_type angle, const Vec3d& axis); 261 inline static Matrixd rotate( value_type angle1, const Vec3f& axis1, 261 inline static Matrixd 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 Matrixd rotate( value_type angle1, const Vec3d& axis1, 264 inline static Matrixd 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 Matrixd rotate( const Quat& quat); 268 268 inline static Matrixd inverse( const Matrixd& matrix); 269 inline static Matrixd orthoNormal(const Matrixd& matrix); 269 inline static Matrixd orthoNormal(const Matrixd& matrix); 270 270 /** Create an orthographic projection matrix. 271 271 * See glOrtho for further details. … … 337 337 void setTrans( const Vec3f& v ); 338 338 void setTrans( const Vec3d& v ); 339 340 inline Vec3d getTrans() const { return Vec3d(_mat[3][0],_mat[3][1],_mat[3][2]); } 341 339 340 inline Vec3d getTrans() const { return Vec3d(_mat[3][0],_mat[3][1],_mat[3][2]); } 341 342 342 inline Vec3d getScale() const { 343 Vec3d x_vec(_mat[0][0],_mat[1][0],_mat[2][0]); 344 Vec3d y_vec(_mat[0][1],_mat[1][1],_mat[2][1]); 345 Vec3d z_vec(_mat[0][2],_mat[1][2],_mat[2][2]); 346 return Vec3d(x_vec.length(), y_vec.length(), z_vec.length()); 343 Vec3d x_vec(_mat[0][0],_mat[1][0],_mat[2][0]); 344 Vec3d y_vec(_mat[0][1],_mat[1][1],_mat[2][1]); 345 Vec3d z_vec(_mat[0][2],_mat[1][2],_mat[2][2]); 346 return Vec3d(x_vec.length(), y_vec.length(), z_vec.length()); 347 347 } 348 348 349 349 /** apply a 3x3 transform of v*M[0..2,0..2]. */ 350 350 inline static Vec3f transform3x3(const Vec3f& v,const Matrixd& m); … … 383 383 inline void postMultRotate( const Quat& q ); 384 384 385 inline void operator *= ( const Matrixd& other ) 385 inline void operator *= ( const Matrixd& other ) 386 386 { if( this == &other ) { 387 387 Matrixd temp(other); 388 388 postMult( temp ); 389 389 } 390 else postMult( other ); 390 else postMult( other ); 391 391 } 392 392 … … 406 406 { 407 407 public: 408 408 409 409 RefMatrixd():Object(false), Matrixd() {} 410 410 RefMatrixd( const Matrixd& other) : Object(false), Matrixd(other) {} … … 416 416 Matrixd::value_type a20, Matrixd::value_type a21, Matrixd::value_type a22, Matrixd::value_type a23, 417 417 Matrixd::value_type a30, Matrixd::value_type a31, Matrixd::value_type a32, Matrixd::value_type a33): 418 Object(false), 418 Object(false), 419 419 Matrixd(a00, a01, a02, a03, 420 420 a10, a11, a12, a13, … … 422 422 a30, a31, a32, a33) {} 423 423 424 virtual Object* cloneType() const { return new RefMatrixd(); } 424 virtual Object* cloneType() const { return new RefMatrixd(); } 425 425 virtual Object* clone(const CopyOp&) const { return new RefMatrixd(*this); } 426 426 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const RefMatrixd*>(obj)!=NULL; } 427 427 virtual const char* libraryName() const { return "osg"; } 428 428 virtual const char* className() const { return "Matrix"; } 429 430 429 430 431 431 protected: 432 432 433 433 virtual ~RefMatrixd() {} 434 434 }; … … 499 499 return m; 500 500 } 501 inline Matrixd Matrixd::rotate( value_type angle1, const Vec3f& axis1, 501 inline Matrixd Matrixd::rotate( value_type angle1, const Vec3f& axis1, 502 502 value_type angle2, const Vec3f& axis2, 503 503 value_type angle3, const Vec3f& axis3) … … 507 507 return m; 508 508 } 509 inline Matrixd Matrixd::rotate( value_type angle1, const Vec3d& axis1, 509 inline Matrixd Matrixd::rotate( value_type angle1, const Vec3d& axis1, 510 510 value_type angle2, const Vec3d& axis2, 511 511 value_type angle3, const Vec3d& axis3) … … 539 539 Matrixd m; 540 540 m.orthoNormalize(matrix); 541 return m; 541 return m; 542 542 } 543 543