MRPT  2.0.3
CCamera.h
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 #pragma once
11 
14 
15 namespace mrpt::opengl
16 {
17 class COpenGLViewport;
18 class CCamera;
19 
20 /** A camera: if added to a scene, the viewpoint defined by this camera will be
21  * used instead of the camera parameters set in COpenGLViewport::m_camera.
22  * A camera can be defined to provide a projective or orthogonal view of the
23  * world by setting the member CCamera::m_projectiveModel.
24  *
25  * Alternatively, a camera pose and orientation can be given as a CPose3D object
26  * if set6DOFMode() is set to `true`, then the pose can be changed with
27  * `CRenderizable::setPose()`. Pose axis convention is +X pointing forwards, +Z
28  * up.
29  *
30  * \sa opengl::COpenGLScene
31  * \ingroup mrpt_opengl_grp
32  */
33 class CCamera : public CRenderizable
34 {
35  friend class COpenGLViewport;
37  public:
38  CCamera() = default;
39  ~CCamera() override = default;
40 
41  void setPointingAt(float x, float y, float z)
42  {
43  m_pointingX = x;
44  m_pointingY = y;
45  m_pointingZ = z;
46  }
47 
48  template <class POSEORPOINT>
49  void setPointingAt(const POSEORPOINT& p)
50  {
51  m_pointingX = p.x();
52  m_pointingY = p.y();
53  m_pointingZ = p.is3DPoseOrPoint() ? p.m_coords[2] : 0;
54  }
55  inline void setPointingAt(const mrpt::math::TPoint3D& p)
56  {
57  setPointingAt(d2f(p.x), d2f(p.y), d2f(p.z));
58  }
59 
60  float getPointingAtX() const { return m_pointingX; }
61  float getPointingAtY() const { return m_pointingY; }
62  float getPointingAtZ() const { return m_pointingZ; }
63  void setZoomDistance(float z) { m_eyeDistance = z; }
64  float getZoomDistance() const { return m_eyeDistance; }
65  float getAzimuthDegrees() const { return m_azimuthDeg; }
66  float getElevationDegrees() const { return m_elevationDeg; }
67  void setAzimuthDegrees(float ang) { m_azimuthDeg = ang; }
68  void setElevationDegrees(float ang) { m_elevationDeg = ang; }
69  /** Enable/Disable projective mode (vs. orthogonal) */
70  void setProjectiveModel(bool v = true) { m_projectiveModel = v; }
71  /** Enable/Disable orthogonal mode (vs. projective) */
72  void setOrthogonal(bool v = true) { m_projectiveModel = !v; }
73  /** Set 6DOFMode, if enabled camera is set according to its pose
74  *(default=false).
75  * Conventionally, eye is set looking towards the positive direction of Z
76  *axis.
77  * Up is set as the Y axis.
78  * In this mode azimuth/elevation are ignored.
79  **/
80  void set6DOFMode(bool v) { m_6DOFMode = v; }
81  bool isProjective() const { return m_projectiveModel; }
82  bool isOrthogonal() const { return !m_projectiveModel; }
83  bool is6DOFMode() const { return m_6DOFMode; }
84  /** Vertical field-of-View in degs, only when projectiveModel=true
85  * (default=30 deg).
86  */
87  void setProjectiveFOVdeg(float ang) { m_projectiveFOVdeg = ang; }
88  /** Field-of-View in degs, only when projectiveModel=true (default=30 deg).
89  */
90  float getProjectiveFOVdeg() const { return m_projectiveFOVdeg; }
91 
92  /** Render does nothing here. */
93  void render(const RenderContext& rc) const override {}
94 
95  /** Render does nothing here. */
96  void renderUpdateBuffers() const override {}
97 
98  /** In this class, returns a fixed box (max,max,max), (-max,-max,-max). */
99  void getBoundingBox(
101  mrpt::math::TPoint3D& bb_max) const override;
102 
103  void freeOpenGLResources() override {}
104 
105  protected:
107  float m_eyeDistance{10};
108  float m_azimuthDeg{45}, m_elevationDeg{45};
109 
110  /** If set to true (default), camera model is projective, otherwise, it's
111  * orthogonal. */
112  bool m_projectiveModel{true};
113  /** Field-of-View in degs, only when projectiveModel=true (default=30 deg).
114  */
116  /** If set to true, camera pose is used when rendering the viewport */
117  bool m_6DOFMode{false};
118 };
119 
120 } // namespace mrpt::opengl
mrpt::opengl::CCamera::getProjectiveFOVdeg
float getProjectiveFOVdeg() const
Field-of-View in degs, only when projectiveModel=true (default=30 deg).
Definition: CCamera.h:90
mrpt::opengl::CCamera::setAzimuthDegrees
void setAzimuthDegrees(float ang)
Definition: CCamera.h:67
mrpt::opengl::CCamera::m_pointingZ
float m_pointingZ
Definition: CCamera.h:106
mrpt::opengl::CCamera::m_elevationDeg
float m_elevationDeg
Definition: CCamera.h:108
mrpt::opengl::CCamera::setPointingAt
void setPointingAt(const POSEORPOINT &p)
Definition: CCamera.h:49
mrpt::opengl::CCamera::setProjectiveModel
void setProjectiveModel(bool v=true)
Enable/Disable projective mode (vs.
Definition: CCamera.h:70
mrpt::opengl::CCamera::m_eyeDistance
float m_eyeDistance
Definition: CCamera.h:107
mrpt::math::TPoint3D_< double >
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:152
mrpt::opengl::CCamera::setProjectiveFOVdeg
void setProjectiveFOVdeg(float ang)
Vertical field-of-View in degs, only when projectiveModel=true (default=30 deg).
Definition: CCamera.h:87
mrpt::opengl::CCamera::m_pointingY
float m_pointingY
Definition: CCamera.h:106
mrpt::opengl::CCamera::getZoomDistance
float getZoomDistance() const
Definition: CCamera.h:64
mrpt::opengl::CRenderizable
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
mrpt::math::TPoint3D_data::z
T z
Definition: TPoint3D.h:29
mrpt::opengl::CCamera::m_projectiveFOVdeg
float m_projectiveFOVdeg
Field-of-View in degs, only when projectiveModel=true (default=30 deg).
Definition: CCamera.h:115
mrpt::opengl::CCamera::m_6DOFMode
bool m_6DOFMode
If set to true, camera pose is used when rendering the viewport.
Definition: CCamera.h:117
mrpt::opengl::CCamera::setPointingAt
void setPointingAt(float x, float y, float z)
Definition: CCamera.h:41
mrpt::opengl::CCamera::m_azimuthDeg
float m_azimuthDeg
Definition: CCamera.h:108
mrpt::opengl::CCamera::is6DOFMode
bool is6DOFMode() const
Definition: CCamera.h:83
mrpt::opengl::CCamera::freeOpenGLResources
void freeOpenGLResources() override
Free opengl buffers.
Definition: CCamera.h:103
mrpt::opengl::CCamera::render
void render(const RenderContext &rc) const override
Render does nothing here.
Definition: CCamera.h:93
mrpt::opengl::CCamera::getPointingAtX
float getPointingAtX() const
Definition: CCamera.h:60
bb_max
const auto bb_max
Definition: CPose3DPDFGrid_unittest.cpp:25
mrpt::opengl::CCamera::getPointingAtZ
float getPointingAtZ() const
Definition: CCamera.h:62
bb_min
const auto bb_min
Definition: CPose3DPDFGrid_unittest.cpp:23
mrpt::opengl::CCamera::renderUpdateBuffers
void renderUpdateBuffers() const override
Render does nothing here.
Definition: CCamera.h:96
mrpt::opengl::CCamera::~CCamera
~CCamera() override=default
mrpt::opengl::CCamera::set6DOFMode
void set6DOFMode(bool v)
Set 6DOFMode, if enabled camera is set according to its pose (default=false).
Definition: CCamera.h:80
mrpt::opengl::CCamera
A camera: if added to a scene, the viewpoint defined by this camera will be used instead of the camer...
Definition: CCamera.h:33
mrpt::opengl::CCamera::CCamera
CCamera()=default
mrpt::d2f
float d2f(const double d)
shortcut for static_cast<float>(double)
Definition: core/include/mrpt/core/bits_math.h:189
CRenderizable.h
mrpt::opengl::CCamera::setZoomDistance
void setZoomDistance(float z)
Definition: CCamera.h:63
mrpt::opengl::CRenderizable::RenderContext
Context for calls to render()
Definition: CRenderizable.h:266
mrpt::math::TPoint3D_data::y
T y
Definition: TPoint3D.h:29
mrpt::opengl::CCamera::setPointingAt
void setPointingAt(const mrpt::math::TPoint3D &p)
Definition: CCamera.h:55
mrpt::opengl::CCamera::getPointingAtY
float getPointingAtY() const
Definition: CCamera.h:61
CPoseOrPoint.h
mrpt::opengl::CCamera::setOrthogonal
void setOrthogonal(bool v=true)
Enable/Disable orthogonal mode (vs.
Definition: CCamera.h:72
mrpt::opengl::CCamera::setElevationDegrees
void setElevationDegrees(float ang)
Definition: CCamera.h:68
mrpt::opengl::CCamera::m_projectiveModel
bool m_projectiveModel
If set to true (default), camera model is projective, otherwise, it's orthogonal.
Definition: CCamera.h:112
mrpt::math::TPoint3D_data::x
T x
X,Y,Z coordinates.
Definition: TPoint3D.h:29
mrpt::opengl::COpenGLViewport
A viewport within a COpenGLScene, containing a set of OpenGL objects to render.
Definition: COpenGLViewport.h:61
mrpt::opengl::CCamera::isProjective
bool isProjective() const
Definition: CCamera.h:81
mrpt::opengl::CCamera::getAzimuthDegrees
float getAzimuthDegrees() const
Definition: CCamera.h:65
mrpt::opengl::CCamera::isOrthogonal
bool isOrthogonal() const
Definition: CCamera.h:82
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
mrpt::opengl::CCamera::getBoundingBox
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
In this class, returns a fixed box (max,max,max), (-max,-max,-max).
Definition: CCamera.cpp:57
mrpt::opengl::CCamera::m_pointingX
float m_pointingX
Definition: CCamera.h:106
mrpt::opengl::CCamera::getElevationDegrees
float getElevationDegrees() const
Definition: CCamera.h:66



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 15:49:54 UTC 2020