Geometry stored on the host. More...
#include <Geometry.hpp>
Public Types | |
enum | GeometryType { CustomModel, StandardQuad, ReversedQuad, PointsGrid2D, PointsGrid3D, Unknown } |
Description of the type of geometry (automatic). More... | |
Public Member Functions | |
GeometryModel (const GeometryModel &mdl) | |
GeometryModel copy constructor. More... | |
unsigned int | getNumVertices (void) const |
Get the number of vertices. More... | |
unsigned int | getNumElements (void) const |
Get the number of GL primitives (elements). More... | |
const GLfloat & | x (GLuint i) const |
Read the X coordinate of the vertex at given index. More... | |
const GLfloat & | y (GLuint i) const |
Read the Y coordinate of the vertex at given index. More... | |
const GLfloat & | z (GLuint i) const |
Read the Z coordinate of the vertex at given index. More... | |
const GLfloat & | ny (GLuint i) const |
Access the Y coordinate of the normal at given index. More... | |
const GLfloat & | u (GLuint i) const |
Access the U coordinate of the texel at given index. More... | |
const GLfloat & | v (GLuint i) const |
Access the V coordinate of the texel at given index. More... | |
const GLuint & | a (GLuint i) const |
Access the index of the first vertex of the element at given index. More... | |
const GLuint & | b (GLuint i) const |
Access the index of the second vertex of the element at given index. More... | |
const GLuint & | c (GLuint i) const |
Access the index of the third vertex of the element at given index. More... | |
bool | testIndices (void) const |
Test if all the indices are valid. More... | |
bool | operator== (const GeometryModel &mdl) const |
Test if two models are identical. More... | |
HdlVBO * | getVBO (GLenum freq) const |
Get the VBO corresponding to this model. It is not recommended to use directly the VBO but, instead, use a GeometryInstance object. More... | |
Static Public Member Functions | |
static int | getNumVerticesInPrimitive (const GLenum &_primitiveGL) |
Get the number of vertices per element for the given primitive. More... | |
static int | getPrimitiveStride (const GLenum &_primitiveGL) |
Get the stride between elements of the given primitive. More... | |
Public Attributes | |
const GeometryType | type |
Geometry Type. | |
const bool | hasNormals |
True if it has texture coordinates attached. | |
const bool | hasTexCoords |
Dimension of the geometry (either 2 or 3). | |
const int | dim |
True if it has normals data attached. | |
const int | numVerticesPerElement |
Number of vertices per elements of the geometry. | |
const int | elementStride |
Stride between the elements. | |
const GLenum | primitiveGL |
ID of the primitive for GL. | |
Protected Member Functions | |
GeometryModel (GeometryType _type, int _dim, GLenum _primitiveGL, bool _hasNormals, bool _hasTexCoords) | |
Geometry model constructor. More... | |
void | reserveVertices (size_t nVertices) |
Prepare the memory to receive a number of vertices. More... | |
void | increaseVerticesReservation (size_t nNewVertices) |
Prepare the memory to receive a new number of vertices. More... | |
void | reserveElements (size_t nVertices) |
Prepare the memory to receive a number of elements. More... | |
void | increaseElementsReservation (size_t nNewVertices) |
Prepare the memory to receive a new number of elements. More... | |
void | addVertices2DInterleaved (const size_t N, const GLfloat *interleavedXY, const GLfloat *interleavedNormalsXY=NULL, const GLfloat *interleavedUV=NULL) |
Add multiple vertives in a two dimensions space (GeometryModel::dim must be equal to 2). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate. More... | |
void | addVertices2D (const size_t N, const GLfloat *x, const GLfloat *y, const GLfloat *nx=NULL, const GLfloat *ny=NULL, const GLfloat *u=NULL, const GLfloat *v=NULL) |
Add multiple vertices in a two dimensions space (GeometryModel::dim must be equal to 2). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate. More... | |
GLuint | addVertex2D (const GLfloat &x, const GLfloat &y, const GLfloat &nx=0.0f, const GLfloat &ny=0.0f, const GLfloat &u=0.0f, const GLfloat &v=0.0f) |
Add a vertex in a two dimensions space (GeometryModel::dim must be equal to 2). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate. More... | |
void | addVertices3DInterleaved (const size_t N, const GLfloat *interleavedXYZ, const GLfloat *interleavedNormalsXYZ=NULL, const GLfloat *interleavedUV=NULL) |
Add multiple vertices in a three dimensions space (GeometryModel::dim must be equal to 3). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate. More... | |
void | addVertices3D (const size_t N, const GLfloat *x, const GLfloat *y, const GLfloat *z, const GLfloat *nx=NULL, const GLfloat *ny=NULL, const GLfloat *nz=NULL, const GLfloat *u=NULL, const GLfloat *v=NULL) |
Add multiple vertices in a three dimensions space (GeometryModel::dim must be equal to 3). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate. More... | |
GLuint | addVertex3D (const GLfloat &x, const GLfloat &y, const GLfloat &z, const GLfloat &nx=0.0f, const GLfloat &ny=0.0f, const GLfloat &nz=0.0f, const GLfloat &u=0.0f, const GLfloat &v=0.0f) |
Add a vertex in a three dimensions space (GeometryModel::dim must be equal to 3). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate. More... | |
void | addElementsInterleaved (const size_t N, GLuint *interleavedIndices) |
Add primitive elements to the model. More... | |
void | addElements (const size_t N, GLuint *a, GLuint *b=NULL, GLuint *c=NULL, GLuint *d=NULL) |
Add primitive elements to the model. More... | |
GLuint | addElement (GLuint a) |
Add a primitive element to the model. More... | |
GLuint | addElement (GLuint a, GLuint b) |
Add a primitive element to the model. More... | |
GLuint | addElement (GLuint a, GLuint b, GLuint c) |
Add a primitive element to the model. More... | |
GLuint | addElement (GLuint a, GLuint b, GLuint c, GLuint d) |
Add a primitive element to the model. More... | |
GLuint | addElement (const std::vector< GLuint > &indices) |
Add (a) primitive element(s) to the model. More... | |
GLfloat & | x (GLuint i) |
Access the X coordinate of the vertex at given index. More... | |
GLfloat & | y (GLuint i) |
Access the Y coordinate of the vertex at given index. More... | |
GLfloat & | z (GLuint i) |
Access the Z coordinate of the vertex at given index. More... | |
GLfloat & | nx (GLuint i) |
Access the X coordinate of the normal at given index. More... | |
GLfloat & | ny (GLuint i) |
Access the Y coordinate of the normal at given index. More... | |
GLfloat & | u (GLuint i) |
Access the U coordinate of the texel at given index. More... | |
GLfloat & | v (GLuint i) |
Access the V coordinate of the texel at given index. More... | |
GLuint & | a (GLuint i) |
Access the index of the first vertex of the element at given index. More... | |
GLuint & | b (GLuint i) |
Access the index of the second vertex of the element at given index. More... | |
GLuint & | c (GLuint i) |
Access the index of the third vertex of the element at given index. More... | |
void | generateNormals (void) |
Automatically generate the normals. More... | |
Geometry stored on the host.
Description of the type of geometry (automatic).
|
protected |
Geometry model constructor.
_type | The type of the geometry (MUST BE GeometryModel::CustomModel for all user defined models). |
_dim | The minimum number of spatial dimensions needed to describe the geometry (either 2 or 3). |
_primitiveGL | The GL ID of the element primitive (among GL_POINTS, GL_LINES, GL_LINES_ADJACENCY, GL_LINE_STRIP, GL_LINE_STRIP_ADJACENCY, GL_TRIANGLES, GL_TRIANGLES_ADJACENCY, GL_TRIANGLE_STRIP, GL_TRIANGLE_STRIP_ADJACENCY) |
_hasNormals | Set to true if the geometry has normals data attached. |
_hasTexCoords | Set to true if the geometry has texel coordinates attached. |
GeometryModel::GeometryModel | ( | const GeometryModel & | mdl | ) |
GeometryModel copy constructor.
mdl | The source model. |
|
protected |
Access the index of the first vertex of the element at given index.
Access the index of the fourth vertex of the element at given index.
i | The element index. |
i | The element index. |
const GLuint & GeometryModel::a | ( | GLuint | i | ) | const |
Access the index of the first vertex of the element at given index.
Access the index of the fourth vertex of the element at given index.
i | The element index. |
i | The element index. |
|
protected |
Add a primitive element to the model.
a | Index of the first vertex. |
|
protected |
Add a primitive element to the model.
a | Index of the first vertex. |
b | Index of the second vertex. |
|
protected |
Add a primitive element to the model.
a | Index of the first vertex. |
b | Index of the second vertex. |
c | Index of the third vertex. |
|
protected |
Add a primitive element to the model.
a | Index of the first vertex. |
b | Index of the second vertex. |
c | Index of the third vertex. |
d | Index of the fourth vertex. |
|
protected |
Add (a) primitive element(s) to the model.
indices | A vector containing the indices of all the vertices used. |
|
protected |
Add primitive elements to the model.
N | Number of primitive elements. |
a | First vertices indices. |
b | Second vertices indices. |
c | Third vertices indices. |
d | Fourth vertices indices. |
All arrays must contain N indices.
|
protected |
Add primitive elements to the model.
N | Number of primitive elements. |
interleavedIndices | Array of vertices indices. Must contain N*numVerticesPerElement indices. |
|
protected |
Add a vertex in a two dimensions space (GeometryModel::dim must be equal to 2). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate.
x | The X coordinate. |
y | The Y coordinate. |
nx | The X component of the normal. |
ny | The Y component of the normal. |
u | The U coordinate for the texel (ignored if GeometryModel::hasTexCoords is set to false). |
v | The V coordinate for the texel (ignored if GeometryModel::hasTexCoords is set to false). |
|
protected |
Add a vertex in a three dimensions space (GeometryModel::dim must be equal to 3). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate.
x | The X coordinate. |
y | The Y coordinate. |
z | The Z coordinate. |
nx | The X component of the normal. |
ny | The Y component of the normal. |
nz | The Z component of the normal. |
u | The U coordinate for the texel (ignored if GeometryModel::hasTexCoords is set to false). |
v | The V coordinate for the texel (ignored if GeometryModel::hasTexCoords is set to false). |
|
protected |
Add multiple vertices in a two dimensions space (GeometryModel::dim must be equal to 2). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate.
N | The number of vertices to be added. |
x | The array of spatial X coordinates. |
y | The array of spatial Y coordinates. |
nx | The array of normal components along X. |
ny | The array of normal components along Y. |
u | The array of texture U coordinates. |
v | The array of texture V coordinates. |
All arrays must contain N indices.
|
protected |
Add multiple vertives in a two dimensions space (GeometryModel::dim must be equal to 2). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate.
N | The number of vertices to be added. |
interleavedXY | The interleaved array of the spatial coordinates. |
interleavedNormalsXY | The interleaved array of the normals data. |
interleavedUV | The interleaved array of the texture coordinates. |
The vertices coordinates and normals arrays must contain N*dim elements. The texture coordinates array must contain 2*N elements.
|
protected |
Add multiple vertices in a three dimensions space (GeometryModel::dim must be equal to 3). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate.
N | The number of vertices to be added. |
x | The array of spatial X coordinates. |
y | The array of spatial Y coordinates. |
z | The array of spatial Z coordinates. |
nx | The array of normal components along X. |
ny | The array of normal components along Y. |
nz | The array of normal components along Z. |
u | The array of texture U coordinates. |
v | The array of texture V coordinates. |
All arrays must contain N indices.
|
protected |
Add multiple vertices in a three dimensions space (GeometryModel::dim must be equal to 3). If GeometryModel::hasTexCoords is true, then it will also use u and v to create a texel coordinate.
N | The number of vertices to be added. |
interleavedXYZ | The interleaved array of the spatial coordinates. |
interleavedNormalsXYZ | The interleaved array of the normals data. |
interleavedUV | The interleaved array of the texture coordinates. |
The vertices coordinates and normals arrays must contain N*dim elements. The texture coordinates array must contain 2*N elements.
|
protected |
Access the index of the second vertex of the element at given index.
i | The element index. |
const GLuint & GeometryModel::b | ( | GLuint | i | ) | const |
Access the index of the second vertex of the element at given index.
i | The element index. |
|
protected |
Access the index of the third vertex of the element at given index.
i | The element index. |
const GLuint & GeometryModel::c | ( | GLuint | i | ) | const |
Access the index of the third vertex of the element at given index.
i | The element index. |
|
protected |
Automatically generate the normals.
If the primitive is GL_POINTS, this will reset the normals to 0.
unsigned int GeometryModel::getNumElements | ( | void | ) | const |
Get the number of GL primitives (elements).
unsigned int GeometryModel::getNumVertices | ( | void | ) | const |
Get the number of vertices.
|
static |
Get the number of vertices per element for the given primitive.
_primitiveGL | The GL primitive (accepted are : GL_POINTS, GL_LINES, GL_LINES_ADJACENCY, GL_LINE_STRIP, GL_LINE_STRIP_ADJACENCY, GL_TRIANGLES, GL_TRIANGLES_ADJACENCY, GL_TRIANGLE_STRIP, GL_TRIANGLE_STRIP_ADJACENCY). |
|
static |
Get the stride between elements of the given primitive.
_primitiveGL | The GL primitive (accepted are : GL_POINTS, GL_LINES, GL_LINES_ADJACENCY, GL_LINE_STRIP, GL_LINE_STRIP_ADJACENCY, GL_TRIANGLES, GL_TRIANGLES_ADJACENCY, GL_TRIANGLE_STRIP, GL_TRIANGLE_STRIP_ADJACENCY). |
HdlVBO * GeometryModel::getVBO | ( | GLenum | freq | ) | const |
Get the VBO corresponding to this model. It is not recommended to use directly the VBO but, instead, use a GeometryInstance object.
freq | The GL frequency of read/write operations (among : GL_STATIC_DRAW_ARB, GL_STATIC_READ_ARB, GL_STATIC_COPY_ARB, GL_DYNAMIC_DRAW_ARB, GL_DYNAMIC_READ_ARB, GL_DYNAMIC_COPY_ARB, GL_STREAM_DRAW_ARB, GL_STREAM_READ_ARB, GL_STREAM_COPY_ARB). |
|
protected |
Prepare the memory to receive a new number of elements.
nNewElements | The number of elements to be added. |
|
protected |
Prepare the memory to receive a new number of vertices.
nNewVertices | The number of vertices to be added. |
|
protected |
Access the X coordinate of the normal at given index.
i | The vertex index. |
i | The vertex index. |
|
protected |
Access the Y coordinate of the normal at given index.
i | The vertex index. |
const GLfloat & GeometryModel::ny | ( | GLuint | i | ) | const |
Access the Y coordinate of the normal at given index.
i | The vertex index. |
bool GeometryModel::operator== | ( | const GeometryModel & | mdl | ) | const |
Test if two models are identical.
mdl | The reference model. |
|
protected |
Prepare the memory to receive a number of elements.
nElements | The total number of elements to contain. |
|
protected |
Prepare the memory to receive a number of vertices.
nVertices | The total number of vertices to contain. |
bool GeometryModel::testIndices | ( | void | ) | const |
Test if all the indices are valid.
|
protected |
Access the U coordinate of the texel at given index.
i | The vertex/texel index. |
const GLfloat & GeometryModel::u | ( | GLuint | i | ) | const |
Access the U coordinate of the texel at given index.
i | The vertex/texel index. |
|
protected |
Access the V coordinate of the texel at given index.
i | The vertex/texel index. |
const GLfloat & GeometryModel::v | ( | GLuint | i | ) | const |
Access the V coordinate of the texel at given index.
i | The vertex/texel index. |
|
protected |
Access the X coordinate of the vertex at given index.
i | The vertex index. |
const GLfloat & GeometryModel::x | ( | GLuint | i | ) | const |
Read the X coordinate of the vertex at given index.
i | The vertex index. |
|
protected |
Access the Y coordinate of the vertex at given index.
i | The vertex index. |
const GLfloat & GeometryModel::y | ( | GLuint | i | ) | const |
Read the Y coordinate of the vertex at given index.
i | The vertex index. |
|
protected |
Access the Z coordinate of the vertex at given index.
Access the Z coordinate of the normal at given index.
i | The vertex index. |
const GLfloat & GeometryModel::z | ( | GLuint | i | ) | const |
Read the Z coordinate of the vertex at given index.
Access the Z coordinate of the normal at given index.
i | The vertex index. |