OGLplus (0.52.0) a C++ wrapper for OpenGL

subdiv_sphere.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_SHAPES_SUBDIV_SPHERE_1309171555_HPP
14 #define OGLPLUS_SHAPES_SUBDIV_SPHERE_1309171555_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 #include <map>
24 
25 namespace oglplus {
26 namespace shapes {
27 
28 OGLPLUS_ENUM_CLASS_BEGIN(SubdivSphereInitialShape, GLuint)
29  OGLPLUS_ENUM_CLASS_VALUE(Icosahedron, 0)
30  OGLPLUS_ENUM_CLASS_COMMA
31  OGLPLUS_ENUM_CLASS_VALUE(Octohedron, 1)
32  OGLPLUS_ENUM_CLASS_COMMA
33  OGLPLUS_ENUM_CLASS_VALUE(Tetrahedron, 2)
34 OGLPLUS_ENUM_CLASS_END(SubdivSphereInitialShape)
35 
38  : public DrawingInstructionWriter
39  , public DrawMode
40 {
41 private:
42  GLuint _subdivs;
43  std::vector<GLdouble> _positions;
44  std::vector<GLuint> _indices;
45 
46  typedef std::pair<GLuint, GLuint> _edge;
47  std::map<_edge, GLuint> _midpoints;
48 
49  GLuint _midpoint(GLuint ia, GLuint ib);
50  void _subdivide(GLuint ia, GLuint ib, GLuint ic, GLuint levels);
51  void _make_face(GLuint ia, GLuint ib, GLuint ic, GLuint levels);
52 
53  void _init_icosah(void);
54  void _init_tetrah(void);
55  void _init_octoh(void);
56 public:
57  typedef SubdivSphereInitialShape InitialShape;
58 
59  SimpleSubdivSphere(void)
60  : _subdivs(2)
61  {
62  _init_icosah();
63  }
64 
65  SimpleSubdivSphere(GLuint subdivs)
66  : _subdivs(subdivs)
67  {
68  _init_icosah();
69  }
70 
71  SimpleSubdivSphere(GLuint subdivs, InitialShape init_shape);
72 
75  {
76  return FaceOrientation::CCW;
77  }
78 
79  typedef GLuint (SimpleSubdivSphere::*VertexAttribFunc)(std::vector<GLfloat>&) const;
80 
82  template <typename T>
83  GLuint Positions(std::vector<T>& dest) const
84  {
85  dest.assign(_positions.begin(), _positions.end());
86  return 3;
87  }
88 
89 #if OGLPLUS_DOCUMENTATION_ONLY
90 
95  typedef VertexAttribsInfo<SubdivSphere> VertexAttribs;
96 #else
97  typedef VertexAttribsInfo<
99  std::tuple<VertexPositionsTag>
100  > VertexAttribs;
101 #endif
102 
104  template <typename T>
105  void BoundingSphere(oglplus::Sphere<T>& bounding_sphere) const
106  {
107  bounding_sphere = oglplus::Sphere<T>(T(0), T(0), T(0), T(1));
108  }
109 
111  typedef std::vector<GLuint> IndexArray;
112 
114  IndexArray Indices(Default = Default()) const
115  {
116  return IndexArray(_indices.begin(), _indices.end());
117  }
118 
119  DrawingInstructions Instructions(PrimitiveType mode) const;
120 
123  {
124  return Instructions(PrimitiveType::Triangles);
125  }
126 };
127 
128 } // shapes
129 } // oglplus
130 
131 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
132 #include <oglplus/shapes/subdiv_sphere.ipp>
133 #endif // OGLPLUS_LINK_LIBRARY
134 
135 #endif // include guard
Implementation of shape draw instructions.
VertexAttribsInfo< SubdivSphere > VertexAttribs
Vertex attribute information for this shape builder.
Definition: subdiv_sphere.hpp:95
PrimitiveType
Primitive type enumeration.
Definition: primitive_type.hpp:29
Sphere utility class.
FaceOrientation FaceWinding(void) const
Returns the winding direction of faces.
Definition: subdiv_sphere.hpp:74
void BoundingSphere(oglplus::Sphere< T > &bounding_sphere) const
Queries the bounding sphere coordinates and dimensions.
Definition: subdiv_sphere.hpp:105
FaceOrientation
Face orientation enumeration.
Definition: face_mode.hpp:62
OpenGL face type-related enumeration.
Class providing vertex attributes and instructions for drawing of a sphere.
Definition: subdiv_sphere.hpp:37
DrawingInstructions Instructions(Default=Default()) const
Returns the instructions for rendering of faces.
Definition: subdiv_sphere.hpp:122
Classes providing additional information about the shape builders.
std::vector< GLuint > IndexArray
The type of the index container returned by Indices()
Definition: subdiv_sphere.hpp:111
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.
GLuint Positions(std::vector< T > &dest) const
Makes the positions and returns the number of values per vertex.
Definition: subdiv_sphere.hpp:83
IndexArray Indices(Default=Default()) const
Returns element indices that are used with the drawing instructions.
Definition: subdiv_sphere.hpp:114
A vector 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).