CTriangleArray.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \version 3.2.0 $Rev: 2173 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CTriangleArrayH
46 #define CTriangleArrayH
47 //------------------------------------------------------------------------------
48 #include "graphics/CGenericArray.h"
49 //------------------------------------------------------------------------------
50 
51 //------------------------------------------------------------------------------
52 namespace chai3d {
53 //------------------------------------------------------------------------------
54 
55 //==============================================================================
62 //==============================================================================
63 
64 //------------------------------------------------------------------------------
66 typedef std::shared_ptr<cTriangleArray> cTriangleArrayPtr;
67 //------------------------------------------------------------------------------
68 
69 //==============================================================================
103 //==============================================================================
105 {
106  //--------------------------------------------------------------------------
107  // CONSTRUCTOR & DESTRUCTOR:
108  //--------------------------------------------------------------------------
109 
110 public:
111 
112  //--------------------------------------------------------------------------
118  //--------------------------------------------------------------------------
119  cTriangleArray(cVertexArrayPtr a_vertexArray) : cGenericArray(a_vertexArray)
120  {
121  // clear all triangles
122  clear();
123 
124  // store pointer to vertex array
125  m_vertices = a_vertexArray;
126 
127  // initialize OpenGL buffer ID
128  m_elementBuffer = 0;
129  }
130 
131 
132  //--------------------------------------------------------------------------
136  //--------------------------------------------------------------------------
138 
139 
141  void clear()
142  {
143  m_allocated.clear();
144  m_indices.clear();
145  m_freeElements.clear();
146  m_flagMarkForUpdate = true;
147  m_flagMarkForResize = true;
148  }
149 
150 
152  static cTriangleArrayPtr create(cVertexArrayPtr a_vertexArray) { return (std::make_shared<cTriangleArray>(a_vertexArray)); }
153 
154 
155  //--------------------------------------------------------------------------
156  // PUBLIC METHODS:
157  //--------------------------------------------------------------------------
158 
159 public:
160 
162  virtual unsigned int getNumVerticesPerElement() { return (3); }
163 
165  cTriangleArrayPtr copy();
166 
168  void compress();
169 
170 
171  //--------------------------------------------------------------------------
181  //--------------------------------------------------------------------------
182  int newTriangle(const unsigned int a_vertexIndex0,
183  const unsigned int a_vertexIndex1,
184  const unsigned int a_vertexIndex2)
185  {
186  int index;
187 
188  // check if there is an available slot on the free triangle list
189  if (m_freeElements.size() > 0)
190  {
191  index = m_freeElements.front();
192  m_allocated[index] = true;
193  m_freeElements.pop_front();
194  setVertices(index, a_vertexIndex0, a_vertexIndex1, a_vertexIndex2);
195  }
196  else
197  {
198  // store new indices
199  m_indices.push_back(a_vertexIndex0);
200  m_indices.push_back(a_vertexIndex1);
201  m_indices.push_back(a_vertexIndex2);
202  m_allocated.push_back(true);
203 
204  m_flagMarkForResize = true;
205 
206  // store index of new triangle
207  index = (int)(m_allocated.size())-1;
208  }
209 
210  // mark for update
211  m_flagMarkForUpdate = true;
212 
213  // return index to new triangle
214  return (index);
215  }
216 
217 
218  //--------------------------------------------------------------------------
226  //--------------------------------------------------------------------------
227  void removeTriangle(const unsigned int a_triangleIndex)
228  {
229  // sanity check
230  if (m_allocated[a_triangleIndex])
231  {
232  // disable triangle
233  m_allocated[a_triangleIndex] = false;
234 
235  // reset indices to vertices
236  setVertices(a_triangleIndex, 0, 0, 0);
237 
238  // add triangle to free list
239  m_freeElements.push_back(a_triangleIndex);
240 
241  // mark for update
242  m_flagMarkForUpdate = true;
243  }
244  }
245 
246 
247  //--------------------------------------------------------------------------
257  //--------------------------------------------------------------------------
258  inline void setVertices(const unsigned int a_triangleIndex,
259  const unsigned int a_vertexIndex0,
260  const unsigned int a_vertexIndex1,
261  const unsigned int a_vertexIndex2)
262  {
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;
266 
267  // mark for update
268  m_flagMarkForUpdate = true;
269  }
270 
271 
272  //--------------------------------------------------------------------------
280  //--------------------------------------------------------------------------
281  inline void setVertexIndex0(const unsigned int a_triangleIndex, const unsigned int a_vertexIndex0)
282  {
283  m_indices[3 * a_triangleIndex + 0] = a_vertexIndex0;
284 
285  // mark for update
286  m_flagMarkForUpdate = true;
287  };
288 
289 
290  //--------------------------------------------------------------------------
298  //--------------------------------------------------------------------------
299  inline unsigned int getVertexIndex0(const unsigned int a_triangleIndex) const
300  {
301  return (m_indices[3*a_triangleIndex+0]);
302  };
303 
304 
305  //--------------------------------------------------------------------------
313  //--------------------------------------------------------------------------
314  inline void setVertexIndex1(const unsigned int a_triangleIndex, const unsigned int a_vertexIndex1)
315  {
316  m_indices[3 * a_triangleIndex + 1] = a_vertexIndex1;
317 
318  // mark for update
319  m_flagMarkForUpdate = true;
320  };
321 
322 
323  //--------------------------------------------------------------------------
331  //--------------------------------------------------------------------------
332  inline unsigned int getVertexIndex1(const unsigned int a_triangleIndex) const
333  {
334  return (m_indices[3*a_triangleIndex+1]);
335  };
336 
337 
338  //--------------------------------------------------------------------------
346  //--------------------------------------------------------------------------
347  inline void setVertexIndex2(const unsigned int a_triangleIndex, const unsigned int a_vertexIndex2)
348  {
349  m_indices[3 * a_triangleIndex + 2] = a_vertexIndex2;
350 
351  // mark for update
352  m_flagMarkForUpdate = true;
353  };
354 
355 
356  //--------------------------------------------------------------------------
364  //--------------------------------------------------------------------------
365  inline unsigned int getVertexIndex2(const unsigned int a_triangleIndex) const
366  {
367  return (m_indices[3*a_triangleIndex+2]);
368  };
369 
370 
371  //--------------------------------------------------------------------------
382  //--------------------------------------------------------------------------
383  virtual unsigned int getVertexIndex(const unsigned int a_elementIndex,
384  const unsigned int a_vertexNumber) const
385  {
386  switch (a_vertexNumber)
387  {
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]);
391  default: return (0);
392  }
393  }
394 
395 
396  //--------------------------------------------------------------------------
406  //--------------------------------------------------------------------------
407  cVector3d getTexCoordAtPosition(const unsigned int a_triangleIndex,
408  const cVector3d& a_localPos)
409  {
410  // get vertices of contact triangles
411  cVector3d vertex0 = m_vertices->getLocalPos(getVertexIndex0(a_triangleIndex));
412  cVector3d vertex1 = m_vertices->getLocalPos(getVertexIndex1(a_triangleIndex));
413  cVector3d vertex2 = m_vertices->getLocalPos(getVertexIndex2(a_triangleIndex));
414 
415  // project desired point on triangle
416  cVector3d vertex = cProjectPointOnTriangle(a_localPos, vertex0, vertex1, vertex2);
417 
418  // compute area of triangle
419  double area = cTriangleArea(vertex0, vertex1, vertex2);
420 
421  // compute areas of three sub-triangles formed by the three vertices of the triangle and the contact point.
422  double area0 = cTriangleArea(vertex, vertex1, vertex2);
423  double area1 = cTriangleArea(vertex, vertex0, vertex2);
424  double area2 = cTriangleArea(vertex, vertex0, vertex1);
425 
426  // compute weights based on position of contact point
427  double c0, c1, c2;
428  if (area > 0.0)
429  {
430  c0 = area0/area;
431  c1 = area1/area;
432  c2 = area2/area;
433  }
434  else
435  {
436  c0 = c1 = c2 = (1.0/3.0);
437  }
438 
439  cVector3d texCoord;
440 
441  if (m_vertices->getUseTexCoordData())
442  {
443  // retrieve the texture coordinate for each triangle vertex
444  cVector3d texCoord0 = m_vertices->getTexCoord(getVertexIndex0(a_triangleIndex));
445  cVector3d texCoord1 = m_vertices->getTexCoord(getVertexIndex1(a_triangleIndex));
446  cVector3d texCoord2 = m_vertices->getTexCoord(getVertexIndex2(a_triangleIndex));
447 
448  // compute the exact texture coordinate at the contact point
449  texCoord = cAdd( cMul(c0, texCoord0), cMul(c1, texCoord1), cMul(c2, texCoord2));
450  }
451  else
452  {
453  texCoord.set(0.0, 0.0, 0.0);
454  }
455 
456  // return result
457  return (texCoord);
458  }
459 
460 
461  //--------------------------------------------------------------------------
467  //--------------------------------------------------------------------------
468  void flip(const unsigned int a_triangleIndex)
469  {
470  // sanity check
471  if (m_allocated[a_triangleIndex])
472  {
473  // get vertices 1 and 2
474  unsigned int v1 = getVertexIndex1(a_triangleIndex);
475  unsigned int v2 = getVertexIndex2(a_triangleIndex);
476 
477  // flip vertices 1 and 2
478  setVertexIndex1(a_triangleIndex, v2);
479  setVertexIndex2(a_triangleIndex, v1);
480  }
481  }
482 
483 
484  //--------------------------------------------------------------------------
488  //--------------------------------------------------------------------------
489  inline void computeBTN()
490  {
491  unsigned int numTriangles = getNumElements();
492  for (unsigned i=0; i<numTriangles; i++)
493  {
494  cVector3d T,B;
495 
496  unsigned int index0 = getVertexIndex0(i);
497  unsigned int index1 = getVertexIndex1(i);
498  unsigned int index2 = getVertexIndex2(i);
499 
500  // calculate the vectors from the current vertex to the two other vertices in the triangle
501  cVector3d v1v0 = m_vertices->getLocalPos(index1) - m_vertices->getLocalPos(index0);
502  cVector3d v2v0 = m_vertices->getLocalPos(index2) - m_vertices->getLocalPos(index0);
503 
504  cVector3d tex0 = m_vertices->getTexCoord(index0);
505  cVector3d tex1 = m_vertices->getTexCoord(index1);
506  cVector3d tex2 = m_vertices->getTexCoord(index2);
507 
508  // calculate c1c0_T and c1c0_B
509  double c1c0_T = tex1.x() - tex0.x();
510  double c1c0_B = tex1.y() - tex0.y();
511 
512  // calculate c2c0_T and c2c0_B
513  double c2c0_T = tex2.x() - tex0.x();
514  double c2c0_B = tex2.y() - tex0.y();
515 
516  double fDenominator = c1c0_T * c2c0_B - c2c0_T * c1c0_B;
517  if (fabs(fDenominator) < C_TINY)
518  {
519  // we won't risk a divide by zero, so set the tangent matrix to the identity matrix
520  T = cVector3d(1.0, 0.0, 0.0);
521  B = cVector3d(0.0, 1.0, 0.0);
522  }
523  else
524  {
525  // calculate the reciprocal value once and for all (to achieve speed)
526  double fScale1 = 1.0f / fDenominator;
527 
528  // T and B are calculated just as the equation in the article states
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);
532 
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);
536 
537  // Calculate the reciprocal value once and for all (to achieve speed)
538  /*
539  double fScale2 = 1.0f / ((T.x() * B.y() * N.z() - T.z() * B.y() * N.x()) +
540  (B.x() * N.y() * T.z() - B.z() * N.y() * T.x()) +
541  (N.x() * T.y() * B.z() - N.z() * T.y() * B.x()));
542  */
543 
544  // compute tangent and bi-tangent vector for vertex 0
545  cVector3d N0 = m_vertices->getNormal(index0);
546  cVector3d T0 = cProjectPointOnPlane(T, cVector3d(0, 0, 0), N0);
547  cVector3d B0 = cProjectPointOnPlane(B, cVector3d(0, 0, 0), N0);
548  T0.normalize();
549  B0.normalize();
550  m_vertices->m_tangent[index0] = T0;
551  m_vertices->m_bitangent[index0] = B0;
552 
553  // compute tangent and bi-tangent vector for vertex 1
554  cVector3d N1 = m_vertices->getNormal(index1);
555  cVector3d T1 = cProjectPointOnPlane(T, cVector3d(0, 0, 0), N1);
556  cVector3d B1 = cProjectPointOnPlane(B, cVector3d(0, 0, 0), N1);
557  T1.normalize();
558  B1.normalize();
559  m_vertices->m_tangent[index1] = T1;
560  m_vertices->m_bitangent[index1] = B1;
561 
562  // compute tangent and bi-tangent vector for vertex 2
563  cVector3d N2 = m_vertices->getNormal(index2);
564  cVector3d T2 = cProjectPointOnPlane(T, cVector3d(0, 0, 0), N2);
565  cVector3d B2 = cProjectPointOnPlane(B, cVector3d(0, 0, 0), N2);
566  T2.normalize();
567  B2.normalize();
568  m_vertices->m_tangent[index2] = T2;
569  m_vertices->m_bitangent[index2] = B2;
570 
571  // mark for update
572  m_vertices->m_flagTangentData = true;
573  m_vertices->m_flagBitangentData = true;
574  }
575  }
576  }
577 
578 
579  //--------------------------------------------------------------------------
583  //--------------------------------------------------------------------------
584  inline void renderInitialize()
585  {
586 #ifdef C_USE_OPENGL
587  unsigned int numtriangles = getNumElements();
588 
589  // allocate object and buffers if needed
590  if (m_elementBuffer == 0)
591  {
592  glGenBuffers(1, &m_elementBuffer);
593  }
594 
595  // bind buffer
596  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementBuffer);
597 
598  // update buffer size if needed
600  {
601  glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3 * numtriangles * sizeof(unsigned int), &(m_indices[0]), GL_STATIC_DRAW);
602  m_flagMarkForResize = true;
603  }
604 
605  // update data if needed
607  {
608  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementBuffer);
609  glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 3 * numtriangles * sizeof(unsigned int), &(m_indices[0]));
610 
611  m_flagMarkForUpdate = false;
612  }
613 
614  // initialize rendering of vertices
615  m_vertices->renderInitialize();
616 
617  // render object
618  glEnableClientState(GL_VERTEX_ARRAY);
619  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementBuffer);
620  glDrawElements(GL_TRIANGLES, 3 * numtriangles, GL_UNSIGNED_INT, (void*)0);
621  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
622 #endif
623  }
624 
625  //--------------------------------------------------------------------------
629  //--------------------------------------------------------------------------
630  inline void renderFinalize()
631  {
632 #ifdef C_USE_OPENGL
633  // finalize rendering
634  m_vertices->renderFinalize();
635  glDisableClientState(GL_VERTEX_ARRAY);
636 #endif
637  }
638 
640  virtual bool computeCollision(const unsigned int a_elementIndex,
641  cGenericObject* a_object,
642  cVector3d& a_segmentPointA,
643  cVector3d& a_segmentPointB,
644  cCollisionRecorder& a_recorder,
645  cCollisionSettings& a_settings) const;
646 
647 
648  //--------------------------------------------------------------------------
654  //--------------------------------------------------------------------------
655  inline double computeArea(const unsigned int a_triangleIndex)
656  {
657  // A = 0.5 * | u x v |
658  cVector3d u = m_vertices->getLocalPos(getVertexIndex1(a_triangleIndex)) - m_vertices->getLocalPos(getVertexIndex0(a_triangleIndex));
659  cVector3d v = m_vertices->getLocalPos(getVertexIndex2(a_triangleIndex)) - m_vertices->getLocalPos(getVertexIndex0(a_triangleIndex));
660 
661  return (0.5 * (cCross(u,v).length()));
662  }
663 
664 
665  //--------------------------------------------------------------------------
675  //--------------------------------------------------------------------------
676  cVector3d computeNormal(const unsigned int a_triangleIndex,
677  const bool a_applyNormalToVertices)
678  {
679  // get pointer to vertices
680  int vertex0 = getVertexIndex0(a_triangleIndex);
681  int vertex1 = getVertexIndex1(a_triangleIndex);
682  int vertex2 = getVertexIndex2(a_triangleIndex);
683 
684  // retrieve vertex positions
685  cVector3d pos0 = m_vertices->getLocalPos(vertex0);
686  cVector3d pos1 = m_vertices->getLocalPos(vertex1);
687  cVector3d pos2 = m_vertices->getLocalPos(vertex2);
688 
689  // compute normal vector
690  cVector3d normal, v01, v02;
691  pos1.subr(pos0, v01);
692  pos2.subr(pos0, v02);
693  v01.crossr(v02, normal);
694  double length = normal.length();
695  if (length > 0.0)
696  {
697  normal.div(length);
698  if (a_applyNormalToVertices)
699  {
700  m_vertices->setNormal(vertex0, normal);
701  m_vertices->setNormal(vertex1, normal);
702  m_vertices->setNormal(vertex2, normal);
703  m_vertices->m_flagNormalData = true;
704  }
705  return (normal);
706  }
707 
708  normal.zero();
709  return (normal);
710  }
711 };
712 
713 //------------------------------------------------------------------------------
714 } // namespace chai3d
715 //------------------------------------------------------------------------------
716 
717 //------------------------------------------------------------------------------
718 #endif
719 //------------------------------------------------------------------------------
720 
721 
This class implements a 3D vector.
Definition: CVector3d.h:88
unsigned int getVertexIndex0(const unsigned int a_triangleIndex) const
Definition: CTriangleArray.h:299
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 flip(const unsigned int a_triangleIndex)
Definition: CTriangleArray.h:468
void normalize()
This method normalizes this vector to length 1.
Definition: CVector3d.h:1054
void zero()
This method clears all vector components with zeros.
Definition: CVector3d.h:256
unsigned int getVertexIndex2(const unsigned int a_triangleIndex) const
Definition: CTriangleArray.h:365
void removeTriangle(const unsigned int a_triangleIndex)
Definition: CTriangleArray.h:227
Implements an abstract class for describing elements composed of vertices.
void div(const double &a_scalar)
This method computes the division of this vector with a scalar.
Definition: CVector3d.h:848
void crossr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the cross product.
Definition: CVector3d.h:975
cVector3d cAdd(const cVector3d &a_vector1, const cVector3d &a_vector2)
This function computes the addition of two vectors.
Definition: CMaths.h:708
std::vector< unsigned int > m_indices
Element indices to vertices.
Definition: CGenericArray.h:230
virtual unsigned int getNumVerticesPerElement()
This method returns the number of vertices that compose a triangle.
Definition: CTriangleArray.h:162
std::vector< bool > m_allocated
Element allocation flags.
Definition: CGenericArray.h:233
void setVertexIndex1(const unsigned int a_triangleIndex, const unsigned int a_vertexIndex1)
Definition: CTriangleArray.h:314
~cTriangleArray()
Definition: CTriangleArray.h:137
This class implements an array of 3D triangles.
Definition: CTriangleArray.h:104
double length() const
This method computes the Euclidean norm of this vector.
Definition: CVector3d.h:1015
std::list< unsigned int > m_freeElements
List of free elements.
Definition: CGenericArray.h:259
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
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
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:298
void renderFinalize()
Definition: CTriangleArray.h:630
This class implements a base class for all 2D or 3D objects in CHAI3D.
Definition: CGenericObject.h:112
This class implements a collision detection recorder that stores all collision events that are report...
Definition: CCollisionBasics.h:185
cTriangleArrayPtr copy()
This method copies all triangle data and returns a new triangle array.
Definition: CTriangleArray.cpp:473
cVector3d cMul(const double &a_value, const cVector3d &a_vector)
This function computes the multiplication of a vector by a scalar.
Definition: CMaths.h:824
double computeArea(const unsigned int a_triangleIndex)
Definition: CTriangleArray.h:655
void renderInitialize()
Definition: CTriangleArray.h:584
bool m_flagMarkForUpdate
If true then element data has been modified.
Definition: CGenericArray.h:236
This structure stores the collision settings that are passed to a collision detector when querying fo...
Definition: CCollisionBasics.h:242
cVector3d getTexCoordAtPosition(const unsigned int a_triangleIndex, const cVector3d &a_localPos)
Definition: CTriangleArray.h:407
virtual unsigned int getNumElements()
This method returns the number of allocated elements.
Definition: CGenericArray.h:145
GLuint m_elementBuffer
OpenGL Buffer for storing elements.
Definition: CGenericArray.h:249
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
static cTriangleArrayPtr create(cVertexArrayPtr a_vertexArray)
Shared cTriangleArray allocator.
Definition: CTriangleArray.h:152
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
const double C_TINY
Smallest value near zero for a double.
Definition: CConstants.h:100
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
void setVertexIndex2(const unsigned int a_triangleIndex, const unsigned int a_vertexIndex2)
Definition: CTriangleArray.h:347
void computeBTN()
Definition: CTriangleArray.h:489
std::shared_ptr< cVertexArray > cVertexArrayPtr
Definition: CVertexArray.h:107
void subr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the subtraction of this vector with another.
Definition: CVector3d.h:622
double y() const
This method returns vector component y.
Definition: CVector3d.h:226
double x() const
This method returns vector component x.
Definition: CVector3d.h:220
int newTriangle(const unsigned int a_vertexIndex0, const unsigned int a_vertexIndex1, const unsigned int a_vertexIndex2)
Definition: CTriangleArray.h:182
cTriangleArray(cVertexArrayPtr a_vertexArray)
Definition: CTriangleArray.h:119
void compress()
This method removes all non allocated triangles.
Definition: CTriangleArray.cpp:511
void clear()
Clear all triangles from array.
Definition: CTriangleArray.h:141
cVector3d cCross(const cVector3d &a_vector1, const cVector3d &a_vector2)
This function computes the cross product between two vectors.
Definition: CMaths.h:881
Definition: CAudioBuffer.cpp:56
void setVertexIndex0(const unsigned int a_triangleIndex, const unsigned int a_vertexIndex0)
Definition: CTriangleArray.h:281
This class implements an abstract class for describing geometrical elements composed of vertices...
Definition: CGenericArray.h:90
std::shared_ptr< cTriangleArray > cTriangleArrayPtr
Definition: CTriangleArray.h:65
cVector3d computeNormal(const unsigned int a_triangleIndex, const bool a_applyNormalToVertices)
Definition: CTriangleArray.h:676
bool m_flagMarkForResize
If true then element array size has changed.
Definition: CGenericArray.h:239
double z() const
This method returns vector component z.
Definition: CVector3d.h:232
cVertexArrayPtr m_vertices
Vertex array that contains all vertices used to describe the elements of this array.
Definition: CGenericArray.h:227