13 #ifndef OGLPLUS_SHAPES_GRID_1107121519_HPP
14 #define OGLPLUS_SHAPES_GRID_1107121519_HPP
31 :
public DrawingInstructionWriter
37 unsigned _udiv, _vdiv;
39 unsigned _vertex_count(
void)
const
41 return (_udiv+1)*2+(_vdiv-1)*2;
46 : _point(0.0f, 0.0f, 0.0f)
47 , _u(1.0f, 0.0f, 0.0f)
48 , _v(0.0f, 0.0f,-1.0f)
55 : _point(0.0f, 0.0f, 0.0f)
61 assert(Length(_u) > 0.0f);
62 assert(Length(_v) > 0.0f);
78 assert(Length(_u) > 0.0f);
79 assert(Length(_v) > 0.0f);
84 const Vec3f& Point(
void)
const
89 const Vec3f& U(
void)
const
94 const Vec3f& V(
void)
const
99 inline Vec3f Normal(
void)
const
101 return Normalized(Cross(_u, _v));
104 inline Vec3f Tangential(
void)
const
106 return Normalized(_u);
109 inline Vec3f Bitangential(
void)
const
111 return Normalized(_v);
114 Vec4f PlaneEquation(
void)
const
116 return Vec4f(Normal(), -Dot(Normal(), _point));
126 template <
typename T>
129 unsigned k = 0, n = _vertex_count();
132 const Vec3f pos(_point - _u - _v);
133 const Vec3f ustep(_u * (2.0 / _udiv));
134 const Vec3f vstep(_v * (2.0 / _vdiv));
136 for(
unsigned i=0; i<(_udiv+1); ++i)
138 Vec3f tmp = pos+ustep*i;
139 dest[k++] =
T(tmp.x());
140 dest[k++] =
T(tmp.
y());
141 dest[k++] =
T(tmp.
z());
144 dest[k++] =
T(tmp.x());
145 dest[k++] =
T(tmp.y());
146 dest[k++] =
T(tmp.z());
149 for(
unsigned j=1; j<(_vdiv); ++j)
151 Vec3f tmp = pos+vstep*j;
152 dest[k++] =
T(tmp.x());
153 dest[k++] =
T(tmp.
y());
154 dest[k++] =
T(tmp.
z());
157 dest[k++] =
T(tmp.x());
158 dest[k++] =
T(tmp.y());
159 dest[k++] =
T(tmp.z());
161 assert(k == dest.size());
166 template <
typename T>
169 unsigned k = 0, n = _vertex_count();
173 T ustep =
T(1) / _udiv;
174 T vstep =
T(1) / _vdiv;
177 for(
unsigned i=0; i<(_udiv+1); ++i)
179 dest[k++] =
T(ustep*i);
182 dest[k++] =
T(ustep*i);
186 for(
unsigned j=1; j<(_vdiv); ++j)
189 dest[k++] =
T(vstep*j);
192 dest[k++] =
T(vstep*j);
194 assert(k == dest.size());
199 #if OGLPLUS_DOCUMENTATION_ONLY
208 typedef VertexAttribsInfo<
212 VertexTexCoordinatesTag
218 template <
typename T>
242 #if !OGLPLUS_LINK_LIBRARY || defined(OGLPLUS_IMPLEMENTING_LIBRARY)
243 #include <oglplus/shapes/grid.ipp>
244 #endif // OGLPLUS_LINK_LIBRARY
246 #endif // include guard
Implementation of shape draw instructions.
Vector< GLfloat, 4 > Vec4f
4D float vector
Definition: vector.hpp:85
std::vector< GLuint > IndexArray
The type of index container returned by Indices()
Definition: grid.hpp:230
IndexArray Indices(Default=Default()) const
Returns element indices that are used with the drawing instructions.
FaceOrientation FaceWinding(void) const
Returns the winding direction of faces (unused)
Definition: grid.hpp:120
GLuint Positions(std::vector< T > &dest) const
Makes vertex coordinates and returns number of values per vertex.
Definition: grid.hpp:127
Grid(const Vec3f u, const Vec3f v)
Creates a grid with going through origin specified by u and v.
Definition: grid.hpp:54
Vector< GLfloat, 3 > Vec3f
3D float vector
Definition: vector.hpp:79
GLuint TexCoordinates(std::vector< T > &dest) const
Makes texture-coorinates and returns number of values per vertex.
Definition: grid.hpp:167
DrawingInstructions Instructions(Default=Default()) const
Returns the instructions for rendering.
FaceOrientation
Face orientation enumeration.
Definition: face_mode.hpp:62
OpenGL face type-related enumeration.
T z(void) const
Returns the 2-nd component.
Definition: vector.hpp:237
void BoundingSphere(oglplus::Sphere< T > &bounding_sphere) const
Queries the bounding sphere coordinates and dimensions.
Definition: grid.hpp:219
T y(void) const
Returns the 1-st component.
Definition: vector.hpp:231
VertexAttribsInfo< Grid > VertexAttribs
Vertex attribute information for this shape builder.
Definition: grid.hpp:206
Grid(const Vec3f p, const Vec3f u, const Vec3f v, unsigned udiv, unsigned vdiv)
Creates a grid with going through p specified by u and v.
Definition: grid.hpp:66
Classes providing additional information about the shape builders.
Class encapsulating the instructions for drawing of a shape.
Definition: draw.hpp:219
Grid(void)
Creates a default grid.
Definition: grid.hpp:45
Class implementing sphere-related functionality.
Definition: sphere.hpp:29
Class providing vertex attributes and instructions for rendering of a grid.
Definition: grid.hpp:30