13 #ifndef OGLPLUS_SHAPES_TORUS_1107121519_HPP
14 #define OGLPLUS_SHAPES_TORUS_1107121519_HPP
29 :
public DrawingInstructionWriter
33 GLdouble _radius_out, _radius_in;
34 unsigned _sections, _rings;
45 Torus(GLdouble rad_out, GLdouble rad_in,
unsigned sects,
unsigned rings)
46 : _radius_out(rad_out)
62 dest.resize((_rings + 1) * (_sections + 1) * 3);
65 GLdouble r_step = (math::TwoPi()) / GLdouble(_rings);
66 GLdouble s_step = (math::TwoPi()) / GLdouble(_sections);
67 GLdouble r1 = _radius_in;
68 GLdouble r2 = _radius_out - _radius_in;
70 for(
unsigned r=0; r!=(_rings+1); ++r)
72 GLdouble vx = std::cos(r*r_step);
73 GLdouble vz = -std::sin(r*r_step);
74 for(
unsigned s=0; s!=(_sections+1); ++s)
76 GLdouble vr = std::cos(s*s_step);
77 GLdouble vy = std::sin(s*s_step);
78 dest[k++] =
T(vx*(r1 + r2 * (1.0 + vr)));
80 dest[k++] =
T(vz*(r1 + r2 * (1.0 + vr)));
83 assert(k == dest.size());
89 GLuint
Normals(std::vector<T>& dest)
const
91 dest.resize((_rings + 1) * (_sections + 1) * 3);
94 GLdouble r_step = (math::TwoPi()) / GLdouble(_rings);
95 GLdouble s_step = (math::TwoPi()) / GLdouble(_sections);
97 for(
unsigned r=0; r!=(_rings+1); ++r)
99 GLdouble nx = std::cos(r*r_step);
100 GLdouble nz = -std::sin(r*r_step);
101 for(
unsigned s=0; s!=(_sections+1); ++s)
103 GLdouble nr = std::cos(s*s_step);
104 GLdouble ny = std::sin(s*s_step);
105 dest[k++] =
T(nx*nr);
107 dest[k++] =
T(nz*nr);
110 assert(k == dest.size());
115 template <
typename T>
118 dest.resize((_rings + 1) * (_sections + 1) * 3);
121 GLdouble r_step = (math::TwoPi()) / GLdouble(_rings);
123 for(
unsigned r=0; r!=(_rings+1); ++r)
125 GLdouble tx = -std::sin(r*r_step);
126 GLdouble tz = -std::cos(r*r_step);
127 for(
unsigned s=0; s!=(_sections+1); ++s)
134 assert(k == dest.size());
139 template <
typename T>
142 dest.resize((_rings + 1) * (_sections + 1) * 3);
145 GLdouble r_step = (math::TwoPi()) / GLdouble(_rings);
146 GLdouble s_step = (math::TwoPi()) / GLdouble(_sections);
149 for(
unsigned r=0; r!=(_rings+1); ++r)
151 GLdouble tx = -std::sin(r*r_step);
152 GLdouble tz = -std::cos(r*r_step);
154 for(
unsigned s=0; s!=(_sections+1); ++s)
156 GLdouble ny = std::sin(s*s_step);
157 GLdouble nr = std::cos(s*s_step);
158 GLdouble nx = -tz*nr;
161 dest[k++] =
T(ny*tz-nz*ty);
162 dest[k++] =
T(nz*tx-nx*tz);
163 dest[k++] =
T(nx*ty-ny*tx);
166 assert(k == dest.size());
171 template <
typename T>
174 dest.resize((_rings + 1) * (_sections + 1) * 2);
177 GLdouble r_step = 1.0 / GLdouble(_rings);
178 GLdouble s_step = 1.0 / GLdouble(_sections);
180 for(
unsigned r=0; r!=(_rings+1); ++r)
182 GLdouble u = r*r_step;
183 for(
unsigned s=0; s!=(_sections+1); ++s)
185 GLdouble v = s*s_step;
190 assert(k == dest.size());
194 #if OGLPLUS_DOCUMENTATION_ONLY
206 typedef VertexAttribsInfo<
213 VertexTexCoordinatesTag
219 template <
typename T>
255 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
256 #include <oglplus/shapes/torus.ipp>
257 #endif // OGLPLUS_LINK_LIBRARY
259 #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: torus.hpp:89
void BoundingSphere(oglplus::Sphere< T > &bounding_sphere) const
Queries the bounding sphere coordinates and dimensions.
Definition: torus.hpp:220
GLuint TexCoordinates(std::vector< T > &dest) const
Makes texture coordinates and returns number of values per vertex.
Definition: torus.hpp:172
DrawingInstructions Instructions(Default=Default()) const
Returns the instructions for rendering.
GLuint Positions(std::vector< T > &dest) const
Makes vertex coordinates and returns number of values per vertex.
Definition: torus.hpp:60
FaceOrientation
Face orientation enumeration.
Definition: face_mode.hpp:62
OpenGL face type-related enumeration.
Class providing vertex attributes and instructions for rendering of a Torus.
Definition: torus.hpp:28
FaceOrientation FaceWinding(void) const
Returns the winding direction of faces.
Definition: torus.hpp:53
VertexAttribsInfo< Torus > VertexAttribs
Vertex attribute information for this shape builder.
Definition: torus.hpp:204
IndexArray Indices(Default=Default()) const
Returns element indices that are used with the drawing instructions.
GLuint Bitangents(std::vector< T > &dest) const
Makes vertex bi-tangents and returns number of values per vertex.
Definition: torus.hpp:140
Classes providing additional information about the shape builders.
Torus(GLdouble rad_out, GLdouble rad_in, unsigned sects, unsigned rings)
Creates a torus with unit radius centered at the origin.
Definition: torus.hpp:45
Torus(void)
Creates a torus with unit radius centered at the origin.
Definition: torus.hpp:37
Class encapsulating the instructions for drawing of a shape.
Definition: draw.hpp:219
Class implementing sphere-related functionality.
Definition: sphere.hpp:29
std::vector< GLushort > IndexArray
The type of index container returned by Indices()
Definition: torus.hpp:231
GLuint Tangents(std::vector< T > &dest) const
Makes vertex tangents and returns number of values per vertex.
Definition: torus.hpp:116