Go to the documentation of this file.
17 #if MRPT_HAS_OPENGL_GLUT
24 #include <GLUT/glut.h>
25 #include <OpenGL/gl.h>
26 #include <OpenGL/glu.h>
31 #ifdef HAVE_FREEGLUT_EXT_H
32 #include <GL/freeglut_ext.h>
35 #endif // MRPT_HAS_OPENGL_GLUT
50 if (m_openGLScene) m_openGLScene->unloadShaders();
64 float zoom =
params.cameraZoomDistance * exp(0.01f * (y - m_mouseClickY));
65 if (zoom <= m_minZoom || (m_maxZoom != -1.0f && m_maxZoom <= zoom))
return;
66 params.cameraZoomDistance = zoom;
67 if (
params.cameraZoomDistance < 0.01f)
params.cameraZoomDistance = 0.01f;
69 float Az = -0.05f * (x - m_mouseClickX);
70 float D = 0.001f *
params.cameraZoomDistance;
71 params.cameraPointingZ += D * Az;
76 float zoom =
params.cameraZoomDistance * (1 - 0.03f * (delta / 120.0f));
77 if (zoom <= m_minZoom || (m_maxZoom != -1.0f && m_maxZoom <= zoom))
return;
79 params.cameraZoomDistance = zoom;
86 const int x,
const int y,
const int& mouseClickX,
const int& mouseClickY)
88 if (std::abs(x - mouseClickX) > 60)
const_cast<int&
>(mouseClickX) = x;
89 if (std::abs(y - mouseClickY) > 60)
const_cast<int&
>(mouseClickY) = y;
96 const float dis = max(0.01f, (
params.cameraZoomDistance));
107 float A_AzimuthDeg = -SENSIBILITY_DEG_PER_PIXEL * (x - m_mouseClickX);
108 params.cameraAzimuthDeg += A_AzimuthDeg;
110 float A_ElevationDeg = SENSIBILITY_DEG_PER_PIXEL * (y - m_mouseClickY);
111 params.setElevationDeg(
params.cameraElevationDeg + A_ElevationDeg);
128 params.cameraAzimuthDeg -= 0.2f * (x - m_mouseClickX);
130 params.cameraElevationDeg + 0.2f * (y - m_mouseClickY));
141 #if MRPT_HAS_OPENGL_GLUT
142 if (w == -1 || h == -1)
return;
144 glViewport(0, 0, (GLint)w, (GLint)h);
150 #if MRPT_HAS_OPENGL_GLUT
151 glClearColor(clearColorR, clearColorG, clearColorB, clearColorA);
157 float Ay = -(x - m_mouseClickX);
158 float Ax = -(y - m_mouseClickY);
159 float D = 0.001f *
params.cameraZoomDistance;
168 return m_cameraParams;
173 return m_cameraParams;
183 return m_cameraParams.cameraZoomDistance;
188 m_cameraParams.cameraZoomDistance = zoom;
194 m_cameraParams.cameraPointingX, m_cameraParams.cameraPointingY,
195 m_cameraParams.cameraPointingZ);
209 m_cameraParams.cameraAzimuthDeg = ang;
214 m_cameraParams.cameraElevationDeg = ang;
219 return m_cameraParams.cameraAzimuthDeg;
224 return m_cameraParams.cameraElevationDeg;
229 m_cameraParams.cameraIsProjective = is;
234 return m_cameraParams.cameraIsProjective;
253 m_openGLScene = scene;
258 m_cameraParams.cameraPointingX = pointX;
259 m_cameraParams.cameraPointingY = pointY;
260 m_cameraParams.cameraPointingZ = pointZ;
265 return m_cameraParams.cameraPointingX;
270 return m_cameraParams.cameraPointingY;
275 return m_cameraParams.cameraPointingZ;
280 #if MRPT_HAS_OPENGL_GLUT
288 CHECK_OPENGL_ERROR();
291 glEnable(GL_DEPTH_TEST);
292 CHECK_OPENGL_ERROR();
295 resizeViewport((GLsizei)width, (GLsizei)height);
303 if (!useCameraFromScene)
309 "Fatal error: there is no 'main' viewport in the 3D "
314 updateCameraParams(cam);
320 m_openGLScene->render();
329 CHECK_OPENGL_ERROR();
333 catch (
const std::exception& e)
335 const std::string err_msg =
336 std::string(
"[CGLCanvasBase::Render] Exception:\n") +
338 std::cerr << err_msg;
339 renderError(err_msg);
350 cameraElevationDeg = deg;
352 if (cameraElevationDeg < -90.0f)
353 cameraElevationDeg = -90.0f;
354 else if (cameraElevationDeg > 90.0f)
355 cameraElevationDeg = 90.0f;
360 std::cerr <<
"[CGlCanvasBaseHeadless::renderError] Error:" << e
const CamaraParams & getRefCameraParams() const
Returns a reference to CamaraParams See also cameraParams(), setCameraParams(const CamaraParams &)
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 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...
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 setAzimuthDegrees(float ang)
bool getUseCameraFromScene() const
See also void setUseCameraFromScene(bool)
float getCameraPointingZ() const
Returns the z pointing of the camera See also setCameraPointing(float, float, float)
float getAzimuthDegrees() const
Returns a azimuth degrees See also setAzimuthDegrees(float)
virtual void setCameraProjective(bool is)
static float SENSIBILITY_DEG_PER_PIXEL
float getClearColorG() const
void setProjectiveModel(bool v=true)
Enable/Disable projective mode (vs.
A high-performance stopwatch, with typical resolution of nanoseconds.
void setProjectiveFOVdeg(float ang)
Vertical field-of-View in degs, only when projectiveModel=true (default=30 deg).
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...
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 setMaximumZoom(float zoom)
Sets the maximum of the zoom See also setMinimumZoom(float)
void setElevationDeg(float deg)
virtual void setCameraParams(const CamaraParams ¶ms)
Sets the CamaraParams See also cameraParams(), getRefCameraParams()
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void setClearColors(float r, float g, float b, float a=1.0f)
Sets the RGBA colors for glClearColor See also clearColors(), getClearColorR(), getClearColorG(),...
void setPointingAt(float x, float y, float z)
#define THROW_EXCEPTION(msg)
bool isCameraProjective() const
virtual void setAzimuthDegrees(float ang)
Saves the degrees of the azimuth camera See also getAzimuthDegrees()
double Tac() noexcept
Stops the stopwatch.
float getCameraPointingY() const
Returns the y pointing of the camera See also setCameraPointing(float, float, float)
std::shared_ptr< mrpt::opengl ::COpenGLViewport > Ptr
mrpt::system::CTicTac CTicTac
void mouseGlitchFilter(const int x, const int y, const int &mouseClickX, const int &mouseClickY)
void updateLastPos(int x, int y)
Sets the last mouse position.
A camera: if added to a scene, the viewpoint defined by this camera will be used instead of the camer...
float getZoomDistance() const
Returns a zoom See also setZoomDistance(float)
void setZoomDistance(float z)
void Tic() noexcept
Starts the stopwatch.
void clearColors()
Calls the glClearColor function See also setClearColors(float, float, float, float)
float getClearColorA() const
constexpr double DEG2RAD(const double x)
Degrees to radians
mrpt::vision::TStereoCalibParams params
Classes for creating GUI windows for 2D and 3D visualization.
float getElevationDegrees() const
Returns a elevation degrees See also setElevationDegrees(float)
std::shared_ptr< mrpt::opengl ::COpenGLScene > Ptr
void setOpenGLSceneRef(mrpt::opengl::COpenGLScene::Ptr scene)
void setElevationDegrees(float ang)
virtual void setCameraFOV(float FOV)
float getClearColorB() const
virtual double renderCanvas(int width=-1, int height=-1)
float getCameraPointingX() const
Returns the x pointing of the camera See also setCameraPointing(float, float, float)
virtual void renderError(const std::string &e) override
virtual void setCameraPointing(float pointX, float pointY, float pointZ)
Saves the pointing of the camera See also getCameraPointingX(), getCameraPointingY(),...
void resizeViewport(int w, int h)
Calls the glViewport function.
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
void setMousePos(int x, int y)
Saves the click position of the mouse See also setMouseClicked(bool)
virtual void setElevationDegrees(float ang)
Saves the degrees of the elevation camera See also getElevationDegrees()
The namespace for 3D scene representation and rendering.
void setMouseClicked(bool is)
Sets the property mouseClicked By default, this property is false.
float getClearColorR() const
void setMinimumZoom(float zoom)
Sets the minimum of the zoom See also setMaximumZoom(float)
void setUseCameraFromScene(bool is)
If set to true (default=false), the cameraPointingX,...
CamaraParams cameraParams() const
Returns a copy of CamaraParams See also getRefCameraParams(), setCameraParams(const CamaraParams &)
virtual void setZoomDistance(float zoom)
Saves camera zooming See also getZoomDistance()
Page generated by Doxygen 1.8.18 for MRPT 2.0.4 at Thu Sep 24 07:14:18 UTC 2020 | |