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

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/include/osg/Quat
r5328 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 */ … … 71 71 } 72 72 73 inline Quat( value_type angle1, const Vec3f& axis1, 73 inline Quat( value_type angle1, const Vec3f& axis1, 74 74 value_type angle2, const Vec3f& axis2, 75 75 value_type angle3, const Vec3f& axis3) … … 78 78 } 79 79 80 inline Quat( value_type angle1, const Vec3d& axis1, 80 inline Quat( value_type angle1, const Vec3d& axis1, 81 81 value_type angle2, const Vec3d& axis2, 82 82 value_type angle3, const Vec3d& axis3) … … 123 123 _v[3]=w; 124 124 } 125 125 126 126 inline void set(const osg::Vec4f& v) 127 127 { … … 139 139 _v[3]=v.w(); 140 140 } 141 141 142 142 void set(const Matrixf& matrix); 143 143 144 144 void set(const Matrixd& matrix); 145 145 146 146 void get(Matrixf& matrix) const; 147 147 148 148 void get(Matrixd& matrix) const; 149 149 150 150 151 151 inline value_type & operator [] (int i) { return _v[i]; } … … 163 163 164 164 /** return true if the Quat represents a zero rotation, and therefore can be ignored in computations.*/ 165 bool zeroRotation() const { return _v[0]==0.0 && _v[1]==0.0 && _v[2]==0.0 && _v[3]==1.0; } 166 167 168 /*  169 BASIC ARITHMETIC METHODS 165 bool zeroRotation() const { return _v[0]==0.0 && _v[1]==0.0 && _v[2]==0.0 && _v[3]==1.0; } 166 167 168 /*  169 BASIC ARITHMETIC METHODS 170 170 Implemented in terms of Vec4s. Some Vec4 operators, e.g. 171 171 operator* are not appropriate for quaternions (as 172 172 mathematical objects) so they are implemented differently. 173 Also define methods for conjugate and the multiplicative inverse. 173 Also define methods for conjugate and the multiplicative inverse. 174 174  */ 175 /// Multiply by scalar 175 /// Multiply by scalar 176 176 inline const Quat operator * (value_type rhs) const 177 177 { … … 179 179 } 180 180 181 /// Unary multiply by scalar 181 /// Unary multiply by scalar 182 182 inline Quat& operator *= (value_type rhs) 183 183 { … … 189 189 } 190 190 191 /// Binary multiply 191 /// Binary multiply 192 192 inline const Quat operator*(const Quat& rhs) const 193 193 { … … 198 198 } 199 199 200 /// Unary multiply 200 /// Unary multiply 201 201 inline Quat& operator*=(const Quat& rhs) 202 202 { … … 213 213 } 214 214 215 /// Divide by scalar 215 /// Divide by scalar 216 216 inline Quat operator / (value_type rhs) const 217 217 { … … 220 220 } 221 221 222 /// Unary divide by scalar 222 /// Unary divide by scalar 223 223 inline Quat& operator /= (value_type rhs) 224 224 { … … 231 231 } 232 232 233 /// Binary divide 233 /// Binary divide 234 234 inline const Quat operator/(const Quat& denom) const 235 235 { … … 237 237 } 238 238 239 /// Unary divide 239 /// Unary divide 240 240 inline Quat& operator/=(const Quat& denom) 241 241 { … … 244 244 } 245 245 246 /// Binary addition 246 /// Binary addition 247 247 inline const Quat operator + (const Quat& rhs) const 248 248 { … … 261 261 } 262 262 263 /// Binary subtraction 263 /// Binary subtraction 264 264 inline const Quat operator  (const Quat& rhs) const 265 265 { … … 268 268 } 269 269 270 /// Unary subtraction 270 /// Unary subtraction 271 271 inline Quat& operator = (const Quat& rhs) 272 272 { … … 297 297 } 298 298 299 /// Conjugate 299 /// Conjugate 300 300 inline Quat conj () const 301 { 301 { 302 302 return Quat( _v[0], _v[1], _v[2], _v[3] ); 303 303 } … … 309 309 } 310 310 311 /*  311 /*  312 312 METHODS RELATED TO ROTATIONS 313 313 Set a quaternion which will perform a rotation of an … … 319 319 Not inlined  see the Quat.cpp file for implementation 320 320  */ 321 void makeRotate( value_type angle, 321 void makeRotate( value_type angle, 322 322 value_type x, value_type y, value_type z ); 323 323 void makeRotate ( value_type angle, const Vec3f& vec ); 324 324 void makeRotate ( value_type angle, const Vec3d& vec ); 325 325 326 void makeRotate ( value_type angle1, const Vec3f& axis1, 326 void makeRotate ( value_type angle1, const Vec3f& axis1, 327 327 value_type angle2, const Vec3f& axis2, 328 328 value_type angle3, const Vec3f& axis3); 329 void makeRotate ( value_type angle1, const Vec3d& axis1, 329 void makeRotate ( value_type angle1, const Vec3d& axis1, 330 330 value_type angle2, const Vec3d& axis2, 331 331 value_type angle3, const Vec3d& axis3); … … 343 343 are coincident or opposite in direction.*/ 344 344 void makeRotate( const Vec3d& vec1, const Vec3d& vec2 ); 345 345 346 346 void makeRotate_original( const Vec3d& vec1, const Vec3d& vec2 ); 347 347 … … 358 358 As t goes from 0 to 1, the Quat object goes from "from" to "to". */ 359 359 void slerp ( value_type t, const Quat& from, const Quat& to); 360 360 361 361 /** Rotate a vector by this quaternion.*/ 362 362 Vec3f operator* (const Vec3f& v) const 363 363 { 364 364 // nVidia SDK implementation 365 Vec3f uv, uuv; 365 Vec3f uv, uuv; 366 366 Vec3f qvec(_v[0], _v[1], _v[2]); 367 367 uv = qvec ^ v; 368 uuv = qvec ^ uv; 369 uv *= ( 2.0f * _v[3] ); 370 uuv *= 2.0f; 368 uuv = qvec ^ uv; 369 uv *= ( 2.0f * _v[3] ); 370 uuv *= 2.0f; 371 371 return v + uv + uuv; 372 372 } 373 373 374 374 /** Rotate a vector by this quaternion.*/ 375 375 Vec3d operator* (const Vec3d& v) const 376 376 { 377 377 // nVidia SDK implementation 378 Vec3d uv, uuv; 378 Vec3d uv, uuv; 379 379 Vec3d qvec(_v[0], _v[1], _v[2]); 380 380 uv = qvec ^ v; 381 uuv = qvec ^ uv; 382 uv *= ( 2.0f * _v[3] ); 383 uuv *= 2.0f; 381 uuv = qvec ^ uv; 382 uv *= ( 2.0f * _v[3] ); 383 uuv *= 2.0f; 384 384 return v + uv + uuv; 385 385 } 386 386 387 387 protected: 388 388 389 389 }; // end of class prototype 390 390 391 391 } // end of namespace 392 392 393 #endif 393 #endif