gKitGL
Orbiter.h
00001 
00002 #ifndef _GK_ORBITER_H
00003 #define _GK_ORBITER_H
00004 
00005 #include "Transform.h"
00006 
00007 
00008 namespace gk {
00009 
00010 //! place et oriente un objet, construit une transformation XYZT.    
00011 class Orbiter
00012 {
00013 protected:
00014     Transform m_transform;
00015 
00016     Point m_position;
00017     float m_rotation_x;
00018     float m_rotation_y;
00019     float m_rotation_z;
00020 
00021 public:
00022     //! renvoie la position de l'origine.
00023     const Point origin( ) const
00024     {
00025         return m_transform.inverse( Point(0.f, 0.f, 0.f) );
00026     }
00027     
00028     //! renvoie le vecteur 'vers le haut'.
00029     const Vector up( ) const // Y
00030     {
00031         return m_transform.inverse( Vector(0.f, 1.f, 0.f) );
00032     }
00033     
00034     //! renvoie le vecteur 'vers la droite'.
00035     const Vector right( ) const      // X
00036     {
00037         return m_transform.inverse( Vector(1.f, 0.f, 0.f) );
00038     }
00039     
00040     //! renvoie le vecteur 'devant'.
00041     const Vector forward( ) const    // Z
00042     {
00043         return m_transform.inverse( Vector(0.f, 0.f, 1.f) );
00044     }
00045 
00046 public:
00047     //! constructeur par defaut : transformation identite.
00048     Orbiter( ) 
00049         :
00050         m_transform(),
00051         m_position(),
00052         m_rotation_x(0.f),
00053         m_rotation_y(0.f),
00054         m_rotation_z(0.f)
00055     {}
00056     
00057     //! constructeur : precise l'orientation de l'objet (et eventuellement sa position).
00058     Orbiter( const float rx, const float ry, const float rz, const Point& position= Point(0.f, 0.f, 0.f) ) 
00059         :
00060         m_transform(),
00061         m_position(position),
00062         m_rotation_x(rx),
00063         m_rotation_y(ry),
00064         m_rotation_z(rz)
00065     {
00066         transform();
00067     }
00068     
00069     //! destructeur.
00070     ~Orbiter( ) {}
00071     
00072     //! re-initialise la transformation.
00073     void reset( )
00074     {
00075         m_transform= Transform();
00076         m_position= Point();
00077         m_rotation_x= 0.f;
00078         m_rotation_y= 0.f;
00079         m_rotation_z= 0.f;
00080     }
00081     
00082     //! deplace l'objet, vers l'avant, +Z.
00083     void moveForward( const float v )
00084     {
00085         m_position= m_position + forward() * v;
00086     }
00087     
00088     //! deplace l'objet, vers la droite, +X.
00089     void moveRight( const float v )
00090     {
00091         m_position= m_position + right() * v;
00092     }
00093     
00094     //! deplace l'objet, en haut, +Y.
00095     void moveUp( const float v )
00096     {
00097         m_position= m_position + up() * v;
00098     }
00099     
00100     //! repositionne l'objet.
00101     void move( const Point& p )
00102     {
00103         m_position= p;
00104     }
00105     
00106     //! rotation gauche-droite (autour de up / Y local).
00107     void rotateUp( const float v )
00108     {
00109         m_rotation_y+= v;
00110     }
00111     
00112     //! rotation haut-bas (autour de right / X local).
00113     void rotateRight( const float v )
00114     {
00115         m_rotation_x+= v;
00116     }
00117     
00118     //! rotation autour de l'axe optique (forward / Z).
00119     void rotateForward( const float v )
00120     {
00121         m_rotation_z+= v;
00122     }
00123     
00124     //! renvoie la transformation.
00125     const Transform& transform( )
00126     {
00127         m_transform= Translate( Vector(m_position) ) * RotateZ(m_rotation_z) * RotateX(m_rotation_x) * RotateY(m_rotation_y);
00128         return m_transform;
00129     }
00130     
00131     //! renvoie l'origine du repere.
00132     const Point& position( ) const
00133     {
00134         return m_position;
00135     }
00136     
00137     //! renvoie l'orientation autour de l'axe up.
00138     float rotationUp( ) const
00139     {
00140         return m_rotation_y;
00141     }
00142     
00143     //! renvoie l'orientation autour de l'axe right.
00144     float rotationRight( ) const
00145     {
00146         return m_rotation_x;
00147     }
00148     
00149     //! renvoie l'orientation autour de l'axe forward.
00150     float rotationForward( ) const
00151     {
00152         return m_rotation_z;
00153     }
00154 };
00155 
00156 }
00157 
00158 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerator Friends