13 #ifndef OGLPLUS_SHAPES_SPHERE_1107121519_HPP
14 #define OGLPLUS_SHAPES_SPHERE_1107121519_HPP
29 :
public DrawingInstructionWriter
34 unsigned _sections, _rings;
47 Sphere(
double radius,
unsigned sections,
unsigned rings)
53 assert(_sections > 0);
86 assert(_sections > 0);
112 template <
typename T>
115 dest.resize(((_rings + 2) * (_sections + 1)) * 3);
118 double r_step = (1.0 * math::Pi()) /
double(_rings + 1);
119 double s_step = (2.0 * math::Pi()) /
double(_sections);
121 for(
unsigned r=0; r!=(_rings+2);++r)
123 double r_lat = std::cos(r*r_step);
124 double r_rad = std::sin(r*r_step);
126 for(
unsigned s=0; s!=(_sections+1);++s)
128 dest[k++] =
T(r_rad * std::cos(s*s_step));
129 dest[k++] =
T(r_lat);
130 dest[k++] =
T(r_rad * -std::sin(s*s_step));
134 assert(k == dest.size());
140 template <
typename T>
143 dest.resize(((_rings + 2) * (_sections + 1)) * 3);
146 double s_step = (2.0 * math::Pi()) /
double(_sections);
148 for(
unsigned r=0; r!=(_rings+2);++r)
150 for(
unsigned s=0; s!=(_sections+1);++s)
152 dest[k++] =
T(-std::sin(s*s_step));
154 dest[k++] =
T(-std::cos(s*s_step));
158 assert(k == dest.size());
164 template <
typename T>
167 dest.resize(((_rings + 2) * (_sections + 1)) * 3);
170 double r_step = (1.0 * math::Pi()) /
double(_rings + 1);
171 double s_step = (2.0 * math::Pi()) /
double(_sections);
174 for(
unsigned r=0; r!=(_rings+2);++r)
176 double r_lat = std::cos(r*r_step);
177 double r_rad = std::sin(r*r_step);
180 for(
unsigned s=0; s!=(_sections+1);++s)
182 double tx = -std::sin(s*s_step);
183 double tz = -std::cos(s*s_step);
184 double nx = -r_rad * tz;
185 double nz = r_rad * tx;
187 dest[k++] =
T(ny*tz-nz*ty);
188 dest[k++] =
T(nz*tx-nx*tz);
189 dest[k++] =
T(nx*ty-ny*tx);
193 assert(k == dest.size());
199 template <
typename T>
204 for(
auto i=dest.begin(),e=dest.end(); i!= e; ++i)
210 template <
typename T>
213 dest.resize(((_rings + 2) * (_sections + 1)) * 2);
216 double r_step = 1.0 / double(_rings + 1);
217 double s_step = 1.0 / double(_sections);
218 for(
unsigned r=0; r!=(_rings+2);++r)
220 double r_lat = 1.0 - r*r_step;
222 for(
unsigned s=0; s!=(_sections+1);++s)
224 dest[k++] =
T(s * s_step);
225 dest[k++] =
T(r_lat);
228 assert(k == dest.size());
233 #if OGLPLUS_DOCUMENTATION_ONLY
245 typedef VertexAttribsInfo<
252 VertexTexCoordinatesTag
258 template <
typename T>
282 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
283 #include <oglplus/shapes/sphere.ipp>
284 #endif // OGLPLUS_LINK_LIBRARY
286 #endif // include guard
Implementation of shape draw instructions.
GLuint Positions(std::vector< T > &dest) const
Makes vertex coordinates and returns number of values per vertex.
Definition: sphere.hpp:200
unsigned Sections(void) const
Returns the number of sections of the sphere.
Definition: sphere.hpp:74
GLuint Bitangents(std::vector< T > &dest) const
Makes vertex bi-tangents and returns number of values per vertex.
Definition: sphere.hpp:165
void BoundingSphere(oglplus::Sphere< T > &bounding_sphere) const
Queries the bounding sphere coordinates and dimensions.
Definition: sphere.hpp:259
IndexArray Indices(Default=Default()) const
Returns element indices that are used with the drawing instructions.
void Radius(double radius)
Sets the radius of the sphere.
Definition: sphere.hpp:67
Sphere(double radius, unsigned sections, unsigned rings)
Creates a sphere with specified radius centered at the origin.
Definition: sphere.hpp:47
std::vector< GLushort > IndexArray
The type of index container returned by Indices()
Definition: sphere.hpp:270
FaceOrientation
Face orientation enumeration.
Definition: face_mode.hpp:62
OpenGL face type-related enumeration.
GLuint Tangents(std::vector< T > &dest) const
Makes vertex tangents and returns number of values per vertex.
Definition: sphere.hpp:141
Sphere(void)
Creates a sphere with unit radius centered at the origin.
Definition: sphere.hpp:37
void Rings(unsigned rings)
Sets the number of rings of the sphere.
Definition: sphere.hpp:99
GLuint Normals(std::vector< T > &dest) const
Makes vertex normals and returns number of values per vertex.
Definition: sphere.hpp:113
double Radius(void) const
Returns the radius of the sphere.
Definition: sphere.hpp:58
VertexAttribsInfo< Sphere > VertexAttribs
Vertex attribute information for this shape builder.
Definition: sphere.hpp:243
Classes providing additional information about the shape builders.
void Sections(unsigned sections)
Sets the number of sections of the sphere.
Definition: sphere.hpp:83
Class encapsulating the instructions for drawing of a shape.
Definition: draw.hpp:219
DrawingInstructions Instructions(Default=Default()) const
Returns the instructions for rendering.
Class implementing sphere-related functionality.
Definition: sphere.hpp:29
GLuint TexCoordinates(std::vector< T > &dest) const
Makes texture-coorinates and returns number of values per vertex.
Definition: sphere.hpp:211
FaceOrientation FaceWinding(void) const
Returns the winding direction of faces.
Definition: sphere.hpp:106
unsigned Rings(void) const
Returns the number of rings of the sphere.
Definition: sphere.hpp:90
Class providing vertex attributes and instructions for rendering of a Sphere.
Definition: sphere.hpp:28