Main MRPT website > C++ reference
MRPT logo
CMyGLCanvasBase.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 
00029 #ifndef CMyGLCanvas_H
00030 #define CMyGLCanvas_H
00031 
00032 #include <mrpt/opengl.h>
00033 #include <mrpt/opengl/opengl_fonts.h>
00034 
00035 #include <mrpt/gui/link_pragmas.h>
00036 
00037 #if MRPT_HAS_WXWIDGETS
00038 
00039 #include <wx/string.h>
00040 #include <wx/intl.h>
00041 #include <wx/bitmap.h>
00042 #include <wx/icon.h>
00043 #include <wx/image.h>
00044 #include <wx/artprov.h>
00045 
00046 #include <wx/msgdlg.h>
00047 #include <wx/filedlg.h>
00048 #include <wx/progdlg.h>
00049 #include <wx/imaglist.h>
00050 #include <wx/busyinfo.h>
00051 #include <wx/log.h>
00052 #include <wx/textdlg.h>
00053 #include <wx/dirdlg.h>
00054 #include <wx/colordlg.h>
00055 #include <wx/dcmemory.h>
00056 
00057 #if wxUSE_GLCANVAS && MRPT_HAS_OPENGL_GLUT
00058 
00059 #include <wx/glcanvas.h>
00060 #include <wx/dcclient.h>
00061 
00062 namespace mrpt
00063 {
00064         namespace gui
00065         {
00066                 /** This class implements a OpenGL canvas, and it's used in gui::CDisplayWindow3D and a number of standalone applications in the MRPT project.
00067                   *  There is a filter to control the user capability of moving the camera with the mouse. See OnUserManuallyMovesCamera
00068                   * \ingroup mrpt_gui_grp
00069                   */
00070                 class GUI_IMPEXP CMyGLCanvasBase: public wxGLCanvas
00071                 {
00072                 public:
00073                         CMyGLCanvasBase( wxWindow *parent, wxWindowID id = wxID_ANY,
00074                                                  const wxPoint& pos = wxDefaultPosition,
00075                                                  const wxSize& size = wxDefaultSize,
00076                                                  long style = 0, const wxString& name = _T("CMyGLCanvasBase") );
00077 
00078                         virtual ~CMyGLCanvasBase();
00079 
00080                         void OnPaint(wxPaintEvent& event);
00081                         void OnSize(wxSizeEvent& event);
00082                         void OnEraseBackground(wxEraseEvent& event);
00083                         void OnEnterWindow(wxMouseEvent& event);
00084 
00085                         void OnChar(wxKeyEvent& event);
00086 
00087                         void OnLeftDown(wxMouseEvent& event);
00088                         void OnMouseMove(wxMouseEvent& event);
00089                         void OnRightDown(wxMouseEvent& event);
00090                         void OnRightUp(wxMouseEvent& event);
00091                         void OnLeftUp(wxMouseEvent& event);
00092                         void OnMouseWheel(wxMouseEvent& event);
00093 
00094                         void Render();
00095                         void InitGL();
00096 
00097                         // Visualization params:
00098                         float   cameraPointingX,cameraPointingY,cameraPointingZ;
00099                         float   cameraZoomDistance;
00100                         float   cameraElevationDeg,cameraAzimuthDeg;
00101                         bool    cameraIsProjective;
00102 
00103                         /** If set to true (default=false), the cameraPointingX,... parameters are ignored and the camera stored in the 3D scene is used instead.
00104                           */
00105                         bool    useCameraFromScene;
00106 
00107                         /** Set the camera from a CPose3D, which defines the +X,+Y axis as image place RIGHT and UP dirctions, and -Z as towards the pointing direction.
00108                           */
00109                         void setCameraPose(const mrpt::poses::CPose3D &camPose);
00110 
00111 
00112                         float   clearColorR,clearColorG,clearColorB;
00113 
00114                         static float  SENSIBILITY_DEG_PER_PIXEL;                // Default = 0.1
00115 
00116                         /**  Methods that can be implemented in custom derived classes  */
00117                         virtual void OnCharCustom( wxKeyEvent& event ) { }
00118 
00119                         virtual void OnPreRender() { }
00120                         virtual void OnPostRender()  { }
00121                         virtual void OnPostRenderSwapBuffers(double At, wxPaintDC &dc) { }
00122                         virtual void OnRenderError( const wxString &str ) { }
00123 
00124                         /** Overload this method to limit the capabilities of the user to move the camera using the mouse.
00125                           *  For all these variables:
00126                           *  - cameraPointingX
00127                           *  - cameraPointingY
00128                           *  - cameraPointingZ
00129                           *  - cameraZoomDistance
00130                           *  - cameraElevationDeg
00131                           *  - cameraAzimuthDeg
00132                           *
00133                           *  A "new_NAME" variable will be passed with the temptative new value after the user action.
00134                           *   The default behavior should be to copy all the new variables to the variables listed above
00135                           *   but in the middle any find of user-defined filter can be implemented.
00136                           */
00137                         virtual void OnUserManuallyMovesCamera(
00138                                 float   new_cameraPointingX,
00139                                 float   new_cameraPointingY,
00140                                 float   new_cameraPointingZ,
00141                                 float   new_cameraZoomDistance,
00142                                 float   new_cameraElevationDeg,
00143                                 float   new_cameraAzimuthDeg )
00144                         {
00145                                 cameraPointingX         = new_cameraPointingX;
00146                                 cameraPointingY         = new_cameraPointingY;
00147                                 cameraPointingZ         = new_cameraPointingZ;
00148                                 cameraZoomDistance      = new_cameraZoomDistance;
00149                                 cameraElevationDeg      = new_cameraElevationDeg ;
00150                                 cameraAzimuthDeg        = new_cameraAzimuthDeg;
00151                         }
00152 
00153                         inline void getLastMousePosition(int &x,int& y) const {
00154                                 x =m_mouseLastX;
00155                                 y =m_mouseLastY;
00156                         }
00157 
00158                         /**  At constructor an empty scene is created. The object is freed at GL canvas destructor.
00159                           */
00160                         opengl::COpenGLScenePtr         m_openGLScene;
00161 
00162                 protected:
00163                         wxGLContext *m_gl_context;
00164                         bool   m_init;
00165 
00166                         int     m_mouseLastX,m_mouseLastY;
00167 
00168                         int     mouseClickX,mouseClickY;
00169                         bool    mouseClicked;
00170 
00171                         long           m_Key;
00172                         unsigned long  m_StartTime;
00173                         unsigned long  m_LastTime;
00174                         unsigned long  m_LastRedraw;
00175 
00176                         /** DEPRECATED: Use CRenderizable static method instead */
00177                         static void renderTextBitmap(
00178                                 int screen_x,
00179                                 int screen_y,
00180                                 const std::string &str,
00181                                 float  color_r=1,
00182                                 float  color_g=1,
00183                                 float  color_b=1,
00184                                 mrpt::opengl::TOpenGLFont    font = mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_24
00185                                 )
00186                         {
00187                                 mrpt::opengl::CRenderizable::renderTextBitmap(screen_x,screen_y,str,color_r,color_g,color_b, font);
00188                         }
00189 
00190                         /** DEPRECATED: Use CRenderizable static method instead */
00191                         static int textBitmapWidth(
00192                                 const std::string &str,
00193                                 mrpt::opengl::TOpenGLFont    font = mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_24 )
00194                         {
00195                                 return mrpt::opengl::CRenderizable::textBitmapWidth(str,font);
00196                         }
00197 
00198                         // Used to create the gl context at startup.
00199                         void OnWindowCreation(wxWindowCreateEvent &ev);
00200 
00201                         DECLARE_EVENT_TABLE()
00202 
00203                 };  // end of class
00204 
00205         }       // end namespace
00206 }       // end namespace
00207 
00208 #endif          // wxUSE_GLCANVAS
00209 #endif          // MRPT_HAS_WXWIDGETS
00210 #endif          // CMyGLCanvas_H
00211 



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011