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 class GUI_IMPEXP CMyGLCanvasBase: public wxGLCanvas
00070 {
00071 public:
00072 CMyGLCanvasBase( wxWindow *parent, wxWindowID id = wxID_ANY,
00073 const wxPoint& pos = wxDefaultPosition,
00074 const wxSize& size = wxDefaultSize,
00075 long style = 0, const wxString& name = _T("CMyGLCanvasBase") );
00076
00077 virtual ~CMyGLCanvasBase();
00078
00079 void OnPaint(wxPaintEvent& event);
00080 void OnSize(wxSizeEvent& event);
00081 void OnEraseBackground(wxEraseEvent& event);
00082 void OnEnterWindow(wxMouseEvent& event);
00083
00084 void OnChar(wxKeyEvent& event);
00085
00086 void OnLeftDown(wxMouseEvent& event);
00087 void OnMouseMove(wxMouseEvent& event);
00088 void OnRightDown(wxMouseEvent& event);
00089 void OnRightUp(wxMouseEvent& event);
00090 void OnLeftUp(wxMouseEvent& event);
00091 void OnMouseWheel(wxMouseEvent& event);
00092
00093 void Render();
00094 void InitGL();
00095
00096
00097 float cameraPointingX,cameraPointingY,cameraPointingZ;
00098 float cameraZoomDistance;
00099 float cameraElevationDeg,cameraAzimuthDeg;
00100 bool cameraIsProjective;
00101
00102
00103
00104 bool useCameraFromScene;
00105
00106
00107
00108 void setCameraPose(const mrpt::poses::CPose3D &camPose);
00109
00110
00111 float clearColorR,clearColorG,clearColorB;
00112
00113 static float SENSIBILITY_DEG_PER_PIXEL;
00114
00115
00116 virtual void OnCharCustom( wxKeyEvent& event ) { }
00117
00118 virtual void OnPreRender() { }
00119 virtual void OnPostRender() { }
00120 virtual void OnPostRenderSwapBuffers(double At, wxPaintDC &dc) { }
00121 virtual void OnRenderError( const wxString &str ) { }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 virtual void OnUserManuallyMovesCamera(
00137 float new_cameraPointingX,
00138 float new_cameraPointingY,
00139 float new_cameraPointingZ,
00140 float new_cameraZoomDistance,
00141 float new_cameraElevationDeg,
00142 float new_cameraAzimuthDeg )
00143 {
00144 cameraPointingX = new_cameraPointingX;
00145 cameraPointingY = new_cameraPointingY;
00146 cameraPointingZ = new_cameraPointingZ;
00147 cameraZoomDistance = new_cameraZoomDistance;
00148 cameraElevationDeg = new_cameraElevationDeg ;
00149 cameraAzimuthDeg = new_cameraAzimuthDeg;
00150 }
00151
00152 inline void getLastMousePosition(int &x,int& y) const {
00153 x =m_mouseLastX;
00154 y =m_mouseLastY;
00155 }
00156
00157
00158
00159 opengl::COpenGLScenePtr m_openGLScene;
00160
00161 protected:
00162 wxGLContext *m_gl_context;
00163 bool m_init;
00164
00165 int m_mouseLastX,m_mouseLastY;
00166
00167 int mouseClickX,mouseClickY;
00168 bool mouseClicked;
00169
00170 long m_Key;
00171 unsigned long m_StartTime;
00172 unsigned long m_LastTime;
00173 unsigned long m_LastRedraw;
00174
00175
00176
00177
00178
00179
00180 void renderTextBitmap(
00181 int screen_x,
00182 int screen_y,
00183 const std::string &str,
00184 float color_r=1,
00185 float color_g=1,
00186 float color_b=1,
00187 mrpt::opengl::TOpenGLFont font = mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_24
00188 );
00189
00190
00191
00192
00193 int textBitmapWidth(
00194 const std::string &str,
00195 mrpt::opengl::TOpenGLFont font = mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_24 );
00196
00197
00198 void OnWindowCreation(wxWindowCreateEvent &ev);
00199
00200 DECLARE_EVENT_TABLE()
00201
00202 };
00203
00204 }
00205 }
00206
00207 #endif // wxUSE_GLCANVAS
00208 #endif // MRPT_HAS_WXWIDGETS
00209 #endif // CMyGLCanvas_H
00210