Main MRPT website > C++ reference for MRPT 1.9.9
CGlCanvasBase.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
12 
13 namespace mrpt
14 {
15 namespace opengl
16 {
17 class CCamera;
18 }
19 }
20 
21 namespace mrpt
22 {
23 namespace gui
24 {
25 /** This base class implements a working with opengl::Camera and a OpenGL
26  * canvas, and it's used in gui::CWxGLCanvasBase and gui::CQtGlCanvasBase.
27 */
29 {
30  public:
31  struct CamaraParams
32  {
34  void setElevationDeg(float deg);
35 
36  float cameraPointingX = .0f, cameraPointingY = .0f,
38  float cameraZoomDistance = 40.f;
39  float cameraElevationDeg = 45.f, cameraAzimuthDeg = 45.f;
40  bool cameraIsProjective = true;
41  float cameraFOV = 30.f;
42  };
43 
45  virtual ~CGlCanvasBase() {}
46  /** Sets the minimum of the zoom
47  * See also setMaximumZoom(float) */
48  void setMinimumZoom(float zoom);
49 
50  /** Sets the maximum of the zoom
51  * See also setMinimumZoom(float) */
52  void setMaximumZoom(float zoom);
53 
54  /** Saves the click position of the mouse
55  * See also setMouseClicked(bool) */
56  void setMousePos(int x, int y);
57 
58  /** Sets the property mouseClicked
59  * By default, this property is false.
60  * See also setMousePos(int, int) */
61  void setMouseClicked(bool is);
62 
63  /** Sets the last mouse position */
64  void updateLastPos(int x, int y);
65  /** Calls the glViewport function*/
66  void resizeViewport(int w, int h);
67  /** Calls the glClearColor function
68  * See also setClearColors(float, float, float, float)*/
69  void clearColors();
70 
71  /** This function for the mouse event
72  * It gets a reference to CamaraParams, x, y
73  * and updates the zoom of the CameraParams.
74  * See also updateZoom(CamaraParams &, float)*/
75  void updateZoom(CamaraParams& params, int x, int y) const;
76  /** This function for the wheel event
77  * It gets a reference to CamaraParams, delta
78  * and updates the zoom of the CameraParams.
79  * See also updateZoom(CamaraParams &, int, int)*/
80  void updateZoom(CamaraParams& params, float delta) const;
81  /** This function for the mouse event
82  * It gets a reference to CamaraParams, x, y
83  * and updates the elevation and azimuth.
84  * See also getElevationDegrees(), getAzimuthDegrees()*/
85  void updateRotate(CamaraParams& params, int x, int y) const;
86  /** This function for the mouse event
87  * It gets a reference to CamaraParams, x, y
88  * and updates the elevation and azimuth.
89  * See also getElevationDegrees(), getAzimuthDegrees()*/
90  void updateOrbitCamera(CamaraParams& params, int x, int y) const;
91  /** This function for the mouse event
92  * It gets a reference to CamaraParams, x, y
93  * and updates the pointing of the camera.
94  * See also getCameraPointingX(), getCameraPointingY(),
95  * getCameraPointingZ()*/
96  void updatePan(CamaraParams& params, int x, int y) const;
97 
98  /** Returns a copy of CamaraParams
99  * See also getRefCameraParams(), setCameraParams(const CamaraParams &)*/
100  CamaraParams cameraParams() const;
101  /** Returns a reference to CamaraParams
102  * See also cameraParams(), setCameraParams(const CamaraParams &) */
103  const CamaraParams& getRefCameraParams() const;
104  /** Sets the CamaraParams
105  * See also cameraParams(), getRefCameraParams()*/
106  virtual void setCameraParams(const CamaraParams& params);
107 
108  /** This function gets a reference to mrpt::opengl::CCamera and
109  * updates the camera parameters(pointing, zoom, azimuth, elevation,
110  * IsProjective, FOV)
111  */
113 
114  /** If set to true (default=false), the cameraPointingX,... parameters are
115  * ignored and the camera stored in the 3D scene is used instead.
116  * See also void bool getUseCameraFromScene()
117  */
118  void setUseCameraFromScene(bool is);
119 
120  /** See also void setUseCameraFromScene(bool)
121  */
122  bool getUseCameraFromScene() const;
123 
124  // Visualization params:
125  /** Saves the pointing of the camera
126  * See also getCameraPointingX(), getCameraPointingY(), getCameraPointingZ()
127  */
128  virtual void setCameraPointing(float pointX, float pointY, float pointZ);
129 
130  /** Returns the x pointing of the camera
131  * See also setCameraPointing(float, float, float)
132  */
133  float getCameraPointingX() const;
134 
135  /** Returns the y pointing of the camera
136  * See also setCameraPointing(float, float, float)
137  */
138  float getCameraPointingY() const;
139 
140  /** Returns the z pointing of the camera
141  * See also setCameraPointing(float, float, float)
142  */
143  float getCameraPointingZ() const;
144 
145  /** Saves camera zooming
146  * See also getZoomDistance()
147  */
148  virtual void setZoomDistance(float zoom);
149 
150  /** Returns a zoom
151  * See also setZoomDistance(float)
152  */
153  float getZoomDistance() const;
154 
155  /** Saves the degrees of the azimuth camera
156  * See also getAzimuthDegrees()
157  */
158  virtual void setAzimuthDegrees(float ang);
159 
160  /** Returns a azimuth degrees
161  * See also setAzimuthDegrees(float)
162  */
163  float getAzimuthDegrees() const;
164 
165  /** Saves the degrees of the elevation camera
166  * See also getElevationDegrees()
167  */
168  virtual void setElevationDegrees(float ang);
169 
170  /** Returns a elevation degrees
171  * See also setElevationDegrees(float)
172  */
173  float getElevationDegrees() const;
174 
175  virtual void setCameraProjective(bool is);
176  bool isCameraProjective() const;
177 
178  virtual void setCameraFOV(float FOV);
179  float cameraFOV() const;
180 
181  /** Sets the RGBA colors for glClearColor
182  * See also clearColors(), getClearColorR(),
183  * getClearColorG(),getClearColorB(), getClearColorA()
184  */
185  void setClearColors(float r, float g, float b, float a = 1.0f);
186  float getClearColorR() const;
187  float getClearColorG() const;
188  float getClearColorB() const;
189  float getClearColorA() const;
190 
191  static float SENSIBILITY_DEG_PER_PIXEL; // Default = 0.1
192 
193  /** Overload this method to limit the capabilities of the user to move the
194  * camera using the mouse.
195  * For all these variables:
196  * - cameraPointingX
197  * - cameraPointingY
198  * - cameraPointingZ
199  * - cameraZoomDistance
200  * - cameraElevationDeg
201  * - cameraAzimuthDeg
202  *
203  * A "new_NAME" variable will be passed with the temptative new
204  * value after the user action.
205  * The default behavior should be to copy all the new variables
206  * to the variables listed above
207  * but in the middle any find of user-defined filter can be
208  * implemented.
209  */
211  float new_cameraPointingX, float new_cameraPointingY,
212  float new_cameraPointingZ, float new_cameraZoomDistance,
213  float new_cameraElevationDeg, float new_cameraAzimuthDeg)
214  {
215  m_cameraParams.cameraPointingX = new_cameraPointingX;
216  m_cameraParams.cameraPointingY = new_cameraPointingY;
217  m_cameraParams.cameraPointingZ = new_cameraPointingZ;
218  m_cameraParams.cameraZoomDistance = new_cameraZoomDistance;
219  m_cameraParams.cameraElevationDeg = new_cameraElevationDeg;
220  m_cameraParams.cameraAzimuthDeg = new_cameraAzimuthDeg;
221  }
222 
223  inline void getLastMousePosition(int& x, int& y) const
224  {
225  x = m_mouseLastX;
226  y = m_mouseLastY;
227  }
228 
229  /** At constructor an empty scene is created. The object is freed at GL
230  canvas destructor.
231  * This function returns a smart pointer to the opengl scene
232  getOpenGLSceneRef */
234  {
235  return m_openGLScene;
236  }
238 
239  protected:
240  virtual void swapBuffers() = 0;
241  virtual void preRender() = 0;
242  virtual void postRender() = 0;
243  virtual void renderError(const std::string& err_msg) = 0;
244 
245  virtual double renderCanvas(int width = -1, int height = -1);
246 
247  private:
248  float clearColorR = .4f, clearColorG = .4f, clearColorB = .4f,
249  clearColorA = 1.f;
250  bool useCameraFromScene = false;
252  mrpt::make_aligned_shared<mrpt::opengl::COpenGLScene>();
255  bool mouseClicked = false;
256  float m_minZoom = 1.f;
257  float m_maxZoom = 3200.f;
259 }; // end of class
260 } // end namespace
261 } // end namespace
bool isCameraProjective() const
virtual void preRender()=0
float getZoomDistance() const
Returns a zoom See also setZoomDistance(float)
void setClearColors(float r, float g, float b, float a=1.0f)
Sets the RGBA colors for glClearColor See also clearColors(), getClearColorR(), getClearColorG(),getClearColorB(), getClearColorA()
float getClearColorB() const
void setMaximumZoom(float zoom)
Sets the maximum of the zoom See also setMinimumZoom(float)
void setMinimumZoom(float zoom)
Sets the minimum of the zoom See also setMaximumZoom(float)
virtual void postRender()=0
mrpt::opengl::COpenGLScene::Ptr m_openGLScene
void setUseCameraFromScene(bool is)
If set to true (default=false), the cameraPointingX,...
virtual void setCameraParams(const CamaraParams &params)
Sets the CamaraParams See also cameraParams(), getRefCameraParams()
void setOpenGLSceneRef(mrpt::opengl::COpenGLScene::Ptr scene)
virtual void swapBuffers()=0
GLenum GLsizei width
Definition: glext.h:3531
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
bool getUseCameraFromScene() const
See also void setUseCameraFromScene(bool)
virtual void setCameraFOV(float FOV)
virtual void OnUserManuallyMovesCamera(float new_cameraPointingX, float new_cameraPointingY, float new_cameraPointingZ, float new_cameraZoomDistance, float new_cameraElevationDeg, float new_cameraAzimuthDeg)
Overload this method to limit the capabilities of the user to move the camera using the mouse...
virtual void setCameraProjective(bool is)
float getElevationDegrees() const
Returns a elevation degrees See also setElevationDegrees(float)
mrpt::opengl::CCamera & updateCameraParams(mrpt::opengl::CCamera &cam) const
This function gets a reference to mrpt::opengl::CCamera and updates the camera parameters(pointing, zoom, azimuth, elevation, IsProjective, FOV)
virtual double renderCanvas(int width=-1, int height=-1)
float getCameraPointingY() const
Returns the y pointing of the camera See also setCameraPointing(float, float, float) ...
void updatePan(CamaraParams &params, int x, int y) const
This function for the mouse event It gets a reference to CamaraParams, x, y and updates the pointing ...
float getClearColorA() const
GLubyte g
Definition: glext.h:6279
GLubyte GLubyte b
Definition: glext.h:6279
virtual void setElevationDegrees(float ang)
Saves the degrees of the elevation camera See also getElevationDegrees()
void getLastMousePosition(int &x, int &y) const
GLsizei const GLchar ** string
Definition: glext.h:4101
void updateLastPos(int x, int y)
Sets the last mouse position.
void updateZoom(CamaraParams &params, int x, int y) const
This function for the mouse event It gets a reference to CamaraParams, x, y and updates the zoom of t...
void resizeViewport(int w, int h)
Calls the glViewport function.
float getClearColorR() const
virtual void setAzimuthDegrees(float ang)
Saves the degrees of the azimuth camera See also getAzimuthDegrees()
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::opengl::COpenGLScene::Ptr & getOpenGLSceneRef()
At constructor an empty scene is created.
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
float getCameraPointingZ() const
Returns the z pointing of the camera See also setCameraPointing(float, float, float) ...
virtual void setZoomDistance(float zoom)
Saves camera zooming See also getZoomDistance()
std::shared_ptr< COpenGLScene > Ptr
Definition: COpenGLScene.h:62
void clearColors()
Calls the glClearColor function See also setClearColors(float, float, float, float) ...
const CamaraParams & getRefCameraParams() const
Returns a reference to CamaraParams See also cameraParams(), setCameraParams(const CamaraParams &) ...
virtual void renderError(const std::string &err_msg)=0
GLenum GLint GLint y
Definition: glext.h:3538
float getCameraPointingX() const
Returns the x pointing of the camera See also setCameraPointing(float, float, float) ...
void updateRotate(CamaraParams &params, int x, int y) const
This function for the mouse event It gets a reference to CamaraParams, x, y and updates the elevation...
CamaraParams cameraParams() const
Returns a copy of CamaraParams See also getRefCameraParams(), setCameraParams(const CamaraParams &) ...
GLenum GLint x
Definition: glext.h:3538
This base class implements a working with opengl::Camera and a OpenGL canvas, and it&#39;s used in gui::C...
Definition: CGlCanvasBase.h:28
A camera: if added to a scene, the viewpoint defined by this camera will be used instead of the camer...
Definition: CCamera.h:30
GLenum GLsizei GLsizei height
Definition: glext.h:3554
static float SENSIBILITY_DEG_PER_PIXEL
void setMouseClicked(bool is)
Sets the property mouseClicked By default, this property is false.
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
GLenum const GLfloat * params
Definition: glext.h:3534
float getClearColorG() const
void updateOrbitCamera(CamaraParams &params, int x, int y) const
This function for the mouse event It gets a reference to CamaraParams, x, y and updates the elevation...
float getAzimuthDegrees() const
Returns a azimuth degrees See also setAzimuthDegrees(float)
virtual void setCameraPointing(float pointX, float pointY, float pointZ)
Saves the pointing of the camera See also getCameraPointingX(), getCameraPointingY(), getCameraPointingZ()
void setMousePos(int x, int y)
Saves the click position of the mouse See also setMouseClicked(bool)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019