OGLplus (0.52.0) a C++ wrapper for OpenGL

spiral_sphere.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_SHAPES_SPIRAL_SPHERE_1107121519_HPP
14 #define OGLPLUS_SHAPES_SPIRAL_SPHERE_1107121519_HPP
15 
16 #include <oglplus/shapes/draw.hpp>
17 #include <oglplus/face_mode.hpp>
18 
20 
22 #include <oglplus/math/sphere.hpp>
23 
24 namespace oglplus {
25 namespace shapes {
26 
29  : public DrawingInstructionWriter
30  , public DrawMode
31 {
32 private:
33  const double _radius, _thickness;
34  const unsigned _bands, _divisions, _segments;
35 
36  unsigned _vertex_count(void) const;
37 
38  template <typename T>
39  void _make_vectors(
40  std::vector<T>& dest,
41  unsigned& k,
42  double sign,
43  double radius
44  ) const;
45 
46  template <typename T>
47  void _make_tangents(
48  std::vector<T>& dest,
49  unsigned& k,
50  double sign
51  ) const;
52 
53  template <typename T>
54  void _make_bitangents(
55  std::vector<T>& dest,
56  unsigned& k,
57  double sign
58  ) const;
59 
60  template <typename T>
61  void _make_uv_coords(std::vector<T>& dest, unsigned& k) const;
62 
63  template <typename T>
64  void _make_side_verts(std::vector<T>& dest, unsigned& k) const;
65 
66  template <typename T>
67  void _make_side_norms(std::vector<T>& dest, unsigned& k) const;
68 
69  template <typename T>
70  void _make_side_tgts(std::vector<T>& dest, unsigned& k) const;
71 
72  template <typename T>
73  void _make_side_btgs(std::vector<T>& dest, unsigned& k) const;
74 
75  template <typename T>
76  void _make_side_uvs(std::vector<T>& dest, unsigned& k) const;
77 public:
80  : _radius(1.0)
81  , _thickness(0.1)
82  , _bands(4)
83  , _divisions(8)
84  , _segments(48)
85  { }
86 
89  double radius,
90  double thickness,
91  unsigned bands,
92  unsigned divisions,
93  unsigned segments
94  ): _radius(radius)
95  , _thickness(thickness)
96  , _bands(bands)
97  , _divisions(divisions)
98  , _segments(segments)
99  { }
100 
103  {
104  return FaceOrientation::CCW;
105  }
106 
107  std::vector<GLfloat> _positions(void) const;
108 
109  GLuint Positions(std::vector<GLfloat>& dest) const
110  {
111  dest = _positions();
112  return 3;
113  }
114 
116  template <typename T>
117  GLuint Positions(std::vector<T>& dest) const
118  {
119  auto v = _positions();
120  dest.assign(v.begin(), v.end());
121  return 3;
122  }
123 
124  std::vector<GLfloat> _normals(void) const;
125 
126  GLuint Normals(std::vector<GLfloat>& dest) const
127  {
128  dest = _normals();
129  return 3;
130  }
131 
133  template <typename T>
134  GLuint Normals(std::vector<T>& dest) const
135  {
136  auto v = _normals();
137  dest.assign(v.begin(), v.end());
138  return 3;
139  }
140 
141  std::vector<GLfloat> _tangents(void) const;
142 
143  GLuint Tangents(std::vector<GLfloat>& dest) const
144  {
145  dest = _tangents();
146  return 3;
147  }
148 
150  template <typename T>
151  GLuint Tangents(std::vector<T>& dest) const
152  {
153  auto v = _tangents();
154  dest.assign(v.begin(), v.end());
155  return 3;
156  }
157 
158  std::vector<GLfloat> _bitangents(void) const;
159 
160  GLuint Bitangents(std::vector<GLfloat>& dest) const
161  {
162  dest = _bitangents();
163  return 3;
164  }
165 
167  template <typename T>
168  GLuint Bitangents(std::vector<T>& dest) const
169  {
170  auto v = _bitangents();
171  dest.assign(v.begin(), v.end());
172  return 3;
173  }
174 
175  std::vector<GLfloat> _tex_coords(void) const;
176 
177  GLuint TexCoordinates(std::vector<GLfloat>& dest) const
178  {
179  dest = _tex_coords();
180  return 2;
181  }
182 
184  template <typename T>
185  GLuint TexCoordinates(std::vector<T>& dest) const
186  {
187  auto v = _tex_coords();
188  dest.assign(v.begin(), v.end());
189  return 2;
190  }
191 
192 #if OGLPLUS_DOCUMENTATION_ONLY
193 
202  typedef VertexAttribsInfo<SpiralSphere> VertexAttribs;
203 #else
204  typedef VertexAttribsInfo<
205  SpiralSphere,
206  std::tuple<
207  VertexPositionsTag,
208  VertexNormalsTag,
209  VertexTangentsTag,
210  VertexBitangentsTag,
211  VertexTexCoordinatesTag
212  >
213  > VertexAttribs;
214 #endif
215 
217  template <typename T>
218  void BoundingSphere(oglplus::Sphere<T>& bounding_sphere) const
219  {
220  bounding_sphere = oglplus::Sphere<T>(
221  T(0),
222  T(0),
223  T(0),
224  T(_radius + _thickness)
225  );
226  }
227 
229  typedef std::vector<GLushort> IndexArray;
230 
232  IndexArray Indices(Default = Default()) const;
233 
235  DrawingInstructions Instructions(Default = Default()) const;
236 };
237 
238 } // shapes
239 } // oglplus
240 
241 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
242 #include <oglplus/shapes/spiral_sphere.ipp>
243 #endif //OGLPLUS_LINK_LIBRARY
244 
245 #endif // include guard
Implementation of shape draw instructions.
GLuint Normals(std::vector< T > &dest) const
Makes vertex normals and returns number of values per vertex.
Definition: spiral_sphere.hpp:134
IndexArray Indices(Default=Default()) const
Returns element indices that are used with the drawing instructions.
FaceOrientation FaceWinding(void) const
Returns the winding direction of faces.
Definition: spiral_sphere.hpp:102
GLuint Tangents(std::vector< T > &dest) const
Makes vertex tangents and returns number of values per vertex.
Definition: spiral_sphere.hpp:151
std::vector< GLushort > IndexArray
The type of index container returned by Indices()
Definition: spiral_sphere.hpp:229
GLuint Positions(std::vector< T > &dest) const
Makes vertex coordinates and returns number of values per vertex.
Definition: spiral_sphere.hpp:117
Sphere utility class.
Class providing data and instructions for rendering of a "spiral sphere".
Definition: spiral_sphere.hpp:28
SpiralSphere(double radius, double thickness, unsigned bands, unsigned divisions, unsigned segments)
Creates a custom spiral sphere.
Definition: spiral_sphere.hpp:88
GLuint TexCoordinates(std::vector< T > &dest) const
Makes texture-coorinates and returns number of values per vertex.
Definition: spiral_sphere.hpp:185
FaceOrientation
Face orientation enumeration.
Definition: face_mode.hpp:62
OpenGL face type-related enumeration.
GLuint Bitangents(std::vector< T > &dest) const
Makes vertex bi-tangents and returns number of values per vertex.
Definition: spiral_sphere.hpp:168
VertexAttribsInfo< SpiralSphere > VertexAttribs
Vertex attribute information for this shape builder.
Definition: spiral_sphere.hpp:202
Classes providing additional information about the shape builders.
Math constants.
SpiralSphere(void)
Creates a default spiral sphere.
Definition: spiral_sphere.hpp:79
Class encapsulating the instructions for drawing of a shape.
Definition: draw.hpp:219
Class implementing sphere-related functionality.
Definition: sphere.hpp:29
CCW: Counter-clockwise.
void BoundingSphere(oglplus::Sphere< T > &bounding_sphere) const
Queries the bounding sphere coordinates and dimensions.
Definition: spiral_sphere.hpp:218
DrawingInstructions Instructions(Default=Default()) const
Returns the instructions for rendering.

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