45#ifndef CTriangleArrayH
46#define CTriangleArrayH
183 const unsigned int a_vertexIndex1,
184 const unsigned int a_vertexIndex2)
194 setVertices(index, a_vertexIndex0, a_vertexIndex1, a_vertexIndex2);
259 const unsigned int a_vertexIndex0,
260 const unsigned int a_vertexIndex1,
261 const unsigned int a_vertexIndex2)
263 m_indices[3*a_triangleIndex+0] = a_vertexIndex0;
264 m_indices[3*a_triangleIndex+1] = a_vertexIndex1;
265 m_indices[3*a_triangleIndex+2] = a_vertexIndex2;
281 inline void setVertexIndex0(
const unsigned int a_triangleIndex,
const unsigned int a_vertexIndex0)
283 m_indices[3 * a_triangleIndex + 0] = a_vertexIndex0;
314 inline void setVertexIndex1(
const unsigned int a_triangleIndex,
const unsigned int a_vertexIndex1)
316 m_indices[3 * a_triangleIndex + 1] = a_vertexIndex1;
347 inline void setVertexIndex2(
const unsigned int a_triangleIndex,
const unsigned int a_vertexIndex2)
349 m_indices[3 * a_triangleIndex + 2] = a_vertexIndex2;
384 const unsigned int a_vertexNumber)
const
386 switch (a_vertexNumber)
388 case 0:
return (
m_indices[3*a_elementIndex+0]);
389 case 1:
return (
m_indices[3*a_elementIndex+1]);
390 case 2:
return (
m_indices[3*a_elementIndex+2]);
436 c0 = c1 = c2 = (1.0/3.0);
449 texCoord =
cAdd(
cMul(c0, texCoord0),
cMul(c1, texCoord1),
cMul(c2, texCoord2));
453 texCoord.
set(0.0, 0.0, 0.0);
468 void flip(
const unsigned int a_triangleIndex)
492 for (
unsigned i=0; i<numTriangles; i++)
509 double c1c0_T = tex1.
x() - tex0.
x();
510 double c1c0_B = tex1.
y() - tex0.
y();
513 double c2c0_T = tex2.
x() - tex0.
x();
514 double c2c0_B = tex2.
y() - tex0.
y();
516 double fDenominator = c1c0_T * c2c0_B - c2c0_T * c1c0_B;
517 if (fabs(fDenominator) <
C_TINY)
526 double fScale1 = 1.0f / fDenominator;
529 T =
cVector3d((c2c0_B * v1v0.
x() - c1c0_B * v2v0.
x()) * fScale1,
530 (c2c0_B * v1v0.
y() - c1c0_B * v2v0.
y()) * fScale1,
531 (c2c0_B * v1v0.
z() - c1c0_B * v2v0.
z()) * fScale1);
533 B =
cVector3d((-c2c0_T * v1v0.
x() + c1c0_T * v2v0.
x()) * fScale1,
534 (-c2c0_T * v1v0.
y() + c1c0_T * v2v0.
y()) * fScale1,
535 (-c2c0_T * v1v0.
z() + c1c0_T * v2v0.
z()) * fScale1);
601 glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3 * numtriangles *
sizeof(
unsigned int), &(
m_indices[0]), GL_STATIC_DRAW);
609 glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 3 * numtriangles *
sizeof(
unsigned int), &(
m_indices[0]));
618 glEnableClientState(GL_VERTEX_ARRAY);
620 glDrawElements(GL_TRIANGLES, 3 * numtriangles, GL_UNSIGNED_INT, (
void*)0);
621 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
635 glDisableClientState(GL_VERTEX_ARRAY);
661 return (0.5 * (
cCross(u,v).length()));
677 const bool a_applyNormalToVertices)
691 pos1.
subr(pos0, v01);
692 pos2.
subr(pos0, v02);
694 double length = normal.
length();
698 if (a_applyNormalToVertices)
Implements an abstract class for describing elements composed of vertices.
This class implements a collision detection recorder that stores all collision events that are report...
Definition CCollisionBasics.h:186
This class implements an abstract class for describing geometrical elements composed of vertices.
Definition CGenericArray.h:91
GLuint m_elementBuffer
OpenGL Buffer for storing elements.
Definition CGenericArray.h:249
cVertexArrayPtr m_vertices
Vertex array that contains all vertices used to describe the elements of this array.
Definition CGenericArray.h:227
std::list< unsigned int > m_freeElements
List of free elements.
Definition CGenericArray.h:259
bool m_flagMarkForResize
If true then element array size has changed.
Definition CGenericArray.h:239
bool m_flagMarkForUpdate
If true then element data has been modified.
Definition CGenericArray.h:236
virtual unsigned int getNumElements()
This method returns the number of allocated elements.
Definition CGenericArray.h:145
std::vector< unsigned int > m_indices
Element indices to vertices.
Definition CGenericArray.h:230
std::vector< bool > m_allocated
Element allocation flags.
Definition CGenericArray.h:233
This class implements a base class for all 2D or 3D objects in CHAI3D.
Definition CGenericObject.h:113
This class implements an array of 3D triangles.
Definition CTriangleArray.h:105
void compress()
This method removes all non allocated triangles.
Definition CTriangleArray.cpp:511
virtual unsigned int getVertexIndex(const unsigned int a_elementIndex, const unsigned int a_vertexNumber) const
Definition CTriangleArray.h:383
unsigned int getVertexIndex1(const unsigned int a_triangleIndex) const
Definition CTriangleArray.h:332
void renderInitialize()
Definition CTriangleArray.h:584
void renderFinalize()
Definition CTriangleArray.h:630
int newTriangle(const unsigned int a_vertexIndex0, const unsigned int a_vertexIndex1, const unsigned int a_vertexIndex2)
Definition CTriangleArray.h:182
virtual unsigned int getNumVerticesPerElement()
This method returns the number of vertices that compose a triangle.
Definition CTriangleArray.h:162
unsigned int getVertexIndex2(const unsigned int a_triangleIndex) const
Definition CTriangleArray.h:365
cVector3d getTexCoordAtPosition(const unsigned int a_triangleIndex, const cVector3d &a_localPos)
Definition CTriangleArray.h:407
virtual ~cTriangleArray()
Definition CTriangleArray.h:137
void setVertexIndex1(const unsigned int a_triangleIndex, const unsigned int a_vertexIndex1)
Definition CTriangleArray.h:314
void setVertices(const unsigned int a_triangleIndex, const unsigned int a_vertexIndex0, const unsigned int a_vertexIndex1, const unsigned int a_vertexIndex2)
Definition CTriangleArray.h:258
void removeTriangle(const unsigned int a_triangleIndex)
Definition CTriangleArray.h:227
static cTriangleArrayPtr create(cVertexArrayPtr a_vertexArray)
Shared cTriangleArray allocator.
Definition CTriangleArray.h:152
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.
Definition CTriangleArray.cpp:73
cTriangleArray(cVertexArrayPtr a_vertexArray)
Definition CTriangleArray.h:119
void computeBTN()
Definition CTriangleArray.h:489
void clear()
Clear all triangles from array.
Definition CTriangleArray.h:141
void setVertexIndex2(const unsigned int a_triangleIndex, const unsigned int a_vertexIndex2)
Definition CTriangleArray.h:347
double computeArea(const unsigned int a_triangleIndex)
Definition CTriangleArray.h:655
unsigned int getVertexIndex0(const unsigned int a_triangleIndex) const
Definition CTriangleArray.h:299
void flip(const unsigned int a_triangleIndex)
Definition CTriangleArray.h:468
cVector3d computeNormal(const unsigned int a_triangleIndex, const bool a_applyNormalToVertices)
Definition CTriangleArray.h:676
void setVertexIndex0(const unsigned int a_triangleIndex, const unsigned int a_vertexIndex0)
Definition CTriangleArray.h:281
cTriangleArrayPtr copy()
This method copies all triangle data and returns a new triangle array.
Definition CTriangleArray.cpp:473
Definition CAudioBuffer.cpp:57
cVector3d cAdd(const cVector3d &a_vector1, const cVector3d &a_vector2)
This function computes the addition of two vectors.
Definition CMaths.h:771
cVector3d cProjectPointOnTriangle(const cVector3d &a_point, const cVector3d &a_vertex0, const cVector3d &a_vertex1, const cVector3d &a_vertex2)
This function computes the projection of a point onto a triangle.
Definition CGeometry.h:394
cVector3d cCross(const cVector3d &a_vector1, const cVector3d &a_vector2)
This function computes the cross product between two vectors.
Definition CMaths.h:944
double cTriangleArea(const cVector3d &a_vertex0, const cVector3d &a_vertex1, const cVector3d &a_vertex2)
This function computes the area of a triangle.
Definition CGeometry.h:89
cVector3d cMul(const double &a_value, const cVector3d &a_vector)
This function computes the multiplication of a vector by a scalar.
Definition CMaths.h:887
const double C_TINY
Smallest value near zero for a double.
Definition CConstants.h:100
std::shared_ptr< cVertexArray > cVertexArrayPtr
Definition CVertexArray.h:108
std::shared_ptr< cTriangleArray > cTriangleArrayPtr
Definition CTriangleArray.h:66
cVector3d cProjectPointOnPlane(const cVector3d &a_point, const cVector3d &a_planePoint, const cVector3d &a_planeNormal)
This function computes the projection of a point onto a plane.
Definition CGeometry.h:117
This structure stores the collision settings that are passed to a collision detector when querying fo...
Definition CCollisionBasics.h:243
This class implements a 3D vector.
Definition CVector3d.h:89
void div(const double &a_scalar)
This method computes the division of this vector with a scalar.
Definition CVector3d.h:828
void normalize()
This method normalizes this vector to length 1.
Definition CVector3d.h:1034
double y() const
This method returns vector component y.
Definition CVector3d.h:206
void zero()
This method clears all vector components with zeros.
Definition CVector3d.h:236
double z() const
This method returns vector component z.
Definition CVector3d.h:212
void set(const double &a_x, const double &a_y, const double &a_z)
This method initializes this vector with components x, y, and z passed as arguments.
Definition CVector3d.h:278
void crossr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the cross product.
Definition CVector3d.h:955
double x() const
This method returns vector component x.
Definition CVector3d.h:200
double length() const
This method computes the Euclidean norm of this vector.
Definition CVector3d.h:995
void subr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the subtraction of this vector with another.
Definition CVector3d.h:602