MRPT  2.0.4
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
float m_projectiveFOVdeg
Field-of-View in degs, only when projectiveModel=true (default=30 deg).
Definition: CCamera.h:115
void freeOpenGLResources() override
Free opengl buffers.
Definition: CCamera.h:103
void setOrthogonal(bool v=true)
Enable/Disable orthogonal mode (vs.
Definition: CCamera.h:72
float getPointingAtY() const
Definition: CCamera.h:61
void set6DOFMode(bool v)
Set 6DOFMode, if enabled camera is set according to its pose (default=false).
Definition: CCamera.h:80
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
void setProjectiveModel(bool v=true)
Enable/Disable projective mode (vs.
Definition: CCamera.h:70
float getZoomDistance() const
Definition: CCamera.h:64
A viewport within a COpenGLScene, containing a set of OpenGL objects to render.
~CCamera() override=default
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
void setZoomDistance(float z)
Definition: CCamera.h:63
Context for calls to render()
void setPointingAt(const mrpt::math::TPoint3D &p)
Definition: CCamera.h:55
void setAzimuthDegrees(float ang)
Definition: CCamera.h:67
float getPointingAtX() const
Definition: CCamera.h:60
float getPointingAtZ() const
Definition: CCamera.h:62
float d2f(const double d)
shortcut for static_cast<float>(double)
void renderUpdateBuffers() const override
Render does nothing here.
Definition: CCamera.h:96
float getAzimuthDegrees() const
Definition: CCamera.h:65
void render(const RenderContext &rc) const override
Render does nothing here.
Definition: CCamera.h:93
void setProjectiveFOVdeg(float ang)
Vertical field-of-View in degs, only when projectiveModel=true (default=30 deg).
Definition: CCamera.h:87
T x
X,Y,Z coordinates.
Definition: TPoint3D.h:29
float getElevationDegrees() const
Definition: CCamera.h:66
void setElevationDegrees(float ang)
Definition: CCamera.h:68
bool m_projectiveModel
If set to true (default), camera model is projective, otherwise, it&#39;s orthogonal. ...
Definition: CCamera.h:112
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
const auto bb_max
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
const auto bb_min
bool m_6DOFMode
If set to true, camera pose is used when rendering the viewport.
Definition: CCamera.h:117
float getProjectiveFOVdeg() const
Field-of-View in degs, only when projectiveModel=true (default=30 deg).
Definition: CCamera.h:90
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 setPointingAt(const POSEORPOINT &p)
Definition: CCamera.h:49
bool is6DOFMode() const
Definition: CCamera.h:83
bool isProjective() const
Definition: CCamera.h:81
bool isOrthogonal() const
Definition: CCamera.h:82
void setPointingAt(float x, float y, float z)
Definition: CCamera.h:41



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020