Free Electron
CameraEditable.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __draw_CameraEditable_h__
8 #define __draw_CameraEditable_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief Adjustable Camera
17 
18  @ingroup draw
19 *//***************************************************************************/
20 class FE_DL_EXPORT CameraEditable:
21  virtual public CameraI,
22  public CastableAs<CameraEditable>
23 {
24  public:
25 
26  CameraEditable(void):
27  m_fov(0.0f,45.0f),
28  m_nearplane(0.1f),
29  m_farplane(1e4f),
30  m_zoom(1.0f),
31  m_rasterSpace(FALSE)
32  {
33  setIdentity(m_cameraMatrix);
34  set(m_center);
35  setName("CameraEditable");
36  }
37 
38  void copy(sp<CameraI> a_spCameraI);
39 
40  //* as CameraI
41 virtual void setCameraMatrix(const SpatialTransform& matrix)
42  { m_cameraMatrix=matrix; }
43 virtual
44 const SpatialTransform& cameraMatrix(void) const
45  { return m_cameraMatrix; }
46 
47 virtual Vector2 fov(void) const
48  { return m_fov; }
49 virtual void setFov(Vector2 a_fov)
50  { m_fov=a_fov; }
51 
52 virtual void setPlanes(Real nearplane,Real farplane)
53  { m_nearplane=nearplane;
54  m_farplane=farplane; }
55 virtual void getPlanes(Real& nearplane,Real& farplane)
56  { nearplane=m_nearplane;
57  farplane=m_farplane; }
58 
59 virtual void setOrtho(Real a_zoom, const Vector2 &a_center)
60  { m_zoom = a_zoom;
61  m_center = a_center; }
62 virtual void getOrtho(Real &a_zoom, Vector2 &a_center) const
63  { a_zoom = m_zoom;
64  a_center = m_center; }
65 
66 virtual void setRasterSpace(BWORD a_rasterSpace)
67  { m_rasterSpace = a_rasterSpace; }
68 virtual BWORD rasterSpace(void) const
69  { return m_rasterSpace; }
70 
71  protected:
72 
73  //* ortho or perspective
74  SpatialTransform m_cameraMatrix;
75 
76  //* perspective
77  Vector2 m_fov;
78  Real m_nearplane;
79  Real m_farplane;
80 
81  //* ortho
82  Vector2 m_center;
83  Real m_zoom;
84 
85  BWORD m_rasterSpace;
86 };
87 
88 inline void CameraEditable::copy(const sp<CameraI> a_spCameraI)
89 {
90  setCameraMatrix(a_spCameraI->cameraMatrix());
91 
92  setFov(a_spCameraI->fov());
93 
94  Real nearplane;
95  Real farplane;
96  a_spCameraI->getPlanes(nearplane,farplane);
97  setPlanes(nearplane,farplane);
98 
99  Real zoom;
100  Vector2 center;
101  a_spCameraI->getOrtho(zoom,center);
102  setOrtho(zoom,center);
103 
104  setRasterSpace(a_spCameraI->rasterSpace());
105 }
106 
107 inline String print(const sp<CameraEditable> a_spCameraEditable)
108 {
109  const Real fovy=a_spCameraEditable->fov()[1];
110 
111  Real nearplane;
112  Real farplane;
113  a_spCameraEditable->getPlanes(nearplane,farplane);
114 
115  Real zoom;
116  Vector2 center;
117  a_spCameraEditable->getOrtho(zoom,center);
118 
119  const SpatialTransform xform=a_spCameraEditable->cameraMatrix();
120 
121  String s;
122  s.sPrintf("fovy %g near %g far %g"
123  " zoom %g center %s camera:\n%s",
124  fovy,nearplane,farplane,
125  zoom,c_print(center),c_print(xform));
126  return s;
127 }
128 
129 } /* namespace ext */
130 } /* namespace fe */
131 
132 #endif /* __draw_CameraEditable_h__ */
virtual void setFov(Vector2 a_fov)
Set perspective Field of View (degrees)
Definition: CameraEditable.h:49
virtual void setOrtho(Real a_zoom, const Vector2 &a_center)
Set clipping planes.
Definition: CameraEditable.h:59
kernel
Definition: namespace.dox:3
virtual const SpatialTransform & cameraMatrix(void) const
Get camera transform.
Definition: CameraEditable.h:44
virtual void getPlanes(Real &nearplane, Real &farplane)
Get distance clipping planes.
Definition: CameraEditable.h:55
virtual void setPlanes(Real nearplane, Real farplane)
Set distance clipping planes.
Definition: CameraEditable.h:52
virtual void getOrtho(Real &a_zoom, Vector2 &a_center) const
Get clipping planes.
Definition: CameraEditable.h:62
virtual void setCameraMatrix(const SpatialTransform &matrix)
Set camera transform.
Definition: CameraEditable.h:41
virtual void setRasterSpace(BWORD a_rasterSpace)
choose drawing to 2D pixel coordinates
Definition: CameraEditable.h:66
virtual BWORD rasterSpace(void) const
Get raster space mode (on/off)
Definition: CameraEditable.h:68
String & sPrintf(const char *fmt,...)
Populate the string in the manner of sprintf().
Definition: String.cc:529
Automatically reference-counted string container.
Definition: String.h:128
virtual Vector2 fov(void) const
Get perspective Field of View (degrees)
Definition: CameraEditable.h:47
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
viewing position
Definition: CameraI.h:20
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192
Adjustable Camera.
Definition: CameraEditable.h:20