- cpp3ds
- VertexArray
Define a set of one or more 2D primitives. More...
#include <VertexArray.hpp>
Public Member Functions | |
VertexArray () | |
Default constructor. More... | |
VertexArray (PrimitiveType type, unsigned int vertexCount=0) | |
Construct the vertex array with a type and an initial number of vertices. More... | |
unsigned int | getVertexCount () const |
Return the vertex count. More... | |
Vertex & | operator[] (unsigned int index) |
Get a read-write access to a vertex by its index. More... | |
const Vertex & | operator[] (unsigned int index) const |
Get a read-only access to a vertex by its index. More... | |
void | clear () |
Clear the vertex array. More... | |
void | resize (unsigned int vertexCount) |
Resize the vertex array. More... | |
void | append (const Vertex &vertex) |
Add a vertex to the array. More... | |
void | setPrimitiveType (PrimitiveType type) |
Set the type of primitives to draw. More... | |
PrimitiveType | getPrimitiveType () const |
Get the type of primitives drawn by the vertex array. More... | |
FloatRect | getBounds () const |
Compute the bounding rectangle of the vertex array. More... | |
Define a set of one or more 2D primitives.
cpp3ds::VertexArray is a very simple wrapper around a dynamic array of vertices and a primitives type.
It inherits cpp3ds::Drawable, but unlike other drawables it is not transformable.
Example:
Definition at line 47 of file VertexArray.hpp.
cpp3ds::VertexArray::VertexArray | ( | ) |
Default constructor.
Creates an empty vertex array.
|
explicit |
Construct the vertex array with a type and an initial number of vertices.
type | Type of primitives |
vertexCount | Initial number of vertices in the array |
void cpp3ds::VertexArray::append | ( | const Vertex & | vertex | ) |
Add a vertex to the array.
vertex | Vertex to add |
void cpp3ds::VertexArray::clear | ( | ) |
Clear the vertex array.
This function removes all the vertices from the array. It doesn't deallocate the corresponding memory, so that adding new vertices after clearing doesn't involve reallocating all the memory.
FloatRect cpp3ds::VertexArray::getBounds | ( | ) | const |
Compute the bounding rectangle of the vertex array.
This function returns the axis-aligned rectangle that contains all the vertices of the array.
PrimitiveType cpp3ds::VertexArray::getPrimitiveType | ( | ) | const |
Get the type of primitives drawn by the vertex array.
unsigned int cpp3ds::VertexArray::getVertexCount | ( | ) | const |
Return the vertex count.
Vertex& cpp3ds::VertexArray::operator[] | ( | unsigned int | index | ) |
Get a read-write access to a vertex by its index.
This function doesn't check index, it must be in range [0, getVertexCount() - 1]. The behaviour is undefined otherwise.
index | Index of the vertex to get |
const Vertex& cpp3ds::VertexArray::operator[] | ( | unsigned int | index | ) | const |
Get a read-only access to a vertex by its index.
This function doesn't check index, it must be in range [0, getVertexCount() - 1]. The behaviour is undefined otherwise.
index | Index of the vertex to get |
void cpp3ds::VertexArray::resize | ( | unsigned int | vertexCount | ) |
Resize the vertex array.
If vertexCount is greater than the current size, the previous vertices are kept and new (default-constructed) vertices are added. If vertexCount is less than the current size, existing vertices are removed from the array.
vertexCount | New size of the array (number of vertices) |
void cpp3ds::VertexArray::setPrimitiveType | ( | PrimitiveType | type | ) |
Set the type of primitives to draw.
This function defines how the vertices must be interpreted when it's time to draw them:
type | Type of primitive |