14 #if MRPT_HAS_OPENGL_GLUT
21 #include <OpenGL/gl.h>
22 #include <OpenGL/glu.h>
23 #include <GLUT/glut.h>
28 #ifdef HAVE_FREEGLUT_EXT_H
29 #include <GL/freeglut_ext.h>
53 float zoom =
params.cameraZoomDistance * exp(0.01 * (
y - m_mouseClickY));
54 if (zoom <= m_minZoom || (m_maxZoom != -1.0f && m_maxZoom <= zoom))
return;
55 params.cameraZoomDistance = zoom;
56 if (
params.cameraZoomDistance < 0.01)
params.cameraZoomDistance = 0.01f;
58 float Az = -0.05 * (
x - m_mouseClickX);
59 float D = 0.001 *
params.cameraZoomDistance;
60 params.cameraPointingZ += D * Az;
65 float zoom =
params.cameraZoomDistance * (1 - 0.03f * (delta / 120.0f));
66 if (zoom <= m_minZoom || (m_maxZoom != -1.0f && m_maxZoom <= zoom))
return;
68 params.cameraZoomDistance = zoom;
73 const float dis = max(0.01f, (
params.cameraZoomDistance));
74 float eye_x =
params.cameraPointingX +
77 float eye_y =
params.cameraPointingY +
84 float A_AzimuthDeg = -SENSIBILITY_DEG_PER_PIXEL * (
x - m_mouseClickX);
85 params.cameraAzimuthDeg += A_AzimuthDeg;
87 float A_ElevationDeg = SENSIBILITY_DEG_PER_PIXEL * (
y - m_mouseClickY);
88 params.setElevationDeg(
params.cameraElevationDeg + A_ElevationDeg);
91 params.cameraPointingX = eye_x -
94 params.cameraPointingY = eye_y -
103 params.cameraAzimuthDeg -= 0.2 * (
x - m_mouseClickX);
105 params.cameraElevationDeg + 0.2 * (
y - m_mouseClickY));
116 #if MRPT_HAS_OPENGL_GLUT
117 if (
w == -1 || h == -1)
return;
125 #if MRPT_HAS_OPENGL_GLUT
126 glClearColor(clearColorR, clearColorG, clearColorB, clearColorA);
132 float Ay = -(
x - m_mouseClickX);
133 float Ax = -(
y - m_mouseClickY);
134 float D = 0.001 *
params.cameraZoomDistance;
143 return m_cameraParams;
148 return m_cameraParams;
158 return m_cameraParams.cameraZoomDistance;
163 m_cameraParams.cameraZoomDistance = zoom;
169 m_cameraParams.cameraPointingX, m_cameraParams.cameraPointingY,
170 m_cameraParams.cameraPointingZ);
184 m_cameraParams.cameraAzimuthDeg = ang;
189 m_cameraParams.cameraElevationDeg = ang;
194 return m_cameraParams.cameraAzimuthDeg;
199 return m_cameraParams.cameraElevationDeg;
204 m_cameraParams.cameraIsProjective = is;
209 return m_cameraParams.cameraIsProjective;
228 m_openGLScene = scene;
233 m_cameraParams.cameraPointingX = pointX;
234 m_cameraParams.cameraPointingY = pointY;
235 m_cameraParams.cameraPointingZ = pointZ;
240 return m_cameraParams.cameraPointingX;
245 return m_cameraParams.cameraPointingY;
250 return m_cameraParams.cameraPointingZ;
255 #if MRPT_HAS_OPENGL_GLUT
281 if (!useCameraFromScene)
287 "Fatal error: there is no 'main' viewport in the 3D "
292 updateCameraParams(cam);
304 m_openGLScene->render();
318 catch (std::exception& e)
322 std::string(
"[CWxGLCanvasBase::Render] Exception!: ") +
324 std::cerr << err_msg;
325 renderError(err_msg);
330 std::cerr <<
"Runtime error!" << std::endl;
341 cameraElevationDeg = deg;
343 if (cameraElevationDeg < -90.0f)
344 cameraElevationDeg = -90.0f;
345 else if (cameraElevationDeg > 90.0f)
346 cameraElevationDeg = 90.0f;
const CamaraParams & getRefCameraParams() const
Returns a reference to CamaraParams See also cameraParams(), setCameraParams(const CamaraParams &)
void setUseCameraFromScene(bool is)
If set to true (default=false), the cameraPointingX,...
void clearColors()
Calls the glClearColor function See also setClearColors(float, float, float, float)
float getZoomDistance() const
Returns a zoom See also setZoomDistance(float)
void updateOrbitCamera(CamaraParams ¶ms, int x, int y) const
This function for the mouse event It gets a reference to CamaraParams, x, y and updates the elevation...
void setClearColors(float r, float g, float b, float a=1.0f)
Sets the RGBA colors for glClearColor See also clearColors(), getClearColorR(), getClearColorG(),...
void updateRotate(CamaraParams ¶ms, int x, int y) const
This function for the mouse event It gets a reference to CamaraParams, x, y and updates the elevation...
virtual void setCameraFOV(float FOV)
virtual void setZoomDistance(float zoom)
Saves camera zooming See also getZoomDistance()
virtual void setElevationDegrees(float ang)
Saves the degrees of the elevation camera See also getElevationDegrees()
void updatePan(CamaraParams ¶ms, int x, int y) const
This function for the mouse event It gets a reference to CamaraParams, x, y and updates the pointing ...
void setMousePos(int x, int y)
Saves the click position of the mouse See also setMouseClicked(bool)
void updateZoom(CamaraParams ¶ms, 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 setMinimumZoom(float zoom)
Sets the minimum of the zoom See also setMaximumZoom(float)
void setMouseClicked(bool is)
Sets the property mouseClicked By default, this property is false.
void updateLastPos(int x, int y)
Sets the last mouse position.
void setMaximumZoom(float zoom)
Sets the maximum of the zoom See also setMinimumZoom(float)
virtual void setCameraProjective(bool is)
bool isCameraProjective() const
float getClearColorA() const
float getClearColorR() const
float getCameraPointingX() const
Returns the x pointing of the camera See also setCameraPointing(float, float, float)
float getClearColorB() const
CamaraParams cameraParams() const
Returns a copy of CamaraParams See also getRefCameraParams(), setCameraParams(const CamaraParams &)
virtual void setAzimuthDegrees(float ang)
Saves the degrees of the azimuth camera See also getAzimuthDegrees()
float getElevationDegrees() const
Returns a elevation degrees See also setElevationDegrees(float)
float getCameraPointingZ() const
Returns the z pointing of the camera See also setCameraPointing(float, float, float)
virtual double renderCanvas(int width=-1, int height=-1)
float getClearColorG() const
virtual void setCameraPointing(float pointX, float pointY, float pointZ)
Saves the pointing of the camera See also getCameraPointingX(), getCameraPointingY(),...
bool getUseCameraFromScene() const
See also void setUseCameraFromScene(bool)
static float SENSIBILITY_DEG_PER_PIXEL
float getCameraPointingY() const
Returns the y pointing of the camera See also setCameraPointing(float, float, 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,...
void resizeViewport(int w, int h)
Calls the glViewport function.
virtual void setCameraParams(const CamaraParams ¶ms)
Sets the CamaraParams See also cameraParams(), getRefCameraParams()
float getAzimuthDegrees() const
Returns a azimuth degrees See also setAzimuthDegrees(float)
void setOpenGLSceneRef(mrpt::opengl::COpenGLScene::Ptr scene)
A camera: if added to a scene, the viewpoint defined by this camera will be used instead of the camer...
void setPointingAt(float x, float y, float z)
void setElevationDegrees(float ang)
void setZoomDistance(float z)
void setProjectiveFOVdeg(float ang)
Field-of-View in degs, only when projectiveModel=true (default=30 deg).
void setProjectiveModel(bool v=true)
Enable/Disable projective mode (vs.
void setAzimuthDegrees(float ang)
std::shared_ptr< COpenGLScene > Ptr
std::shared_ptr< COpenGLViewport > Ptr
A high-performance stopwatch, with typical resolution of nanoseconds.
void Tic() noexcept
Starts the stopwatch.
double Tac() noexcept
Stops the stopwatch.
#define THROW_EXCEPTION(msg)
GLAPI void GLAPIENTRY glEnable(GLenum cap)
GLAPI void GLAPIENTRY glLoadIdentity(void)
GLAPI void GLAPIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
#define GL_ALL_ATTRIB_BITS
GLAPI void GLAPIENTRY glPopAttrib(void)
GLAPI void GLAPIENTRY glPushAttrib(GLbitfield mask)
GLAPI void GLAPIENTRY glMatrixMode(GLenum mode)
GLAPI void GLAPIENTRY glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
GLAPI void GLAPIENTRY glFlush(void)
GLubyte GLubyte GLubyte GLubyte w
GLdouble GLdouble GLdouble r
GLubyte GLubyte GLubyte a
GLenum GLsizei GLsizei height
GLenum const GLfloat * params
GLsizei const GLchar ** string
Classes for creating GUI windows for 2D and 3D visualization.
The namespace for 3D scene representation and rendering.
mrpt::system::CTicTac CTicTac
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double DEG2RAD(const double x)
Degrees to radians.
void setElevationDeg(float deg)