TAPs 0.7.7.3
TAPsOpenGLCameraModel.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsOpenGLCameraModel.hpp
00003 
00004 Camera Model for OpenGL
00005 
00006 SUKITTI PUNAK   (05/13/2006)
00007 UPDATE          (12/14/2010)
00008 ******************************************************************************/
00009 #ifndef TAPs_OPENGL_CAMERA_MODEL_HPP
00010 #define TAPs_OPENGL_CAMERA_MODEL_HPP
00011 
00012 #include "TAPsOpenGLFns.hpp"
00013 
00014 BEGIN_NAMESPACE_TAPs__OpenGL
00015 //=============================================================================
00016 template <typename T>
00017 class OpenGLCameraModel {
00018 //-----------------------------------------------------------------------------
00019 public:
00020     static int GetNumberOfCameras ();
00021     //-------------------------------------------------------------------------
00022     // Constructor and Destructor
00023     OpenGLCameraModel (     // Orthographic or Perspective
00024         //Enum::CameraType  cameraType = Enum::ORTHOGRAPHIC
00025         Enum::CameraType    cameraType = Enum::PERSPECTIVE
00026     );
00027     OpenGLCameraModel ( 
00028             Enum::CameraType    cameraType, // Orthographic or Perspective
00029             T positionX, T positionY, T positionZ,          // position
00030             T centerX, T centerY, T centerZ,                // center
00031             T orientationX, T orientationY, T orientationZ, // orientation
00032             T tLeft,   T tRight,    // left & right projections
00033             T tBottom, T tTop,      // bottom & top projections
00034             T tNear,   T tFar       // near & far   projections
00035     );
00036     // For perspective camera only
00037     OpenGLCameraModel ( 
00038             Enum::CameraType    cameraType, // Orthographic or Perspective
00039             T positionX, T positionY, T positionZ,          // position
00040             T centerX, T centerY, T centerZ,                // center
00041             T orientationX, T orientationY, T orientationZ, // orientation
00042             T tFovy,    // angle of the field of view in the yz-plane [0,180]
00043             T tAspect,  // aspect ratio (width/height of the view port)
00044             T tNear,    // near clipping plane
00045             T tFar      // far  clipping plane
00046     );
00047     ~OpenGLCameraModel ();
00048     //---------------------------------------------------------------
00049     // Get/Set Function(s)
00050     inline void Set ();
00051     inline void SetViewVolume ();
00052     inline void Reset ()    { SetDefaultValues( cameraType ); Set(); }
00053 //  inline void Enable ();
00054 //  inline void Disable ();
00055 //  inline void Switch ( bool on );
00056 //  inline void ToggleSwitch ();
00057 //  inline bool IsOn () const;
00058 //  inline bool IsEnabled () const;
00059     //-------------------------------------------
00060     inline void SetCameraType ( Enum::CameraType cameraType );
00061     inline Enum::CameraType GetCameraType () const;
00062     //-------------------------------------------
00063     inline void SetPosition ( const Vector3<T> & p );
00064     inline void SetPosition ( T x, T y, T z );
00065     inline const Vector3<T> & GetPosition () const;
00066     //-------------------------------------------
00067     inline void SetCenter ( const Vector3<T> & p );
00068     inline void SetCenter ( T x, T y, T z );
00069     inline const Vector3<T> & GetCenter () const;
00070     //-------------------------------------------
00071     inline void SetOrientation ( const Vector3<T> & v );
00072     inline void SetOrientation ( T x, T y, T z );
00073     inline const Vector3<T> & GetOrientation () const;
00074     //-----------------------------------------------------
00075     // View Volume for Both Orthographic and Perspective
00076     inline void SetViewVolume ( 
00077             T tLeft,   T tRight, 
00078             T tBottom, T tTop, 
00079             T tNear,   T tFar );
00080     inline void SetViewVolumeLeftAndRight ( T tLeft, T tRight );
00081     inline void SetViewVolumeBottomAndTop ( T tBottom, T tTop );
00082     inline void SetViewVolumeNearAndFar ( T tNear, T tFar );
00083     //---------------------------------
00084     inline void GetViewVolume ( 
00085             T & tLeft,   T & tRight, 
00086             T & tBottom, T & tTop, 
00087             T & tNear,   T & tFar ) const;
00088     inline void GetViewVolumeLeftAndRight ( T & tLeft, T & tRight ) const;
00089     inline void GetViewVolumeBottomAndTop ( T & tBottom, T & tTop ) const;
00090     inline void GetViewVolumeNearAndFar ( T & tNear, T & tFar ) const;
00091     //-----------------------------------------------------
00092     // ViewVolume for Perspective Only
00093     inline void SetViewVolumePerspective ( 
00094         T tFovy, T tAspect, T tNear, T tFar );
00095     inline void GetViewVolumePerspective ( 
00096         T & tFovy, T & tAspect, T & tNear, T & tFar ) const;
00097     //-------------------------------------------
00098     inline void SetViewPort ( const Vector4<int> & v );
00099     inline void SetViewPort ( int x, int y, int width, int height );
00100     inline void SetViewPortLowerLeftCorner ( int x, int y );
00101     inline void SetViewPortWidthAndHeight ( int width, int height );
00102     //---------------------------------
00103     inline const Vector4<int> & GetViewPort () const;
00104     inline void GetViewPort ( int & x, int & y, int & width, int & height ) const;
00105     inline void GetViewPortLowerLeftCorner ( int & x, int & y ) const;
00106     inline void GetViewPortWidthAndHeight ( int & width, int & height ) const;
00107     //---------------------------------------------------------------
00108     // Operation(s)
00109     //---------------------------------------------------------------
00110     // Drawing(s)
00111     void Draw ();
00112 //-----------------------------------------------------------------------------
00113 private:
00114     //-------------------------------------------------------------------------
00115     void SetDefaultValues ( Enum::CameraType cameraType );
00116     void SetProjectionMatrix ();
00117     inline void SetOrthographicViewVolume ();
00118     inline void SetPerspectiveViewVolume ();
00119     //-------------------------------------------------------------------------
00120     // Data Member(s)
00121     //---------------------------------------------------------------
00122     // Projection Matrix
00123     //-------------------
00124     //         S[0]  S[1]  S[2]  0   // 0  4  8 12 
00125     // Proj =  U[0]  U[1]  U[2]  0   // 1  5  9 13
00126     //        -F[0] -F[1] -F[2]  0   // 2  6 10 14
00127     //          0     0     0    1   // 3  7 11 15
00128     // Where S = F x UP
00129     //       U = S x F
00130     //       F = (Center - Eye) / ||Center - Eye||
00131     //      UP = Orientation / ||Orientation||
00132     Matrix4x4<T>    m_M4x4ProjectionMatrix;
00133     Matrix4x4<T>    m_M4x4ModelViewMatrix;
00134     //---------------------------------------------------------------
00135     Enum::CameraType    m_eCameraType;  // Orthographic or Perspective
00136 //  bool            m_bOn;              // On/Off (enable/disable) camera
00137     Vector3<T>      m_v3Position;       // Camera Position  
00138                                         //   for Perspective (Default: (0,0,2))
00139                                         //   for Orthographic  (Default: (0,0,1))
00140     Vector3<T>      m_v3Center;         // Camera Center (Default: (0,0,0))
00141     Vector3<T>      m_v3Orientation;    // Camera Orientation (Default: (0,1,0))
00142     //===========================================
00143     // Camera View Volume
00144     //-------------------------------------------
00145     //   Dafault values for a PERSPECTIVE camera:
00146     //     left:   -0.25 right: 0.25
00147     //     bottom: -0.25 top:   0.25
00148     //     near:    1    far:   100
00149     //   Dafault values for an ORTHOGONAL camera:
00150     //     left:   -25   right: 25
00151     //     bottom: -25   top:   25
00152     //     near:    0    far:   100
00153     T   m_tLeft;
00154     T   m_tRight;
00155     T   m_tBottom;
00156     T   m_tTop;
00157     T   m_tNear;
00158     T   m_tFar;
00159     //T m_tFOVY;            // default is 40 degrees
00160     //---------------------------------------------------------------
00161     // View Port
00162     Vector4<int> m_v4iViewport;     // (x,y) lower left corner; width & height
00163     //---------------------------------------------------------------
00164     // Static Data Member(s)
00165     static GLuint   g_uiGLDisplayList;  // display list for camera models
00166     static int      g_iTotalCameras;    // Number of cameras created
00167     //-------------------------------------------------------------------------
00168 };  // END CLASS OpenGLCameraModel
00169 
00170 //=============================================================================
00171 END_NAMESPACE_TAPs__OpenGL
00172 //-----------------------------------------------------------------------------
00173 // Include definition if TAPs_USE_EXPORT is not defined
00174 //#if !defined( TAPs_USE_EXPORT )
00175     #include "TAPsOpenGLCameraModel.cpp"
00176 //#endif
00177 //-----------------------------------------------------------------------------
00178 #endif
00179 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00180 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines