Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00067
00068
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
00098 float cameraPointingX,cameraPointingY,cameraPointingZ;
00099 float cameraZoomDistance;
00100 float cameraElevationDeg,cameraAzimuthDeg;
00101 bool cameraIsProjective;
00102
00103
00104
00105 bool useCameraFromScene;
00106
00107
00108
00109 void setCameraPose(const mrpt::poses::CPose3D &camPose);
00110
00111
00112 float clearColorR,clearColorG,clearColorB;
00113
00114 static float SENSIBILITY_DEG_PER_PIXEL;
00115
00116
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
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
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
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
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
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
00199 void OnWindowCreation(wxWindowCreateEvent &ev);
00200
00201 DECLARE_EVENT_TABLE()
00202
00203 };
00204
00205 }
00206 }
00207
00208 #endif // wxUSE_GLCANVAS
00209 #endif // MRPT_HAS_WXWIDGETS
00210 #endif // CMyGLCanvas_H
00211