Developer Documentation
BoxesNode.hh
1#pragma once
2/*===========================================================================*\
3 * *
4 * OpenFlipper *
5 * Copyright (c) 2001-2015, RWTH-Aachen University *
6 * Department of Computer Graphics and Multimedia *
7 * All rights reserved. *
8 * www.openflipper.org *
9 * *
10 *---------------------------------------------------------------------------*
11 * This file is part of OpenFlipper. *
12 *---------------------------------------------------------------------------*
13 * *
14 * Redistribution and use in source and binary forms, with or without *
15 * modification, are permitted provided that the following conditions *
16 * are met: *
17 * *
18 * 1. Redistributions of source code must retain the above copyright notice, *
19 * this list of conditions and the following disclaimer. *
20 * *
21 * 2. Redistributions in binary form must reproduce the above copyright *
22 * notice, this list of conditions and the following disclaimer in the *
23 * documentation and/or other materials provided with the distribution. *
24 * *
25 * 3. Neither the name of the copyright holder nor the names of its *
26 * contributors may be used to endorse or promote products derived from *
27 * this software without specific prior written permission. *
28 * *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
32 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
40 * *
41\*===========================================================================*/
42
43
44#include <ACG/Scenegraph/MaterialNode.hh>
45#include <ACG/Scenegraph/DrawModes.hh>
46#include <ACG/GL/VertexDeclaration.hh>
47#include <ACG/GL/globjects.hh>
48#include <ACG/Math/Matrix3x3T.hh>
49#include <vector>
50#include <limits>
51
52namespace ACG {
53namespace SceneGraph {
54
55struct BoxElement {
56 Matrix3x3d transform;
57 Vec3d pos;
58};
59
60class BoxesNode : public MaterialNode
61{
62public:
64
65 BoxesNode(BaseNode* _parent=nullptr,
66 std::string _name="<BoxesNode>" );
67
68 ~BoxesNode() = default;
69
72 }
73
74 void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
75
76 void clear() { elem_.clear(); updateVBO_ = true; }
77
78 void reserve(size_t _n) { elem_.reserve(_n); }
79
81 void push_back(const BoxElement& _v) { elem_.push_back(_v); updateVBO_ = true; }
82 typedef BoxElement value_type;
83 typedef BoxElement& reference;
84 typedef const BoxElement& const_reference;
85
86 void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const ACG::SceneGraph::Material* _mat) override;
87
88 void setScaleFactor(float _val) { scaleFactor_ = _val;}
89
90protected:
92 void createVBO();
93
94 std::vector<BoxElement> elem_;
95 float scaleFactor_ = 1.0f;
96
97 // geometry of a single box
98 std::vector<std::array<Vec3f,3>> triangles_;
99 std::vector<Vec4f> triangle_colors_;
100
101 GeometryBuffer geometry_vbo_;
102 GeometryBuffer instance_vbo_;
103
104 // True if points changed and the vbo has to be updated
105 bool updateVBO_;
106
107 ACG::VertexDeclaration vertexDecl_;
108
109 std::string boxesNodeName_;
110};
111
112
113//=============================================================================
114} // namespace SceneGraph
115} // namespace ACG
116//=============================================================================
void createVBO()
creates the vbo only if update was requested
Definition: BoxesNode.cc:112
void push_back(const BoxElement &_v)
STL conformance.
Definition: BoxesNode.hh:81
DrawModes::DrawMode availableDrawModes() const override
Definition: BoxesNode.hh:70
void boundingBox(Vec3d &_bbMin, Vec3d &_bbMax) override
Definition: BoxesNode.cc:103
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const ACG::SceneGraph::Material *_mat) override
Deferred draw call with shader based renderer.
Definition: BoxesNode.cc:169
ACG_CLASSNAME(MaterialNode)
set current GL-color and GL-material
Class to define the vertex input layout.
DrawMode SOLID_FACES_COLORED_FLAT_SHADED
draw flat shaded and colored faces (requires face normals and colors)
Definition: DrawModes.cc:94
Namespace providing different geometric functions concerning angles.