OGLplus (0.52.0) a C++ wrapper for OpenGL

cube.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_SHAPES_CUBE_1107121519_HPP
14 #define OGLPLUS_SHAPES_CUBE_1107121519_HPP
15 
16 #include <oglplus/face_mode.hpp>
17 #include <oglplus/shapes/draw.hpp>
18 
20 
21 #include <oglplus/math/sphere.hpp>
22 
23 #include <cmath>
24 
25 namespace oglplus {
26 namespace shapes {
27 
29 class Cube
30  : public DrawingInstructionWriter
31  , public DrawMode
32 {
33 private:
34  GLdouble _sx, _sy, _sz;
35  GLdouble _ox, _oy, _oz;
36 public:
38  Cube(void)
39  : _sx(1.0)
40  , _sy(1.0)
41  , _sz(1.0)
42  , _ox(0.0)
43  , _oy(0.0)
44  , _oz(0.0)
45  { }
46 
48  Cube(GLdouble w, GLdouble h, GLdouble d)
49  : _sx(w)
50  , _sy(h)
51  , _sz(d)
52  , _ox(0.0)
53  , _oy(0.0)
54  , _oz(0.0)
55  { }
56 
59  GLdouble w,
60  GLdouble h,
61  GLdouble d,
62  GLdouble x,
63  GLdouble y,
64  GLdouble z
65  ): _sx(w)
66  , _sy(h)
67  , _sz(d)
68  , _ox(x)
69  , _oy(y)
70  , _oz(z)
71  { }
72 
75  {
76  return FaceOrientation::CW;
77  }
78 
79  typedef GLuint (Cube::*VertexAttribFunc)(std::vector<GLfloat>&) const;
80 
81  std::vector<GLfloat> _positions(void) const;
82 
83  GLuint Positions(std::vector<GLfloat>& dest) const
84  {
85  dest = _positions();
86  return 3;
87  }
88 
90  template <typename T>
91  GLuint Positions(std::vector<T>& dest) const
92  {
93  auto v = _positions();
94  dest.assign(v.begin(), v.end());
95  return 3;
96  }
97 
98  std::vector<GLfloat> _normals(void) const;
99 
100  GLuint Normals(std::vector<GLfloat>& dest) const
101  {
102  dest = _normals();
103  return 3;
104  }
105 
107  template <typename T>
108  GLuint Normals(std::vector<T>& dest) const
109  {
110  auto v = _normals();
111  dest.assign(v.begin(), v.end());
112  return 3;
113  }
114 
115  std::vector<GLfloat> _tangents(void) const;
116 
117  GLuint Tangents(std::vector<GLfloat>& dest) const
118  {
119  dest = _tangents();
120  return 3;
121  }
122 
124  template <typename T>
125  GLuint Tangents(std::vector<T>& dest) const
126  {
127  auto v = _tangents();
128  dest.assign(v.begin(), v.end());
129  return 3;
130  }
131 
132  std::vector<GLfloat> _tex_coords(void) const;
133 
134  GLuint TexCoordinates(std::vector<GLfloat>& dest) const
135  {
136  dest = _tex_coords();
137  return 3;
138  }
139 
141  template <typename T>
142  GLuint TexCoordinates(std::vector<T>& dest) const
143  {
144  auto v = _tex_coords();
145  dest.assign(v.begin(), v.end());
146  return 3;
147  }
148 
149 #if OGLPLUS_DOCUMENTATION_ONLY
150 
158  typedef VertexAttribsInfo<Cube> VertexAttribs;
159 #else
160  typedef VertexAttribsInfo<
161  Cube,
162  std::tuple<
163  VertexPositionsTag,
164  VertexNormalsTag,
165  VertexTangentsTag,
166  VertexTexCoordinatesTag
167  >
168  > VertexAttribs;
169 #endif
170 
172  template <typename T>
173  void BoundingSphere(oglplus::Sphere<T>& bounding_sphere) const
174  {
175  bounding_sphere = oglplus::Sphere<T>(
176  T(_ox),
177  T(_oy),
178  T(_oz),
179  T(std::sqrt(_sx*_sx + _sy*_sy + _sz*_sz))
180  );
181  }
182 
184  typedef std::vector<GLushort> IndexArray;
185 
187  IndexArray Indices(Default = Default()) const
188  {
189  return IndexArray();
190  }
191 
193  DrawingInstructions Instructions(Default = Default()) const;
194 
196  IndexArray Indices(Edges) const;
197 
199  DrawingInstructions Instructions(Edges) const;
200 };
201 
202 } // shapes
203 } // oglplus
204 
205 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
206 #include <oglplus/shapes/cube.ipp>
207 #endif // OGLPLUS_LINK_LIBRARY
208 
209 #endif // include guard
Implementation of shape draw instructions.
GLuint Normals(std::vector< T > &dest) const
Makes the normals and returns the number of values per vertex.
Definition: cube.hpp:108
GLuint Positions(std::vector< T > &dest) const
Makes the vertices and returns the number of values per vertex.
Definition: cube.hpp:91
Cube(GLdouble w, GLdouble h, GLdouble d, GLdouble x, GLdouble y, GLdouble z)
Constructs a cube with width, height, depth and x,y and z offsets.
Definition: cube.hpp:58
Sphere utility class.
Cube(void)
Constructs a unit cube centered at the origin.
Definition: cube.hpp:38
VertexAttribsInfo< Cube > VertexAttribs
Vertex attribute information for this shape builder.
Definition: cube.hpp:158
IndexArray Indices(Default=Default()) const
Returns element indices that are used with the drawing instructions.
Definition: cube.hpp:187
FaceOrientation
Face orientation enumeration.
Definition: face_mode.hpp:62
OpenGL face type-related enumeration.
GLuint TexCoordinates(std::vector< T > &dest) const
Makes the texture coordinates and returns the number of values per vertex.
Definition: cube.hpp:142
DrawingInstructions Instructions(Default=Default()) const
Returns the instructions for rendering of faces.
void BoundingSphere(oglplus::Sphere< T > &bounding_sphere) const
Queries the bounding sphere coordinates and dimensions.
Definition: cube.hpp:173
GLuint Tangents(std::vector< T > &dest) const
Makes the tangents and returns the number of values per vertex.
Definition: cube.hpp:125
FaceOrientation FaceWinding(void) const
Returns the winding direction of faces.
Definition: cube.hpp:74
std::vector< GLushort > IndexArray
The type of the index container returned by Indices()
Definition: cube.hpp:184
Class providing vertex attributes and instructions for rendering of a cube.
Definition: cube.hpp:29
Cube(GLdouble w, GLdouble h, GLdouble d)
Constructs a cube with width, height, depth.
Definition: cube.hpp:48
Classes providing additional information about the shape builders.
Class encapsulating the instructions for drawing of a shape.
Definition: draw.hpp:219
Class implementing sphere-related functionality.
Definition: sphere.hpp:29

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