Rotation.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00027 //
00029 
00030 #ifndef __ROTATION_H__
00031 #define __ROTATION_H__
00032 
00033 #include "H3DApi.h"
00034 #include "H3DBasicTypes.h"
00035 #include "H3DMath.h"
00036 #include "Vec3f.h"
00037 #include "H3DTemplateOperators.h"
00038 
00039 namespace H3D {
00040   namespace ArithmeticTypes {
00041     // forward declarations.
00042     class Matrix3f;
00043     class Matrix3d;
00044     class Quaternion;
00045 
00049     class H3DAPI_API Rotation {
00050     public:
00052       Rotation() : axis( 0,0,0 ), angle( 0 ) {}
00053 
00056       Rotation( H3DFloat x,
00057                 H3DFloat y,
00058                 H3DFloat z,
00059                 H3DFloat a ) : axis( x, y, z ), angle(a) {}
00060 
00064       Rotation( const Vec3f &_axis, 
00065                 H3DFloat _angle ) : axis( _axis ), angle( _angle ) {}
00066 
00070       Rotation( const Vec3f &n1, const Vec3f &n2 );
00071 
00073       explicit Rotation( const Vec3f &euler_angles );
00074 
00076       explicit Rotation( const Vec3d &euler_angles );
00077 
00079       Rotation( const Quaternion &r );
00080       
00083       explicit Rotation( const Matrix3f &m );
00084 
00087       explicit Rotation( const Matrix3d &m );
00088       
00091       Vec3f toEulerAngles(); 
00092 
00096       Rotation slerp( const Rotation &r, 
00097                       H3DFloat t ) const;
00098 
00100       Vec3f axis;
00101 
00103       H3DFloat angle;
00104     };
00105 
00112 
00114     inline bool operator==( const Rotation &r1, const Rotation &r2 ) {
00115       return r1.axis == r2.axis && r1.angle == r2.angle;
00116     }
00117                 
00121     inline Rotation operator-( const Rotation &r ) {
00122       return Rotation( r.axis, -r.angle );
00123     }
00124 
00126     inline Rotation operator*( const Rotation &r, 
00127                                double d ) {    
00128       return Rotation( r.axis, (H3DFloat) (r.angle * d) );
00129     }
00130 
00132     inline Rotation operator*( const Rotation &r, 
00133                                float f ) {    
00134       return Rotation( r.axis, (H3DFloat) (r.angle * f) );
00135     }
00136 
00138     inline Rotation operator*( const Rotation &r, 
00139                                int i ) {    
00140       return Rotation( r.axis, r.angle * i );
00141     }
00142 
00144     inline Rotation operator*( const Rotation &r, 
00145                                long i ) {    
00146       return Rotation( r.axis, r.angle * i );
00147     }
00148 
00150     inline Rotation operator*( const float &a, 
00151                                const Rotation &b ) { 
00152       return b * a;
00153     }
00154 
00156     inline Rotation operator*( const double &a, 
00157                                const Rotation &b ) { 
00158       return b * a;
00159     }
00160 
00162     inline Rotation operator*( const int &a, 
00163                                const Rotation &b ) { 
00164       return b * a;
00165     }
00166 
00168     inline Rotation operator*( const long &a, 
00169                                const Rotation &b ) { 
00170       return b * a;
00171     }
00172 
00174           inline ostream& operator<<( ostream &os, const Rotation &r ) {
00175                   os << r.axis << " " << r.angle;
00176                   return os;
00177           }
00178 
00180     Rotation H3DAPI_API operator*( const Rotation &r1 ,const Rotation &r2 );
00181    }
00182 }
00183 
00184 #endif

Generated on Thu Aug 24 12:38:34 2006 for H3D API by  doxygen 1.4.5