Developer Documentation
ArrowNode.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
45
46
47//=============================================================================
48//
49// CLASS ArrowNode
50//
51//=============================================================================
52
53
54#ifndef ACG_ARROWNODE_HH
55#define ACG_ARROWNODE_HH
56
57
58//== INCLUDES =================================================================
59
60#include <ACG/Scenegraph/MaterialNode.hh>
61#include <ACG/GL/globjects.hh>
62#include <ACG/GL/VertexDeclaration.hh>
63
64//== NAMESPACES ===============================================================
65
66namespace ACG {
67namespace SceneGraph {
68
69//== CLASS DEFINITION =========================================================
70
71
72
78class ACGDLLEXPORT ArrowNode : public MaterialNode
79{
80public:
81
83 ArrowNode(BaseNode* _parent = 0,
84 std::string _name="<ArrowNode>" );
85
87 ~ArrowNode();
88
89
92
94 DrawModes::DrawMode availableDrawModes() const override;
95
97 void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
98
100 void reserve(int _n);
101
111 int addArrow(const Vec3f& _start, const Vec3f& _dir, const Vec3f& _normal = Vec3f(0.0f, 1.0f, 0.0f), const Vec3f& _scale = Vec3f(1.0f, 1.0f, 1.0f), const Vec4uc& _color = Vec4uc(82, 82, 82, 255));
112
122 int addArrow(const Vec3f& _start, const Vec3f& _dir, const Vec3f& _normal, const Vec3f& _scale, const Vec4f& _color);
123
133 int addArrow(const Vec3d& _start, const Vec3d& _dir, const Vec3d& _normal = Vec3d(0.0, 1.0, 0.0), const Vec3d& _scale = Vec3d(1.0, 1.0, 1.0), const Vec4uc& _color = Vec4uc(82, 82, 82, 255));
134
144 int addArrow(const Vec3d& _start, const Vec3d& _dir, const Vec3d& _normal, const Vec3d& _scale, const Vec4f& _color);
145
151 Vec3f arrowStart(int _arrowID) const;
152
158 void arrowStart(int _arrowID, const Vec3f& _start);
159
160
166 Vec3f arrowDir(int _arrowID) const;
167
173 void arrowDir(int _arrowID, const Vec3f& _dir);
174
175
181 Vec3f arrowNormal(int _arrowID) const;
182
188 void arrowNormal(int _arrowID, const Vec3f& _normal);
189
196 Vec3f arrowScale(int _arrowID) const;
197
204 void arrowScale(int _arrowID, const Vec3f& _scale);
205
211 Vec4uc arrowColor(int _arrowID) const;
212
218 void arrowColor(int _arrowID, const Vec4uc& _color);
219
221 void clear();
222
224 int n_arrows() const;
225
227 void draw(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
228
236 void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const ACG::SceneGraph::Material* _mat) override;
237
238
239private:
240 void createArrowMesh();
241
242
243 GLMatrixf computeWorldMatrix(int _arrow) const;
244 GLMatrixf readWorldMatrix(int _arrow) const;
245 void updateInstanceData();
246
247 void updateInstanceBuffer();
248
249 // arrow instances
250
251 struct Arrow
252 {
253 Vec3f start, dir;
254 Vec3f normal;
255 Vec3f scale; // width, length, height
256 Vec4uc color;
257
258 void orthonormalize();
259 };
260
261 std::vector<Arrow> arrows_;
262
263 // arrow mesh:
264 int numVertices_;
265 int numIndices_;
266 GeometryBuffer vertexBuffer_;
267 IndexBuffer indexBuffer_;
268 VertexDeclaration vertexDecl_;
269 Vec3f localArrowMin_;
270 Vec3f localArrowMax_;
271
272
273 // instance data:
274 // float4x3 world transform
275 // ubyte4_norm color
276
277 // dword offset of the instance data of an arrow ( modify this if more data gets appended )
278 int instanceDataOffset(int _arrow) const {return _arrow * (4*3 + 3*3 +1);}
279
280 // size in dwords of instance data ( modify this if more data gets appended )
281 int instanceDataSize() const {return 4*3 + 3*3 + 1;}
282
283
284 std::vector<float> instanceData_;
285
286 // instance vbo
287 GeometryBuffer instanceBuffer_;
288 VertexDeclaration vertexDeclInstanced_;
289
290
291 bool invalidateInstanceData_;
292 bool invalidateInstanceBuffer_;
293 int supportsInstancing_;
294};
295
296
297//=============================================================================
298} // namespace SceneGraph
299} // namespace ACG
300//=============================================================================
301#endif // ACG_ARROWNODE_HH defined
302//=============================================================================
303
ACG_CLASSNAME(ArrowNode)
static name of this class
Class to define the vertex input layout.
Namespace providing different geometric functions concerning angles.
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:119
VectorT< unsigned char, 4 > Vec4uc
Definition: VectorT.hh:128
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121