Developer Documentation
GlutPrimitiveNode.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 // CLASS GlutPrimitiveNode
49 //
50 //=============================================================================
51 
52 
53 #ifndef ACG_GLUT_PRIMITIVE_NODE_HH
54 #define ACG_GLUT_PRIMITIVE_NODE_HH
55 
56 
57 //== INCLUDES =================================================================
58 
59 
60 #include "BaseNode.hh"
61 #include "DrawModes.hh"
62 #include <string>
63 
64 #include <ACG/GL/GLPrimitives.hh>
65 
66 
67 //== NAMESPACES ===============================================================
68 
69 namespace ACG {
70 namespace SceneGraph {
71 
72 
73 //== CLASS DEFINITION =========================================================
74 
75 
82 class ACGDLLEXPORT GlutPrimitiveNode : public BaseNode
83 {
84 
85 public:
86 
89  {
90  CONE=0,
91  CUBE,
92  DODECAHEDRON,
93  ICOSAHEDRON,
94  OCTAHEDRON,
95  SPHERE,
96  TETRAHEDRON,
97  TORUS
98  };
99 
100 
101  struct Primitive
102  {
103  Vec3d position; // position
104  Vec3d axis; // direction / axis vector
105 
106  GlutPrimitiveType type; // glut primitive type
107 
108  ACG::Vec4f color; // color
109 
110  // glut primitive resolution
111  double size;
112  double innersize; // size of inner loop for torus, height for cone
113  unsigned int slices, stacks;
114 
115  // Constructor
116  explicit Primitive(GlutPrimitiveType _t) :
117 
118  // default axis is negative z
119  axis(Vec3d(0,0,1)),
120 
121  // Set the type
122  type(_t),
123 
124  // set default resolution
125  size(1.0),
126  innersize(1.0),
127  slices(20),
128  stacks(20)
129  {
130  }
131 
133  position(_p),
134  axis(_a),
135  type(_t),
136  color(_c),
137 
138  // set default resolution
139  size(1.0),
140  innersize(1.0),
141  slices(20),
142  stacks(20)
143  {
144 
145  }
146 
147  // Copy Constructor
148  Primitive( const Primitive& _p)
149  {
150  // use defined = operator
151  *this = _p;
152  }
153 
154  // = operator
155  Primitive& operator=(const Primitive& _p)
156  {
157  type = _p.type;
158  position = _p.position;
159  axis = _p.axis;
160  color = _p.color;
161  size = _p.size;
162  innersize = _p.innersize;
163  slices = _p.slices;
164  stacks = _p.stacks;
165 
166  return *this;
167  }
168  };
169 
170 
171  GlutPrimitiveNode( BaseNode* _parent=0,
172  const std::string & _name="<GlutPrimitive>" );
173 
174 
176  BaseNode* _parent=0,
177  const std::string & _name="<GlutPrimitive>" );
178 
179 
181  virtual ~GlutPrimitiveNode() {
182  if(sphere_)
183  delete sphere_;
184  if(cone_)
185  delete cone_;
186  }
187 
193  size_t add_primitive(GlutPrimitiveType _type, Vec3d _pos, Vec3d _axis, ACG::Vec4f _color);
194 
195  void clear(){primitives_.clear();};
196 
198  void set_position(const Vec3d& _p, int _idx = 0);
200  const Vec3d get_position(int _idx = 0) const;
201 
203  Primitive& get_primitive(int _idx){return primitives_[_idx];};
204 
206  void set_size(double _s, int _idx = 0);
208  double get_size(int _idx = 0) const;
209 
210  ACG_CLASSNAME(GlutPrimitiveNode);
211 
213  DrawModes::DrawMode availableDrawModes() const override;
214 
216  void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax) override;
217 
219  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode) override;
220  void draw_obj(GLState& _state, size_t _idx) const;
221 
223  void pick(GLState& _state, PickTarget _target) override;
224 
230  void setColorInternal(bool _set) { setColor_ = _set; };
231 
239  void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat) override;
240 
241 private:
242 
243  std::vector<Primitive> primitives_;
244 
245  bool setColor_;
246 
247  // Sphere rendering
248  ACG::GLSphere* sphere_;
249  ACG::GLCone* cone_;
250 
251 };
252 
253 
254 //=============================================================================
255 } // namespace SceneGraph
256 } // namespace ACG
257 //=============================================================================
258 #endif // ACG_GLUT_PRIMITIVE_NODE_HH
259 //=============================================================================
Namespace providing different geometric functions concerning angles.
void setColorInternal(bool _set)
Disable internal color processing.
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
GlutPrimitiveType
Lists all available primivites.
Primitive & get_primitive(int _idx)
get a primitive
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121