OGLplus (0.52.0) a C++ wrapper for OpenGL

tetrahedrons.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_SHAPES_TETRAHEDRONS_1201311347_HPP
14 #define OGLPLUS_SHAPES_TETRAHEDRONS_1201311347_HPP
15 
16 #include <oglplus/shapes/draw.hpp>
17 #include <oglplus/face_mode.hpp>
18 
20 
21 #include <oglplus/math/sphere.hpp>
22 #include <cmath>
23 #include <cassert>
24 
25 namespace oglplus {
26 namespace shapes {
27 
30  : public DrawingInstructionWriter
31  , public DrawMode
32 {
33 private:
34  GLdouble _side;
35  unsigned _divisions;
36 public:
39  : _side(1.0)
40  , _divisions(10)
41  { }
42 
44  Tetrahedrons(GLdouble side, unsigned divisions)
45  : _side(side)
46  , _divisions(divisions)
47  {
48  assert(_side > 0.0);
49  assert(divisions > 0);
50  }
51 
54  {
55  return FaceOrientation::CW;
56  }
57 
59  template <typename T>
60  GLuint Positions(std::vector<T>& dest) const
61  {
62  const unsigned n = _divisions + 1;
63  unsigned k = 0;
64  dest.resize(n*n*n*3+3);
65 
66  dest[k++] = T(0);
67  dest[k++] = T(0);
68  dest[k++] = T(0);
69 
70  GLdouble step = _side / _divisions;
71  //
72  for(unsigned z=0; z!=n; ++z)
73  for(unsigned y=0; y!=n; ++y)
74  for(unsigned x=0; x!=n; ++x)
75  {
76  dest[k++] = T(x*step);
77  dest[k++] = T(y*step);
78  dest[k++] = T(z*step);
79  }
80  assert(k == dest.size());
81  return 3;
82  }
83 
85  template <typename T>
86  GLuint TexCoordinates(std::vector<T>& dest) const
87  {
88  const unsigned n = _divisions + 1;
89  unsigned k = 0;
90  dest.resize(n*n*n*3+3);
91 
92  dest[k++] = T(0);
93  dest[k++] = T(0);
94  dest[k++] = T(0);
95 
96  GLdouble step = 1.0 / _divisions;
97  //
98  for(unsigned z=0; z!=n; ++z)
99  for(unsigned y=0; y!=n; ++y)
100  for(unsigned x=0; x!=n; ++x)
101  {
102  dest[k++] = T(x*step);
103  dest[k++] = T(y*step);
104  dest[k++] = T(z*step);
105  }
106  assert(k == dest.size());
107  return 3;
108  }
109 
110 #if OGLPLUS_DOCUMENTATION_ONLY
111 
117  typedef VertexAttribsInfo<Tetrahedrons> VertexAttribs;
118 #else
119  typedef VertexAttribsInfo<
120  Tetrahedrons,
121  std::tuple<
122  VertexPositionsTag,
123  VertexTexCoordinatesTag
124  >
125  > VertexAttribs;
126 #endif
127 
128  // This is here just for consistency with Shape wrapper
129  template <typename T>
130  void BoundingSphere(oglplus::Sphere<T>&) const
131  {
132  }
133 
135  typedef std::vector<GLuint> IndexArray;
136 
138  IndexArray Indices(WithAdjacency = WithAdjacency()) const;
139 
141  DrawingInstructions Instructions(WithAdjacency = WithAdjacency()) const;
142 };
143 
144 } // shapes
145 } // oglplus
146 
147 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
148 #include <oglplus/shapes/tetrahedrons.ipp>
149 #endif //OGLPLUS_LINK_LIBRARY
150 
151 #endif // include guard
Implementation of shape draw instructions.
IndexArray Indices(WithAdjacency=WithAdjacency()) const
Returns element indices that are used with the drawing instructions.
Sphere utility class.
FaceOrientation
Face orientation enumeration.
Definition: face_mode.hpp:62
OpenGL face type-related enumeration.
GLuint Positions(std::vector< T > &dest) const
Makes vertex coordinates and returns number of values per vertex.
Definition: tetrahedrons.hpp:60
GLuint TexCoordinates(std::vector< T > &dest) const
Makes texture coorinates and returns number of values per vertex.
Definition: tetrahedrons.hpp:86
Tetrahedrons(void)
Makes a unit sized tetrahedra filled cube with 10 divisions.
Definition: tetrahedrons.hpp:38
std::vector< GLuint > IndexArray
The type of index container returned by Indices()
Definition: tetrahedrons.hpp:135
Provides data and instructions for rendering of cube filling tetrahedrons.
Definition: tetrahedrons.hpp:29
FaceOrientation FaceWinding(void) const
Returns the winding direction of faces.
Definition: tetrahedrons.hpp:53
Tetrahedrons(GLdouble side, unsigned divisions)
Makes a cube with the specified side and number of divisions.
Definition: tetrahedrons.hpp:44
Classes providing additional information about the shape builders.
Class encapsulating the instructions for drawing of a shape.
Definition: draw.hpp:219
DrawingInstructions Instructions(WithAdjacency=WithAdjacency()) const
Returns the instructions for rendering.
Class implementing sphere-related functionality.
Definition: sphere.hpp:29
VertexAttribsInfo< Tetrahedrons > VertexAttribs
Vertex attribute information for this shape builder.
Definition: tetrahedrons.hpp:117

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).