MRPT  1.9.9
MRPT2NanoguiGLCanvas.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "gui-precomp.h" // Precompiled headers
11 
12 #include <mrpt/core/exceptions.h>
14 
15 using namespace mrpt::gui;
16 
17 #if MRPT_HAS_NANOGUI
18 
20  : nanogui::GLCanvas(parent)
21 {
22 }
23 
25 
27 {
28 #if MRPT_HAS_OPENGL_GLUT
29  std::lock_guard<std::mutex> lck(scene_mtx);
30 
31  try
32  {
33  // Set the background color:
34  mrpt::img::TColorf m_backgroundColor = {0.7f, 0.7f, 0.7f, 1.0f};
35  glClearColor(
36  m_backgroundColor.R, m_backgroundColor.G, m_backgroundColor.B,
37  m_backgroundColor.A);
38 
39  if (!scene) return; // No scene -> nothing to render
40 
41  // We need the size of the viewport:
42  GLint win_dims[4];
43  glGetIntegerv(GL_VIEWPORT, win_dims);
44 
45  // Set the camera params in the scene:
46  mrpt::opengl::COpenGLViewport::Ptr view = scene->getViewport("main");
47  if (!view)
49  "Fatal error: there is no 'main' viewport in the 3D scene!");
50  mrpt::opengl::CCamera& cam = view->getCamera();
52 
53  for (const auto& m_viewport : scene->viewports())
54  m_viewport->render(
55  win_dims[2], win_dims[3], win_dims[0], win_dims[1]);
56  }
57  catch (const std::exception& e)
58  {
59  std::cerr << "[MRPT2NanoguiGLCanvas::drawGL] Exception:\n"
61  }
62 #endif
63 }
64 
66  const nanogui::Vector2i& p, const nanogui::Vector2i& rel, int button,
67  int modifiers)
68 {
69  m_headless_canvas.mouseMotionEvent(p, rel, button, modifiers);
70  return true; // already processed
71 }
72 
74  const nanogui::Vector2i& p, int button, bool down, int modifiers)
75 {
76  m_headless_canvas.mouseButtonEvent(p, button, down, modifiers);
77  return true; // already processed
78 }
80  const nanogui::Vector2i& p, const nanogui::Vector2f& rel)
81 {
83  return true; // already processed
84 }
85 
86 #endif // MRPT_HAS_NANOGUI
virtual bool scrollEvent(const nanogui::Vector2i &p, const nanogui::Vector2f &rel) override
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
void scrollEvent(const nanogui::Vector2i &p, const nanogui::Vector2f &rel)
virtual bool mouseMotionEvent(const nanogui::Vector2i &p, const nanogui::Vector2i &rel, int button, int modifiers) override
void render(const RenderContext &rc) const override
Render does nothing here.
Definition: CCamera.h:93
MRPT2NanoguiGLCanvas(nanogui::Widget *parent)
virtual bool mouseButtonEvent(const nanogui::Vector2i &p, int button, bool down, int modifiers) override
internal::NanoGUICanvasHeadless m_headless_canvas
Used to keep track of mouse events on the camera.
void mouseButtonEvent(const nanogui::Vector2i &p, int button, bool down, int modifiers)
An RGBA color - floats in the range [0,1].
Definition: TColor.h:88
mrpt::opengl::COpenGLScene::Ptr scene
The scene to render in this control.
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...
Definition: exceptions.cpp:59
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
A camera: if added to a scene, the viewpoint defined by this camera will be used instead of the camer...
Definition: CCamera.h:33
void mouseMotionEvent(const nanogui::Vector2i &p, const nanogui::Vector2i &rel, int button, int modifiers)
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)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020