OGLplus (0.52.0) a C++ wrapper for OpenGL

cage.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_SHAPES_CAGE_1107121519_HPP
14 #define OGLPLUS_SHAPES_CAGE_1107121519_HPP
15 
16 #include <oglplus/face_mode.hpp>
17 #include <oglplus/shapes/draw.hpp>
18 
20 #include <oglplus/math/matrix.hpp>
21 #include <oglplus/math/sphere.hpp>
22 
23 namespace oglplus {
24 namespace shapes {
25 
27 class Cage
28  : public DrawingInstructionWriter
29  , public DrawMode
30 {
31 private:
32  Vector<GLdouble, 3> _size;
33  Vector<GLdouble, 3> _barw;
34  Vector<GLdouble, 3> _divs;
35 
36  static const Matrix<GLdouble, 3, 3>& _face_mat(GLuint face);
37 
38  GLdouble _face_size(GLuint face, GLuint axis) const
39  {
40  return std::fabs(Dot(_face_mat(face).Row(axis), _size));
41  }
42 
43  GLdouble _face_barw(GLuint face, GLuint axis) const
44  {
45  return std::fabs(Dot(_face_mat(face).Row(axis), _barw));
46  }
47 
48  GLuint _face_divs(GLuint face, GLuint axis) const
49  {
50  return GLuint(std::fabs(Dot(_face_mat(face).Row(axis), _divs)));
51  }
52 
53  static const Vector<GLdouble, 3> _face_vec(
54  GLuint face,
55  const Vector<GLdouble, 3> vec
56  )
57  {
58  return _face_mat(face)*vec;
59  }
60 
61  template <typename Iter>
62  static Iter _write(Iter iter, const Vector<GLdouble, 3>& vec)
63  {
64  *iter++ = vec.x();
65  *iter++ = vec.y();
66  *iter++ = vec.z();
67  return iter;
68  }
69 
70  GLuint _vert_count(void) const;
71 
72  // primitive-restart-index
73  GLuint _pri(void) const { return _vert_count(); }
74 
75  GLuint _index_count(void) const;
76 public:
78  Cage(void)
79  : _size(1, 1, 1)
80  , _barw(0.15, 0.15, 0.15)
81  , _divs(4, 4, 4)
82  { }
83 
86  GLdouble xs, GLdouble ys, GLdouble zs,
87  GLdouble xb, GLdouble yb, GLdouble zb,
88  GLuint xd, GLuint yd, GLuint zd
89  ): _size(xs, ys, zs)
90  , _barw(xb, yb, zb)
91  , _divs(xd, yd, zd)
92  {
93  assert(xs > 0.0);
94  assert(ys > 0.0);
95  assert(zs > 0.0);
96 
97  assert(xd > 0);
98  assert(yd > 0);
99  assert(zd > 0);
100 
101  assert(xs > xb*(xd-1));
102  assert(ys > yb*(yd-1));
103  assert(zs > zb*(zd-1));
104  }
105 
108  {
109  return FaceOrientation::CW;
110  }
111 
112  typedef GLuint (Cage::*VertexAttribFunc)(std::vector<GLfloat>&) const;
113 
114  std::vector<GLfloat> _positions(void) const;
115 
116  GLuint Positions(std::vector<GLfloat>& dest) const
117  {
118  dest = _positions();
119  return 3;
120  }
121 
123  template <typename T>
124  GLuint Positions(std::vector<T>& dest) const
125  {
126  auto p = _positions();
127  dest.assign(p.begin(), p.end());
128  return 3;
129  }
130 
131  std::vector<GLfloat> _normals(void) const;
132 
133  GLuint Normals(std::vector<GLfloat>& dest) const
134  {
135  dest = _normals();
136  return 3;
137  }
138 
140  template <typename T>
141  GLuint Normals(std::vector<T>& dest) const
142  {
143  auto n = _normals();
144  dest.assign(n.begin(), n.end());
145  return 3;
146  }
147 
148  std::vector<GLfloat> _tangents(void) const;
149 
150  GLuint Tangents(std::vector<GLfloat>& dest) const
151  {
152  dest = _tangents();
153  return 3;
154  }
155 
157  template <typename T>
158  GLuint Tangents(std::vector<T>& dest) const
159  {
160  auto t = _tangents();
161  dest.assign(t.begin(), t.end());
162  return 3;
163  }
164 
165  std::vector<GLfloat> _tex_coords(void) const;
166 
167  GLuint TexCoordinates(std::vector<GLfloat>& dest) const
168  {
169  dest = _tex_coords();
170  return 3;
171  }
172 
174  template <typename T>
175  GLuint TexCoordinates(std::vector<T>& dest) const
176  {
177  auto t = _tex_coords();
178  dest.assign(t.begin(), t.end());
179  return 3;
180  }
181 
182 #if OGLPLUS_DOCUMENTATION_ONLY
183 
191  typedef VertexAttribsInfo<Cage> VertexAttribs;
192 #else
193  typedef VertexAttribsInfo<
194  Cage,
195  std::tuple<
196  VertexPositionsTag,
197  VertexNormalsTag,
198  VertexTangentsTag,
199  VertexTexCoordinatesTag
200  >
201  > VertexAttribs;
202 #endif
203 
205  template <typename T>
206  void BoundingSphere(oglplus::Sphere<T>& bounding_sphere) const
207  {
208  bounding_sphere = oglplus::Sphere<T>(
209  T(0),
210  T(0),
211  T(0),
212  Length(_size)
213  );
214  }
215 
217  typedef std::vector<GLuint> IndexArray;
218 
220  IndexArray Indices(Default = Default()) const;
221 
223  DrawingInstructions Instructions(Default = Default()) const;
224 };
225 
226 } // shapes
227 } // oglplus
228 
229 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
230 #include <oglplus/shapes/cage.ipp>
231 #endif
232 
233 #endif // include guard
Implementation of shape draw instructions.
Class providing vertex attributes and instructions for rendering of a cage.
Definition: cage.hpp:27
GLuint TexCoordinates(std::vector< T > &dest) const
Makes the texture coordinates and returns the number of values per vertex.
Definition: cage.hpp:175
Sphere utility class.
DrawingInstructions Instructions(Default=Default()) const
Returns the instructions for rendering of faces.
IndexArray Indices(Default=Default()) const
Returns element indices that are used with the drawing instructions.
FaceOrientation
Face orientation enumeration.
Definition: face_mode.hpp:62
OpenGL face type-related enumeration.
T z(void) const
Returns the 2-nd component.
Definition: vector.hpp:237
FaceOrientation FaceWinding(void) const
Returns the winding direction of faces.
Definition: cage.hpp:107
void BoundingSphere(oglplus::Sphere< T > &bounding_sphere) const
Queries the bounding sphere coordinates and dimensions.
Definition: cage.hpp:206
T y(void) const
Returns the 1-st component.
Definition: vector.hpp:231
GLuint Normals(std::vector< T > &dest) const
Makes the normals and returns the number of values per vertex.
Definition: cage.hpp:141
GLuint Positions(std::vector< T > &dest) const
Makes the vertices and returns the number of values per vertex.
Definition: cage.hpp:124
VertexAttribsInfo< Cage > VertexAttribs
Vertex attribute information for this shape builder.
Definition: cage.hpp:191
std::vector< GLuint > IndexArray
The type of the index container returned by Indices()
Definition: cage.hpp:217
Base template for Matrix.
Definition: fwd.hpp:63
Classes providing additional information about the shape builders.
Cage(void)
Constructs a unit cage centered at the origin.
Definition: cage.hpp:78
Class encapsulating the instructions for drawing of a shape.
Definition: draw.hpp:219
Class implementing sphere-related functionality.
Definition: sphere.hpp:29
GLuint Tangents(std::vector< T > &dest) const
Makes the tangents and returns the number of values per vertex.
Definition: cage.hpp:158
Cage(GLdouble xs, GLdouble ys, GLdouble zs, GLdouble xb, GLdouble yb, GLdouble zb, GLuint xd, GLuint yd, GLuint zd)
Constructs a cage with width, height, depth.
Definition: cage.hpp:85
A matrix class.

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).