OGLplus (0.52.0) a C++ wrapper for OpenGL

twisted_torus.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_SHAPES_TWISTED_TORUS_1201021336_HPP
14 #define OGLPLUS_SHAPES_TWISTED_TORUS_1201021336_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 GLdouble _radius_out, _radius_in, _thickness;
34  const GLdouble _r_slip_coef, _s_slip_coef;
35  const unsigned _sections, _rings, _twist;
36 public:
39  : _radius_out(1.0)
40  , _radius_in(0.5)
41  , _thickness(0.02)
42  , _r_slip_coef(0.25)
43  , _s_slip_coef(0.20)
44  , _sections(12)
45  , _rings(48)
46  , _twist(12)
47  { }
48 
51  GLdouble rad_out,
52  GLdouble rad_in,
53  GLdouble thickness,
54  unsigned sects,
55  unsigned rings,
56  unsigned twist
57  ): _radius_out(rad_out)
58  , _radius_in(rad_in)
59  , _thickness(thickness)
60  , _r_slip_coef(0.25)
61  , _s_slip_coef(0.20)
62  , _sections(sects)
63  , _rings(rings)
64  , _twist(twist)
65  {
66  assert(_sections % 2 == 0);
67  assert(_rings % 2 == 0);
68  assert(_thickness > 0.0);
69  assert(_thickness < _radius_in);
70  assert(_radius_in < _radius_out);
71  }
72 
75  {
76  return FaceOrientation::CW;
77  }
78 
79  std::vector<GLfloat> _positions(void) const;
80 
81  GLuint Positions(std::vector<GLfloat>& dest) const
82  {
83  dest = _positions();
84  return 3;
85  }
86 
88  template <typename T>
89  GLuint Positions(std::vector<T>& dest) const
90  {
91  auto v = _positions();
92  dest.assign(v.begin(), v.end());
93  return 3;
94  }
95 
96  std::vector<GLfloat> _normals(void) const;
97 
98  GLuint Normals(std::vector<GLfloat>& dest) const
99  {
100  dest = _normals();
101  return 3;
102  }
103 
105  template <typename T>
106  GLuint Normals(std::vector<T>& dest) const
107  {
108  auto v = _normals();
109  dest.assign(v.begin(), v.end());
110  return 3;
111  }
112 
113  std::vector<GLfloat> _tangents(void) const;
114 
115  GLuint Tangents(std::vector<GLfloat>& dest) const
116  {
117  dest = _tangents();
118  return 3;
119  }
120 
122  template <typename T>
123  GLuint Tangents(std::vector<T>& dest) const
124  {
125  auto v = _tangents();
126  dest.assign(v.begin(), v.end());
127  return 3;
128  }
129 
130  std::vector<GLfloat> _bitangents(void) const;
131 
132  GLuint Bitangents(std::vector<GLfloat>& dest) const
133  {
134  dest = _bitangents();
135  return 3;
136  }
137 
139  template <typename T>
140  GLuint Bitangents(std::vector<T>& dest) const
141  {
142  auto v = _bitangents();
143  dest.assign(v.begin(), v.end());
144  return 3;
145  }
146 
147  std::vector<GLfloat> _tex_coords(void) const;
148 
149  GLuint TexCoordinates(std::vector<GLfloat>& dest) const
150  {
151  dest = _tex_coords();
152  return 2;
153  }
154 
156  template <typename T>
157  GLuint TexCoordinates(std::vector<T>& dest) const
158  {
159  auto v = _tex_coords();
160  dest.assign(v.begin(), v.end());
161  return 2;
162  }
163 
164 #if OGLPLUS_DOCUMENTATION_ONLY
165 
174  typedef VertexAttribsInfo<TwistedTorus> VertexAttribs;
175 #else
176  typedef VertexAttribsInfo<
177  TwistedTorus,
178  std::tuple<
179  VertexPositionsTag,
180  VertexNormalsTag,
181  VertexTangentsTag,
182  VertexBitangentsTag,
183  VertexTexCoordinatesTag
184  >
185  > VertexAttribs;
186 #endif
187 
189  template <typename T>
190  void BoundingSphere(oglplus::Sphere<T>& bounding_sphere) const
191  {
192  bounding_sphere = oglplus::Sphere<T>(
193  T(0),
194  T(0),
195  T(0),
196  T(_radius_out + _thickness)
197  );
198  }
199 
201  typedef std::vector<GLuint> IndexArray;
202 
204  IndexArray Indices(Default = Default()) const
205  {
206  return IndexArray();
207  }
208 
210  DrawingInstructions Instructions(Default = Default()) const;
211 };
212 
213 } // shapes
214 } // oglplus
215 
216 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
217 #include <oglplus/shapes/twisted_torus.ipp>
218 #endif // OGLPLUS_LINK_LIBRARY
219 
220 #endif // include guard
Implementation of shape draw instructions.
IndexArray Indices(Default=Default()) const
Returns element indices that are used with the drawing instructions.
Definition: twisted_torus.hpp:204
void BoundingSphere(oglplus::Sphere< T > &bounding_sphere) const
Queries the bounding sphere coordinates and dimensions.
Definition: twisted_torus.hpp:190
Sphere utility class.
DrawingInstructions Instructions(Default=Default()) const
Returns the instructions for rendering.
TwistedTorus(GLdouble rad_out, GLdouble rad_in, GLdouble thickness, unsigned sects, unsigned rings, unsigned twist)
Creates a torus with unit radius centered at the origin.
Definition: twisted_torus.hpp:50
GLuint Normals(std::vector< T > &dest) const
Makes vertex normals and returns number of values per vertex.
Definition: twisted_torus.hpp:106
FaceOrientation FaceWinding(void) const
Returns the winding direction of faces.
Definition: twisted_torus.hpp:74
FaceOrientation
Face orientation enumeration.
Definition: face_mode.hpp:62
GLuint Positions(std::vector< T > &dest) const
Makes vertex coordinates and returns number of values per vertex.
Definition: twisted_torus.hpp:89
OpenGL face type-related enumeration.
GLuint Tangents(std::vector< T > &dest) const
Makes vertex tangents and returns number of values per vertex.
Definition: twisted_torus.hpp:123
VertexAttribsInfo< TwistedTorus > VertexAttribs
Vertex attribute information for this shape builder.
Definition: twisted_torus.hpp:174
std::vector< GLuint > IndexArray
The type of index container returned by Indices()
Definition: twisted_torus.hpp:201
TwistedTorus(void)
Creates a torus with unit radius centered at the origin.
Definition: twisted_torus.hpp:38
Classes providing additional information about the shape builders.
Math constants.
GLuint TexCoordinates(std::vector< T > &dest) const
Makes texture coorinates and returns number of values per vertex.
Definition: twisted_torus.hpp:157
Class encapsulating the instructions for drawing of a shape.
Definition: draw.hpp:219
Class implementing sphere-related functionality.
Definition: sphere.hpp:29
GLuint Bitangents(std::vector< T > &dest) const
Makes vertex bi-tangents and returns number of values per vertex.
Definition: twisted_torus.hpp:140
Class providing vertex attributes and instructions for rendering of a Torus.
Definition: twisted_torus.hpp:28

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