OGLplus (0.52.0) a C++ wrapper for OpenGL

icosahedron.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_SHAPES_ICOSAHEDRON_1206011111_HPP
14 #define OGLPLUS_SHAPES_ICOSAHEDRON_1206011111_HPP
15 
16 #include <oglplus/face_mode.hpp>
17 #include <oglplus/shapes/draw.hpp>
18 
20 #include <oglplus/math/vector.hpp>
21 #include <oglplus/math/sphere.hpp>
22 
23 namespace oglplus {
24 namespace shapes {
25 
26 class IcosahedronBase
27 {
28 protected:
29  static const GLushort* _indices(void);
30  static const GLdouble* _positions(void);
31 };
32 
35  : public DrawingInstructionWriter
36  , public DrawMode
37  , public IcosahedronBase
38 {
39 public:
42  {
43  return FaceOrientation::CCW;
44  }
45 
46  typedef GLuint (SimpleIcosahedron::*VertexAttribFunc)(std::vector<GLfloat>&) const;
47 
49  template <typename T>
50  GLuint Positions(std::vector<T>& dest) const
51  {
52  const GLdouble* p = _positions();
53  dest.assign(p, p+12*3);
54  return 3;
55  }
56 
57 #if OGLPLUS_DOCUMENTATION_ONLY
58 
63  typedef VertexAttribsInfo<Icosahedron> VertexAttribs;
64 #else
65  typedef VertexAttribsInfo<
67  std::tuple<VertexPositionsTag>
68  > VertexAttribs;
69 #endif
70 
72  template <typename T>
73  void BoundingSphere(oglplus::Sphere<T>& bounding_sphere) const
74  {
75  bounding_sphere = oglplus::Sphere<T>(T(0), T(0), T(0), T(1));
76  }
77 
79  typedef std::vector<GLushort> IndexArray;
80 
82  IndexArray Indices(Default = Default()) const
83  {
84  const GLushort* i = _indices();
85  return IndexArray(i, i+20*3);
86  }
87 
88  DrawingInstructions Instructions(PrimitiveType mode) const;
89 
92  {
93  return Instructions(PrimitiveType::Triangles);
94  }
95 };
96 
99  : public DrawingInstructionWriter
100  , public DrawMode
101  , public IcosahedronBase
102 {
103 public:
106  {
107  return FaceOrientation::CW;
108  }
109 
110  typedef GLuint (Icosahedron::*VertexAttribFunc)(std::vector<GLfloat>&) const;
111 
113  template <typename T>
114  GLuint Positions(std::vector<T>& dest) const
115  {
116  dest.resize(20*3*3);
117 
118  const GLdouble* p = _positions();
119  const GLushort* i = _indices();
120 
121  for(GLuint f=0; f!=20; ++f)
122  {
123  for(GLuint v=0; v!=3; ++v)
124  {
125  for(GLuint c=0; c!=3; ++c)
126  {
127  dest[f*9+v*3+c] = p[i[f*3+v]*3+c];
128  }
129  }
130  }
131  return 3;
132  }
133 
135  template <typename T>
136  GLuint Normals(std::vector<T>& dest) const
137  {
138  dest.resize(20*3*3);
139 
140  const GLdouble* p = _positions();
141  const GLushort* i = _indices();
142 
143  for(GLuint f=0; f!=20; ++f)
144  {
145  Vector<T, 3> v0(
146  p[i[f*3+0]*3+0],
147  p[i[f*3+0]*3+1],
148  p[i[f*3+0]*3+2]
149  );
150  Vector<T, 3> v1(
151  p[i[f*3+1]*3+0],
152  p[i[f*3+1]*3+1],
153  p[i[f*3+1]*3+2]
154  );
155  Vector<T, 3> v2(
156  p[i[f*3+2]*3+0],
157  p[i[f*3+2]*3+1],
158  p[i[f*3+2]*3+2]
159  );
160  Vector<T, 3> fn(Normalized(Cross(v1-v0, v2-v0)));
161 
162  for(GLuint v=0; v!=3; ++v)
163  {
164  for(GLuint c=0; c!=3; ++c)
165  {
166  dest[f*9+v*3+c] = fn[c];
167  }
168  }
169  }
170  return 3;
171  }
172 
173 #if OGLPLUS_DOCUMENTATION_ONLY
174 
180  typedef VertexAttribsInfo<Icosahedron> VertexAttribs;
181 #else
182  typedef VertexAttribsInfo<
183  Icosahedron,
184  std::tuple<
185  VertexPositionsTag,
186  VertexNormalsTag
187  >
188  > VertexAttribs;
189 #endif
190 
192  template <typename T>
193  void BoundingSphere(Sphere<T>& center_and_radius) const
194  {
195  center_and_radius = Sphere<T>(T(0), T(0), T(0), T(1));
196  }
197 
199  typedef std::vector<GLushort> IndexArray;
200 
202  IndexArray Indices(Default = Default()) const
203  {
204  return IndexArray();
205  }
206 
207  DrawingInstructions Instructions(PrimitiveType mode) const;
208 
211  {
212  return Instructions(PrimitiveType::Triangles);
213  }
214 };
215 
216 } // shapes
217 } // oglplus
218 
219 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
220 #include <oglplus/shapes/icosahedron.ipp>
221 #endif // OGLPLUS_LINK_LIBRARY
222 
223 #endif // include guard
Implementation of shape draw instructions.
Definition: vector.hpp:14
GLuint Positions(std::vector< T > &dest) const
Makes the positions and returns the number of values per vertex.
Definition: icosahedron.hpp:114
IndexArray Indices(Default=Default()) const
Returns element indices that are used with the drawing instructions.
Definition: icosahedron.hpp:82
VertexAttribsInfo< Icosahedron > VertexAttribs
Vertex attribute information for this shape builder.
Definition: icosahedron.hpp:63
FaceOrientation FaceWinding(void) const
Returns the winding direction of faces.
Definition: icosahedron.hpp:41
FaceOrientation FaceWinding(void) const
Returns the winding direction of faces.
Definition: icosahedron.hpp:105
PrimitiveType
Primitive type enumeration.
Definition: primitive_type.hpp:29
Sphere utility class.
void BoundingSphere(oglplus::Sphere< T > &bounding_sphere) const
Queries the bounding sphere coordinates and dimensions.
Definition: icosahedron.hpp:73
GLuint Normals(std::vector< T > &dest) const
Makes the normals and returns the number of values per vertex.
Definition: icosahedron.hpp:136
IndexArray Indices(Default=Default()) const
Returns element indices that are used with the drawing instructions.
Definition: icosahedron.hpp:202
FaceOrientation
Face orientation enumeration.
Definition: face_mode.hpp:62
OpenGL face type-related enumeration.
DrawingInstructions Instructions(Default=Default()) const
Returns the instructions for rendering of faces.
Definition: icosahedron.hpp:210
DrawingInstructions Instructions(Default=Default()) const
Returns the instructions for rendering of faces.
Definition: icosahedron.hpp:91
Class providing vertex attributes and instructions for drawing of a icosahedron.
Definition: icosahedron.hpp:98
std::vector< GLushort > IndexArray
The type of the index container returned by Indices()
Definition: icosahedron.hpp:199
Classes providing additional information about the shape builders.
GLuint Positions(std::vector< T > &dest) const
Makes the positions and returns the number of values per vertex.
Definition: icosahedron.hpp:50
Class encapsulating the instructions for drawing of a shape.
Definition: draw.hpp:219
Class implementing sphere-related functionality.
Definition: sphere.hpp:29
void BoundingSphere(Sphere< T > &center_and_radius) const
Queries the bounding sphere coordinates and dimensions.
Definition: icosahedron.hpp:193
CCW: Counter-clockwise.
Class providing vertex attributes and instructions for drawing of a icosahedron.
Definition: icosahedron.hpp:34
std::vector< GLushort > IndexArray
The type of the index container returned by Indices()
Definition: icosahedron.hpp:79
Class providing vertex attributes and instructions for rendering of a Sphere.
Definition: sphere.hpp:28
A vector class.
VertexAttribsInfo< Icosahedron > VertexAttribs
Vertex attribute information for this shape builder.
Definition: icosahedron.hpp:180

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