Developer Documentation
CameraNode.hh
1 /* ========================================================================= *
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  * ========================================================================= */
41 
42 /*===========================================================================*\
43  *
44  * $Revision$
45  * $Date$
46  *
47 \*===========================================================================*/
48 
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS CameraNode
56 //
57 //=============================================================================
58 
59 
60 #ifndef ACG_CAMERAVIS_NODE_HH
61 #define ACG_CAMERAVIS_NODE_HH
62 
63 //== INCLUDES =================================================================
64 
65 
66 #include <ACG/Scenegraph/BaseNode.hh>
67 #include <ACG/Scenegraph/DrawModes.hh>
68 #include <ACG/GL/GLPrimitives.hh>
69 #include <ACG/GL/globjects.hh>
70 #include <string>
71 #include <vector>
72 
73 #include <ACG/Math/QuaternionT.hh>
74 
76 
77 //== NAMESPACES ===============================================================
78 
79 namespace ACG {
80 namespace SceneGraph {
81 
82 //== CLASS DEFINITION =========================================================
83 
84 
90 class OBJECTTYPEDLLEXPORT CameraNode: public BaseNode {
91 
92 public:
93 
95  CameraNode( BaseNode* _parent = 0, std::string _name = "<CameraVis>");
96 
98  virtual ~CameraNode();
99 
100  ACG_CLASSNAME( CameraNode);
101 
103  DrawModes::DrawMode availableDrawModes() const override;
104 
106  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
107 
109  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
110 
112  void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat) override;
113 
115  void pick(GLState& _state, PickTarget _target) override;
116 
118  void setModelView(ACG::GLMatrixd _modelView) { modelView_ = _modelView; modelViewInv_ = _modelView; modelViewInv_.invert(); update_vbo_ = true; }
119 
121  const ACG::GLMatrixd& modelview() const {return modelView_;}
122 
124  void setProjection(ACG::GLMatrixd _projection) { projection_ = _projection; update_vbo_ = true; }
125 
127  const ACG::GLMatrixd& projection() const {return projection_;}
128 
130  OM_DEPRECATED("setSize() is redundant, because it is already defined by the projection matrix.")
131  void setSize(int _w, int _h) { /*obsolete*/ }
132 
134  void setEncodedView(QString _encodedView) { encodedView_ = _encodedView; }
135 
137  OM_DEPRECATED("setFarPlane() is redundant, because it is already defined by the projection matrix.")
138  void setFarPlane(double _far) { /*obsolete*/ }
139 
141  OM_DEPRECATED("setNearPlane() is redundant, because it is already defined by the projection matrix.")
142  void setNearPlane(double _near) { /*obsolete*/ }
143 
145  QString getEncodedView() { return encodedView_; }
146 
148  void showFrustum(bool _showFrustum) { showFrustum_ = _showFrustum; }
149 
151  bool showFrustum() { return showFrustum_; }
152 
153 
154 private:
155 
156  void updateVBO();
157 
158  void updateBoundingBoxes();
159 
160  // recalculate frustum positions in world space
161  void updateFrustumWS();
162 
163  OpenMesh::Vec3d bbmin_;
164  OpenMesh::Vec3d bbmax_;
165 
166  ACG::GLMatrixd modelView_;
167  ACG::GLMatrixd modelViewInv_;
168  ACG::GLMatrixd projection_;
169 
170  GLCylinder* cylinder_;
171  GLCone* cone_;
172  float axis_length_;
173 
174  GeometryBuffer vbo_;
175  IndexBuffer ibo_;
176  VertexDeclaration vdecl_;
177  bool update_vbo_;
178  std::vector<Vec4f> vboData_; // 8 frustum vertices + camera position
179  int offsetTris_; // offsets into index buffer
180  int offsetLines_;
181  int offsetFront_;
182 
183  QString encodedView_;
184 
185  bool showFrustum_;
186 };
187 
188 
189 
190 //=============================================================================
191 } // namespace SceneGraph
192 } // namespace ACG
193 
194 //=============================================================================
195 #endif // ACG_CameraVis_NODE_HH
196 //=============================================================================
Namespace providing different geometric functions concerning angles.
Class to define the vertex input layout.
bool showFrustum()
Returns true if camera renders its whole frustum.
Definition: CameraNode.hh:151
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
bool invert()
matrix inversion (returns true on success)
#define OM_DEPRECATED(msg)
define OM_SUPPRESS_DEPRECATED to suppress deprecated code warnings
Definition: config.h:102
QString getEncodedView()
Return encoded view string.
Definition: CameraNode.hh:145
void showFrustum(bool _showFrustum)
Set if viewing frustum should be shown or not.
Definition: CameraNode.hh:148
void setModelView(ACG::GLMatrixd _modelView)
set model view matrix
Definition: CameraNode.hh:118
const ACG::GLMatrixd & modelview() const
Returns the modelview matrix.
Definition: CameraNode.hh:121
ACG::SceneGraph::CameraNode CameraNode
Simple Name for CameraNode.
Definition: CameraTypes.hh:75
void setEncodedView(QString _encodedView)
Return encoded view string.
Definition: CameraNode.hh:134
const ACG::GLMatrixd & projection() const
Returns the projection matrix.
Definition: CameraNode.hh:127
void setProjection(ACG::GLMatrixd _projection)
Set projection Matrix ( used to calculate frustum ... )
Definition: CameraNode.hh:124