This class implements an array of 3D segments. More...
#include <CSegmentArray.h>
Public Member Functions | |
cSegmentArray (cVertexArrayPtr a_vertexArray) | |
~cSegmentArray () | |
void | clear () |
This method clears all segments from array. More... | |
virtual unsigned int | getNumVerticesPerElement () |
This method returns the number of vertices that compose a segment. More... | |
cSegmentArrayPtr | copy () |
This method create a copy of all segment data and returns a new segment array. More... | |
void | compress () |
This method compresses the array by removing non used segments. More... | |
int | newSegment (const unsigned int a_vertexIndex0, const unsigned int a_vertexIndex1) |
void | removeSegment (const unsigned int a_segmentIndex) |
void | setVertices (const unsigned int a_segmentIndex, const unsigned int a_vertexIndex0, const unsigned int a_vertexIndex1) |
unsigned int | getVertexIndex0 (const unsigned int a_segmentIndex) const |
unsigned int | getVertexIndex1 (const unsigned int a_segmentIndex) const |
virtual unsigned int | getVertexIndex (const unsigned int a_elementIndex, const unsigned int a_vertexNumber) const |
cVector3d | getTexCoordAtPosition (const unsigned int a_segmentIndex, const cVector3d &a_localPos) |
void | render () |
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 segment from this array. More... | |
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) |
Static Public Member Functions | |
static cSegmentArrayPtr | create (cVertexArrayPtr a_vertexArray) |
Shared cSegmentArray 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... | |
This class defines an array of segments each composed of two vertices.
A segment array is created by first passing a reference to an array of vertices (cVertexArray) from which the segments are composed.
Every segment is described by a set of two vertex indices. The indices point to the vertices that describe the segment.
For graphic rendering purposes and memory efficiency, segments are stored in large arrays. The number of allocated segments in an array can be retrieved by call getNumElements().
New segments can be added or removed by calling newSegment() and removeSegment(). respectively.
When a segment is removed from the array, the vertex indices are set to zero and the segment index number is added to a list of free segments for future allocation. Segments are therefore never removed from memory, but become a point until they are converted to an active segment again.
To avoid accumulating large numbers of free segments, it is possible to compress the array by calling compress(). This method removes all non used segments from memory.
|
inline |
Constructor of cSegmentArray.
a_vertexArray | Array of vertices used to describe the segments. |
|
inline |
Destructor of cSegmentArray.
|
inlinevirtual |
Reimplemented from chai3d::cGenericArray.
|
inlinestatic |
|
inlinevirtual |
Reimplemented from chai3d::cGenericArray.
cSegmentArrayPtr chai3d::cSegmentArray::copy | ( | ) |
This method copies all allocated segments. Please note that this method does not copy segments that were previously deallocated.
void chai3d::cSegmentArray::compress | ( | ) |
This method compresses the segment array by removing all non allocated segments. If many segments 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 segments that no longer exist.
|
inline |
This method creates a new segment.
a_vertexIndex0 | index of vertex 0. |
a_vertexIndex1 | index of vertex 1. |
|
inline |
This method deallocates a selected segment from the array. The two vertex indices of the segment are set to zero, and the segment is added to the free list for future allocation.
a_segmentIndex | Index number of selected segment. |
|
inline |
This method sets the vertices of a selected segment by passing their index numbers.
a_segmentIndex | Index of selected segment. |
a_vertexIndex0 | Index of vertex 0. |
a_vertexIndex1 | Index of vertex 1. |
|
inline |
This method returns the index of vertex 0 of a selected segment.
a_segmentIndex | Index of segment. |
|
inline |
This method returns index of vertex 1 of a selected segment.
a_segmentIndex | Index of selected segment. |
|
inlinevirtual |
This method returns the index number of a selected vertex for a selected segment. In the case of a segment a_vertexNumber takes either 0 or 1.
a_elementIndex | Index number of selected segment. |
a_vertexNumber | Vertex number. |
Reimplemented from chai3d::cGenericArray.
|
inline |
This method returns the texture coordinate at the nearest point on the segment from a location passed as argument.
a_segmentIndex | Index number of selected segment. |
a_localPos | Local point along the segment. |
|
inlinevirtual |
This method renders the OpenGL vertex buffer object.
Reimplemented from chai3d::cGenericArray.
|
virtual |
This method checks if the given line segment intersects a selected segment from this array.
If a collision occurs, the collision point is reported through the collision recorder.
a_elementIndex | Segment 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 detection settings. |
Reimplemented from chai3d::cGenericArray.