TAPs 0.7.7.3
TAPsWXOpenGLCanvas.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsWXOpenGLCanvas.hpp
00003 
00004 WXOpenGLCanvas is a subclass of wxGLCanvas for using wxWidgets Toolkit with 
00005 OpenGL support.
00006 
00007 SUKITTI PUNAK   (05/07/2006)
00008 UPDATE          (05/07/2006)
00009 ******************************************************************************/
00010 #ifndef TAPs_WX_OPENGL_CANVAS_HPP
00011 #define TAPs_WX_OPENGL_CANVAS_HPP
00012 
00013 // for all others, include the necessary headers (this file is usually all you
00014 // need because it includes almost all "standard" wxWidgets headers)
00015 //#ifndef WX_PRECOMP
00016 //    #include "wx/wx.h"
00017 //#endif
00018 #include <TAPs/wxWidgets/TAPsWXDebug.hpp>
00019 #include <GL/gl.h>
00020 #include <GL/glu.h>
00021 #include "wx/glcanvas.h"
00022 #include "OpenGL/TAPsBaseOpenGLManager.hpp"
00023 
00024 BEGIN_NAMESPACE_TAPs
00025 //=============================================================================
00026 // Class WXOpenGLCanvas : subclass of class wxGLCanvas
00027 //-----------------------------------------------------------------------------
00028 // Define a new frame type
00029 class WXOpenGLCanvas : public wxGLCanvas {
00030     friend class WXFrameSupportGLCanvas;
00031     //---------------------------------------------------------------
00032 public:
00033     WXOpenGLCanvas ( 
00034             wxWindow * parent, 
00035             wxWindowID id = wxID_ANY,
00036             const wxPoint & pos = wxDefaultPosition,
00037             const wxSize & size = wxDefaultSize,
00038             long style = 0, 
00039             const wxString & name = wxT( "WXOpenGLCanvas" )
00040     );
00041     //---------------------------------------------------------------
00042     WXOpenGLCanvas ( 
00043             wxWindow * parent, 
00044             const WXOpenGLCanvas *other, 
00045             wxWindowID id = wxID_ANY, 
00046             const wxPoint & pos = wxDefaultPosition,
00047             const wxSize & size = wxDefaultSize, 
00048             long style = 0, 
00049             const wxString & name = wxT( "WXOpenGLCanvas" ) 
00050     );
00051     //---------------------------------------------------------------
00052     virtual ~WXOpenGLCanvas ();
00053     //---------------------------------------------------------------
00054 protected:
00055     virtual void CreationAddOn ();
00056 public:
00057     //---------------------------------------------------------------
00058     virtual void Setup ( OpenGL::BaseOpenGLManager<Real> * pGLManager );
00059     //---------------------------------------------------------------
00060     // In EVT_TABLE( WXOpenGLCanvas, wxGLCanvas )
00061     //--------------------------------------
00062     void OnPaint            ( wxPaintEvent & event );   // Display
00063     void OnSize             ( wxSizeEvent & event );    // Reshape
00064     void OnEraseBackground  ( wxEraseEvent & event );   // Display
00065     void OnChar             ( wxKeyEvent & event );     // Keyboard
00066     void OnKeyDown          ( wxKeyEvent & event );     // Keyboard
00067     void OnKeyUp            ( wxKeyEvent & event );     // Keyboard
00068     void OnEnterWindow      ( wxMouseEvent & event );   // Mouse
00069     void OnMouse            ( wxMouseEvent & event );   // Mouse
00070     void OnIdle             ( wxIdleEvent & event );    // Idle
00071     //---------------------------------------------------------------
00072     // Not in EVT_TABLE( WXOpenGLCanvas, wxGLCanvas )
00073     //------------------------------------------
00074     // Popup Menu for Setting up Spline Model Property
00075     // Called inside OnMouse when the mouse right click is active
00076     void OnMouseRightClick  ( wxMouseEvent & event );
00077     //-------------------------------------
00078     // Use Dynamic Event Handlers
00079     //-------------------------------------
00080     // Response to a change/selection in popup menu #1
00081     void OnPopupMenu1 ( wxCommandEvent & event );
00082     //---------------------------------------------------------------
00083     void InitGL ();
00084     void Rotate ( GLfloat deg );
00085     static GLfloat CalcRotateSpeed  ( unsigned long accelTime );
00086     static GLfloat CalcRotateAngle  ( unsigned long lastTime, unsigned long accelTime );
00087     void Action ( long code, unsigned long lastTime, unsigned long accelTime );
00088     //---------------------------------------------------------------
00089     // Drawing Properties
00090     inline GLenum GetDrawStyle ()
00091         { return m_eDrawStyle; }
00092     inline void   SetDrawStyle ( GLenum drawStyle )
00093         { m_eDrawStyle = drawStyle; }
00094     //-------------------------------------------
00095     inline bool GetStatusShowCtrlPts ()
00096         { return m_bShowCtrlPts; }
00097     inline void SetStatusShowCtrlPts ( bool b )
00098         { m_bShowCtrlPts = b; }
00099     inline void ToggleStatusShowCtrlPts ()
00100         { m_bShowCtrlPts = !m_bShowCtrlPts; }
00101     //-------------------------------------------
00102     inline bool GetStatusDrawTexts ()
00103         { return m_bDrawTexts; }
00104     inline void SetStatusDrawTexts ( bool b )
00105         { m_bDrawTexts = b; }
00106     inline void ToggleStatusDrawTexts ()
00107         { m_bDrawTexts = !m_bDrawTexts; }
00108     //-------------------------------------------
00109     inline bool GetStatusUseFancyColor ()
00110         { return m_bUseFancyColor; }
00111     inline void SetStatusUseFancyColor ( bool b )
00112         { m_bUseFancyColor = b; }
00113     inline void ToggleStatusUseFancyColor  ()
00114         { m_bUseFancyColor = !m_bUseFancyColor; }
00115     //-------------------------------------------
00116     inline bool GetStatusDrawRefObject ()
00117         { return m_bDrawRefObject; }
00118     inline void SetStatusDrawRefObject ( bool b )
00119         { m_bDrawRefObject = b; }
00120     inline void ToggleStatusDrawRefObject ()
00121         { m_bDrawRefObject = !m_bDrawRefObject; }
00122     //-------------------------------------------
00123     inline bool GetStatusDrawPlatform ()
00124         { return m_bDrawPlatform; }
00125     inline void SetStatusDrawPlatform ( bool b )
00126         { m_bDrawPlatform = b; }
00127     inline void ToggleStatusDrawPlatform ()
00128         { m_bDrawPlatform = !m_bDrawPlatform; }
00129     //-------------------------------------------
00130     inline bool GetStatusDrawShadow ()
00131         { return m_bDrawShadow; }
00132     inline void SetStatusDrawShadow ( bool b )
00133         { m_bDrawShadow = b; }
00134     inline void ToggleStatusShadow ()
00135         { m_bDrawShadow = !m_bDrawShadow; }
00136     //-------------------------------------------
00137     inline bool GetStatusDrawLinesConnectedControlPts ()
00138         { return m_bDrawLinesConnectedControlPts; }
00139     inline void SetStatusDrawLinesConnectedControlPts ( bool b )
00140         { m_bDrawLinesConnectedControlPts = b; }
00141     inline void ToggleStatusDrawLinesConnectedControlPts ()
00142         { m_bDrawLinesConnectedControlPts = !m_bDrawLinesConnectedControlPts; }
00143     //---------------------------------------------------------------
00144     // View
00145     inline GLdouble * const RetModelMatrixPtr ()    { return m_adModelMatrix; }
00146     inline GLdouble * const RetProjMatrixPtr ()     { return m_adProjMatrix; }
00147     inline GLint    * const RetViewportPtr ()       { return m_aiViewport; }
00148     inline Real GetViewAngle ()             { return m_rViewAngle; }
00149     inline void SetViewAngle ( Real angle ) { m_rViewAngle = angle; }
00150     //---------------------------------------------------------------
00151     // Camera
00152     inline Real * const GetCameraPosition() { return m_arCameraPosition; }
00153     inline Real * const GetCameraLookAt()   { return m_arCameraLookAt; }
00154     inline Real * const GetCameraUpVector() { return m_arCameraUpVector; }
00155     inline void SetOpenGLLookAt () {
00156         gluLookAt( m_arCameraPosition[0], m_arCameraPosition[1], m_arCameraPosition[2], 
00157                    m_arCameraLookAt[0], m_arCameraLookAt[1], m_arCameraLookAt[2], 
00158                    m_arCameraUpVector[0], m_arCameraUpVector[1], m_arCameraUpVector[2] );
00159     }
00160     //---------------------------------------------------------------
00161     // Trackball
00162 //  inline Trackball_GL * const RetTrackballWorldPtr () { return m_pTrackballWorld; }
00163 //  inline Trackball_GL * const RetTrackballModelPtr () { return m_pTrackballModel; }
00164     //---------------------------------------------------------------
00165     // Menu
00166     inline wxMenu * const RetPopupMenu1 () { return m_menuPopup1; }
00167     void CreateMenuPopup1 ();
00168     void UpdateMenuPopup1 ();
00169     //---------------------------------------------------------------
00170 protected:
00171     //---------------------------------------------------------------
00172     // Data Members
00173     //---------------------------------------------------------------
00174     // Window Size
00175     GLint       m_iWidth;
00176     GLint       m_iHeight;
00177     //---------------------------------------------------------------
00178     // Mouse Position
00179     int         m_iMouseX;
00180     int         m_iMouseY;
00181     //---------------------------------------------------------------
00182     // For Debugging
00183     char        m_cstrDebug[256];
00184     //---------------------------------------------------------------
00185     // Drawing Properties
00186     GLenum      m_eDrawStyle;
00187     bool        m_bShowCtrlPts;
00188     bool        m_bDrawTexts;
00189     bool        m_bUseFancyColor;
00190     bool        m_bDrawRefObject;
00191     bool        m_bDrawPlatform;
00192     bool        m_bDrawShadow;
00193     bool        m_bDrawLinesConnectedControlPts;
00194     //---------------------------------------------------------------
00195     // View
00196     GLdouble    m_adModelMatrix[16];
00197     GLdouble    m_adProjMatrix[16];
00198     GLint       m_aiViewport[4];
00199     Real        m_rViewAngle;       // For perspective view
00200     Real        m_rOrthoAdjuster;   // For orthogonal view
00201     //---------------------------------------------------------------
00202     // Camera
00203     Real        m_arCameraPosition[3];
00204     Real        m_arCameraLookAt[3];
00205     Real        m_arCameraUpVector[3];
00206     //---------------------------------------------------------------
00207     // Trackball
00208 //  Trackball_GL * m_pTrackballWorld;
00209 //  Trackball_GL * m_pTrackballModel;
00210     //---------------------------------------------------------------
00211     GLuint      m_uiGLList;
00212     long        m_lRotateLeft;
00213     long        m_lRotateRight;
00214     //---------------------------------------------------------------
00215     static unsigned long    m_sulSecBase;
00216     static int              m_siTimeInitialized;
00217     static unsigned long    m_sulXSynct;
00218     static unsigned long    m_sulGSynct;
00219     //---------------------------------------------------------------
00220     long            m_lKey;
00221     unsigned long   m_ulStartTime;
00222     unsigned long   m_ulLastTime;
00223     unsigned long   m_ulLastRedraw;
00224     //---------------------------------------------------------------
00225     // Popup Menu(s)
00226     wxMenu  * m_menuPopup1;
00227     //---------------------------------------------------------------
00228     // OpenGL Manager
00229     OpenGL::BaseOpenGLManager<Real> *   m_pGLManager;
00230     //---------------------------------------------------------------
00231     DECLARE_EVENT_TABLE()
00232 };  // End Class WXOpenGLCanvas ************************************************
00233 //-----------------------------------------------------------------------------
00234 //=============================================================================
00235 END_NAMESPACE_TAPs
00236 //-----------------------------------------------------------------------------
00237 // Include definition if TAPs_USE_EXPORT is not defined
00238 #if !defined( TAPs_USE_EXPORT )
00239     #include "TAPsWXOpenGLCanvas.cpp"
00240 #endif
00241 //-----------------------------------------------------------------------------
00242 #endif
00243 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00244 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines