SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLKeyframeCamera.cpp
Go to the documentation of this file.
1 /**
2  * \file SLKeyframeCamera.cpp
3  * \authors Michael Goettlicher, Marcus Hudritsch
4  * \date Dezember 2017
5  * \authors Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9 */
10 
11 #include <SLKeyframeCamera.h>
12 #include <SLSceneView.h>
13 #include <SLGLTexture.h>
14 
16  : SLCamera(name)
17 {
18  setDrawColor();
19 }
20 //-----------------------------------------------------------------------------
21 //! SLKeyframeCamera::drawMeshes draws the cameras frustum lines
22 /*!
23 Only draws the frustum lines without lighting when the camera is not the
24 active one. This means that it can be seen from the active view point.
25 */
27 {
28  if (sv->camera() != this)
29  {
30  // Return if hidden
31  if (sv->drawBit(SL_DB_HIDDEN) || this->drawBit(SL_DB_HIDDEN))
32  return;
33 
34  // Vertices of the near plane
35  SLVec3f nearRT, nearRB, nearLT, nearLB;
36 
38  {
39  const SLMat4f& vm = updateAndGetWMI();
40  SLVVec3f P;
41  SLVec3f pos(vm.translation());
42  SLfloat t = tan(Utils::DEG2RAD * _fovV * 0.5f) * pos.length();
43  SLfloat b = -t;
44  SLfloat l = -sv->scrWdivH() * t;
45  SLfloat r = -l;
46 
47  // small line in view direction
48  P.push_back(SLVec3f(0, 0, 0));
49  P.push_back(SLVec3f(0, 0, _clipNear));
50 
51  // frustum pyramid lines
52  nearRT.set(r, t, -_clipNear);
53  nearRB.set(r, b, -_clipNear);
54  nearLT.set(l, t, -_clipNear);
55  nearLB.set(l, b, -_clipNear);
56 
57  // around near clipping plane
58  P.push_back(SLVec3f(r, t, _clipNear));
59  P.push_back(SLVec3f(r, b, _clipNear));
60  P.push_back(SLVec3f(r, b, _clipNear));
61  P.push_back(SLVec3f(l, b, _clipNear));
62  P.push_back(SLVec3f(l, b, _clipNear));
63  P.push_back(SLVec3f(l, t, _clipNear));
64  P.push_back(SLVec3f(l, t, _clipNear));
65  P.push_back(SLVec3f(r, t, _clipNear));
66 
68  }
69  else
70  {
71  SLVVec3f P;
73  SLfloat tanFov = tan(_fovV * Utils::DEG2RAD * 0.5f);
74  SLfloat tN = tanFov * _clipNear; // top near
75  SLfloat rN = tN * aspect; // right near
76  SLfloat lN = -tN * aspect; // left near
77 
78  // small line in view direction
79  P.push_back(SLVec3f(0, 0, 0));
80  P.push_back(SLVec3f(0, 0, _clipNear));
81 
82  // frustum pyramid lines
83  nearRT.set(rN, tN, -_clipNear);
84  nearRB.set(rN, -tN, -_clipNear);
85  nearLT.set(lN, tN, -_clipNear);
86  nearLB.set(lN, -tN, -_clipNear);
87 
88  P.push_back(SLVec3f(0, 0, 0));
89  P.push_back(nearRT);
90  P.push_back(SLVec3f(0, 0, 0));
91  P.push_back(nearLT);
92  P.push_back(SLVec3f(0, 0, 0));
93  P.push_back(nearLB);
94  P.push_back(SLVec3f(0, 0, 0));
95  P.push_back(nearRB);
96 
97  // around near clipping plane
98  P.push_back(SLVec3f(rN, tN, -_clipNear));
99  P.push_back(SLVec3f(rN, -tN, -_clipNear));
100  P.push_back(SLVec3f(rN, -tN, -_clipNear));
101  P.push_back(SLVec3f(lN, -tN, -_clipNear));
102  P.push_back(SLVec3f(lN, -tN, -_clipNear));
103  P.push_back(SLVec3f(lN, tN, -_clipNear));
104  P.push_back(SLVec3f(lN, tN, -_clipNear));
105  P.push_back(SLVec3f(rN, tN, -_clipNear));
106 
108  }
109 
110  SLCol4f color = sv->s()->singleNodeSelected() == this ? SLCol4f::YELLOW : _color;
112 
113  if (renderBackground())
114  _background.renderInScene(updateAndGetWM(), nearLT, nearLB, nearRT, nearRB);
115  }
116 }
117 
118 //-----------------------------------------------------------------------------
119 
120 //! SLKeyframeCamera::setDrawColor specify which color should be use.
121 
123 {
124  _color = color;
125 }
float SLfloat
Definition: SL.h:173
string SLstring
Definition: SL.h:158
#define SL_DB_HIDDEN
Flags an object as hidden.
Definition: SLDrawBits.h:20
@ P_monoOrthographic
standard mono orthographic projection
Definition: SLEnums.h:137
@ PT_lines
Definition: SLGLEnums.h:32
vector< SLVec3f > SLVVec3f
Definition: SLVec3.h:325
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
void renderInScene(const SLMat4f &wm, const SLVec3f &LT, const SLVec3f &LB, const SLVec3f &RT, const SLVec3f &RB)
Draws the background as a quad on the far clipping plane.
Active or visible camera node class.
Definition: SLCamera.h:54
SLBackground _background
Colors or texture displayed in the background.
Definition: SLCamera.h:198
SLfloat _fovV
Current vertical field of view (view angle) in degrees.
Definition: SLCamera.h:187
SLfloat _clipNear
Dist. to the near clipping plane.
Definition: SLCamera.h:189
SLGLVertexArrayExt _vao
OpenGL Vertex array for rendering.
Definition: SLCamera.h:200
SLfloat aspect() const
Definition: SLCamera.h:139
SLProjType _projType
Projection type.
Definition: SLCamera.h:186
void generateVertexPos(SLVVec2f *p)
Adds or updates & generates a position vertex attribute for colored line or point drawing.
void drawArrayAsColored(SLGLPrimitiveType primitiveType, SLCol4f color, SLfloat lineOrPointSize=1.0f, SLuint indexFirstVertex=0, SLuint countVertices=0)
Draws the array as the specified primitive with the color.
SLKeyframeCamera(SLstring name="Camera")
virtual void drawMesh(SLSceneView *sv)
SLKeyframeCamera::drawMeshes draws the cameras frustum lines.
void setDrawColor(SLCol4f color=SLCol4f::WHITE *0.7f)
SLKeyframeCamera::setDrawColor specify which color should be use.
SLVec3< T > translation() const
Definition: SLMat4.h:184
const SLMat4f & updateAndGetWM() const
Definition: SLNode.cpp:703
const SLMat4f & updateAndGetWMI() const
Definition: SLNode.cpp:714
SLNode * singleNodeSelected()
Returns the node if only one is selected. See also SLMesh::selectNodeMesh.
Definition: SLScene.h:116
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
SLfloat scrWdivH() const
Definition: SLSceneView.h:174
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
SLbool drawBit(SLuint bit)
Definition: SLSceneView.h:199
SLScene * s()
Definition: SLSceneView.h:167
T length() const
Definition: SLVec3.h:122
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59
static SLVec4 YELLOW
Definition: SLVec4.h:219
static const float DEG2RAD
Definition: Utils.h:239