This class implements an array of 3D triangles. More...
#include <CTriangleArray.h>
Public Member Functions | |
cTriangleArray (cVertexArrayPtr a_vertexArray) | |
~cTriangleArray () | |
void | clear () |
Clear all triangles from array. More... | |
virtual unsigned int | getNumVerticesPerElement () |
This method returns the number of vertices that compose a triangle. More... | |
cTriangleArrayPtr | copy () |
This method copies all triangle data and returns a new triangle array. More... | |
void | compress () |
This method removes all non allocated triangles. More... | |
int | newTriangle (const unsigned int a_vertexIndex0, const unsigned int a_vertexIndex1, const unsigned int a_vertexIndex2) |
void | removeTriangle (const unsigned int a_triangleIndex) |
void | setVertices (const unsigned int a_triangleIndex, const unsigned int a_vertexIndex0, const unsigned int a_vertexIndex1, const unsigned int a_vertexIndex2) |
void | setVertexIndex0 (const unsigned int a_triangleIndex, const unsigned int a_vertexIndex0) |
unsigned int | getVertexIndex0 (const unsigned int a_triangleIndex) const |
void | setVertexIndex1 (const unsigned int a_triangleIndex, const unsigned int a_vertexIndex1) |
unsigned int | getVertexIndex1 (const unsigned int a_triangleIndex) const |
void | setVertexIndex2 (const unsigned int a_triangleIndex, const unsigned int a_vertexIndex2) |
unsigned int | getVertexIndex2 (const unsigned int a_triangleIndex) const |
virtual unsigned int | getVertexIndex (const unsigned int a_elementIndex, const unsigned int a_vertexNumber) const |
cVector3d | getTexCoordAtPosition (const unsigned int a_triangleIndex, const cVector3d &a_localPos) |
void | flip (const unsigned int a_triangleIndex) |
void | computeBTN () |
void | renderInitialize () |
void | renderFinalize () |
virtual bool | computeCollision (const unsigned int a_elementIndex, cGenericObject *a_object, cVector3d &a_segmentPointA, cVector3d &a_segmentPointB, cCollisionRecorder &a_recorder, cCollisionSettings &a_settings) const |
This method checks if the given line segment intersects a selected triangle from this array. More... | |
double | computeArea (const unsigned int a_triangleIndex) |
cVector3d | computeNormal (const unsigned int a_triangleIndex, const bool a_applyNormalToVertices) |
Public Member Functions inherited from chai3d::cGenericArray | |
cGenericArray (cVertexArrayPtr a_vertexArray) | |
~cGenericArray () | |
virtual unsigned int | getNumElements () |
This method returns the number of allocated elements. More... | |
void | compress () |
This method removes non used elements. This compresses the array. More... | |
bool | getAllocated (const unsigned int a_index) const |
cVector3d | getTexCoordAtPosition (const unsigned int a_elementIndex, const cVector3d &a_localPos) |
virtual void | render () |
This method render the OpenGL vertex buffer object. More... | |
Static Public Member Functions | |
static cTriangleArrayPtr | create (cVertexArrayPtr a_vertexArray) |
Shared cTriangleArray allocator. More... | |
Static Public Member Functions inherited from chai3d::cGenericArray | |
static cGenericArrayPtr | create (cVertexArrayPtr a_vertexArray) |
Shared cGenericArray allocator. More... | |
Additional Inherited Members | |
Public Attributes inherited from chai3d::cGenericArray | |
cVertexArrayPtr | m_vertices |
Vertex array that contains all vertices used to describe the elements of this array. More... | |
std::vector< unsigned int > | m_indices |
Element indices to vertices. More... | |
std::vector< bool > | m_allocated |
Element allocation flags. More... | |
bool | m_flagMarkForUpdate |
If true then element data has been modified. More... | |
bool | m_flagMarkForResize |
If true then element array size has changed. More... | |
GLuint | m_elementBuffer |
OpenGL Buffer for storing elements. More... | |
Protected Attributes inherited from chai3d::cGenericArray | |
std::list< unsigned int > | m_freeElements |
List of free elements. More... | |
cTriangleArray defines an array of triangles, typically bound to a mesh for describing its geometry.
A triangle array is created by first passing a reference to an array of vertices (cVertexArray) from which the triangles are composed.
Every triangle is described by a set of three vertex indices. The indices point to the vertices, or points, that describe the shape of the triangle.
For graphic rendering purposes and memory efficiency, triangles are stored in large arrays. The number of allocated triangles in an array can be retrieved by call getNumElements().
New triangles can be added or removed by calling newTriangle() and removeTriangle(). respectively.
When a triangle is removed from the array, the vertex indices are set to zero and the triangle index number is added to a list of free triangles for future allocation. Triangles are therefore never removed from memory, but become a point until they are converted to an active triangle again.
To avoid accumulating large numbers of free triangles, it is possible to compress the array by calling compress(). This method removes all non used triangles from memory.
|
inline |
Constructor of cTriangleArray.
a_vertexArray | Array of vertices used to describe the triangles. |
|
inline |
Destructor of cTriangleArray.
|
inlinevirtual |
Reimplemented from chai3d::cGenericArray.
|
inlinestatic |
|
inlinevirtual |
Reimplemented from chai3d::cGenericArray.
cTriangleArrayPtr chai3d::cTriangleArray::copy | ( | ) |
This method copies all allocated triangles. Please note that this method does copy triangles that were previously deallocated.
void chai3d::cTriangleArray::compress | ( | ) |
This method compressed the triangle array by removing all non allocated triangles. If many triangles are unused, this method can effectively reduce the memory footprint allocated by the array.
IMPORTANT:
After calling this method, it is important to immediately update any collision detector as the collision tree may try to access triangles that no longer exist.
|
inline |
This method creates a new triangle.
a_vertexIndex0 | index of vertex 0. |
a_vertexIndex1 | index of vertex 1. |
a_vertexIndex2 | index of vertex 2. |
|
inline |
This method deallocates a selected triangle from the array. The three vertices of the triangle are set to zero, and the triangle is added to the free list for future allocation.
a_triangleIndex | Index of selected triangle. |
|
inline |
This method set the vertices of a selected triangle by passing their index numbers.
a_triangleIndex | Index of selected triangle. |
a_vertexIndex0 | Index of vertex 0. |
a_vertexIndex1 | Index of vertex 1. |
a_vertexIndex2 | Index of vertex 2. |
|
inline |
This method sets vertex 0 of a selected triangle by passing their index numbers.
a_triangleIndex | Index of triangle. |
a_vertexIndex0 | Index of vertex 0. |
|
inline |
This method returns the index of vertex 0 of a selected triangle.
a_triangleIndex | Index of triangle. |
|
inline |
This method sets vertex 1 of a selected triangle by passing their index numbers.
a_triangleIndex | Index of triangle. |
a_vertexIndex1 | Index of vertex 1. |
|
inline |
This method returns the index of vertex 1 of a selected triangle.
a_triangleIndex | Index of selected triangle. |
|
inline |
This method sets vertex 2 of a selected triangle by passing their index numbers.
a_triangleIndex | Index of triangle. |
a_vertexIndex2 | Index of vertex 2. |
|
inline |
This method returns the index of vertex 2 of a selected triangle.
a_triangleIndex | Index of triangle. |
|
inlinevirtual |
This method returns the index number of a selected vertex for a selected triangle. In the case of a triangle a_vertexNumber takes either 0, 1 or 2.
a_elementIndex | Index number of selected triangle. |
a_vertexNumber | Vertex number. |
Reimplemented from chai3d::cGenericArray.
|
inline |
This method returns the texture coordinate at the nearest point on the triangle from an input location.
a_triangleIndex | Index number of selected triangle. |
a_localPos | Local point on triangle. |
|
inline |
This method flips the vertices of the triangle.
a_triangleIndex | Index number of selected triangle. |
|
inline |
This method computes the normal matrix vectors for all triangles.
|
inline |
This method renders the OpenGL vertex buffer object.
|
inline |
This method finalizes rendering the OpenGL vertex buffer object.
|
virtual |
This method checks if the given line segment intersects a selected a triangle from this array.
If a collision occurs, the collision point is reported in the collision recorder.
a_elementIndex | Triangle index number. |
a_object | Pointer to the object on which collision detection is being performed. |
a_segmentPointA | Point from where collision ray starts (in local frame). |
a_segmentPointB | Direction vector of collision ray (in local frame). |
a_recorder | Stores collision events |
a_settings | Collision detector settings. |
Reimplemented from chai3d::cGenericArray.
|
inline |
This method computes and returns the area for a selected triangle.
|
inline |
This method computes the surface normal of a triangle and if requested, updates the normal of each of the three vertices.
a_triangleIndex | Index number of selected triangle. |
a_applyNormalToVertices | If true, then update normal of each vertex. |