CGenericArray.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: 2015 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CGenericArrayH
46 #define CGenericArrayH
47 //------------------------------------------------------------------------------
48 #include "math/CGeometry.h"
49 #include "graphics/CVertexArray.h"
50 //------------------------------------------------------------------------------
51 namespace chai3d {
52 //------------------------------------------------------------------------------
53 
54 //------------------------------------------------------------------------------
55 class cGenericObject;
56 class cCollisionRecorder;
57 struct cCollisionSettings;
58 //------------------------------------------------------------------------------
59 
60 //==============================================================================
67 //==============================================================================
68 
69 //------------------------------------------------------------------------------
71 typedef std::shared_ptr<cGenericArray> cGenericArrayPtr;
72 //------------------------------------------------------------------------------
73 
74 //==============================================================================
89 //==============================================================================
91 {
92  //--------------------------------------------------------------------------
93  // CONSTRUCTOR & DESTRUCTOR:
94  //--------------------------------------------------------------------------
95 
96 public:
97 
98  //--------------------------------------------------------------------------
104  //--------------------------------------------------------------------------
106  {
107  // clear all elements
108  clear();
109 
110  // initialize OpenGL buffer ID
111  m_elementBuffer = 0;
112  }
113 
114 
115  //--------------------------------------------------------------------------
119  //--------------------------------------------------------------------------
121 
122 
124  virtual void clear()
125  {
126  m_allocated.clear();
127  m_indices.clear();
128  m_freeElements.clear();
129  m_flagMarkForUpdate = true;
130  m_flagMarkForResize = true;
131  }
132 
133 
135  static cGenericArrayPtr create(cVertexArrayPtr a_vertexArray) { return (std::make_shared<cGenericArray>(a_vertexArray)); }
136 
137 
138  //--------------------------------------------------------------------------
139  // PUBLIC METHODS:
140  //--------------------------------------------------------------------------
141 
142 public:
143 
145  virtual unsigned int getNumElements() { return (unsigned int)(m_allocated.size()); }
146 
148  virtual unsigned int getNumVerticesPerElement() { return (1); }
149 
151  void compress();
152 
153 
154  //--------------------------------------------------------------------------
160  //--------------------------------------------------------------------------
161  inline bool getAllocated(const unsigned int a_index) const
162  {
163  return (m_allocated[a_index]);
164  };
165 
166 
167  //--------------------------------------------------------------------------
179  //--------------------------------------------------------------------------
180  virtual unsigned int getVertexIndex(const unsigned int a_elementIndex,
181  const unsigned int a_vertexNumber) const
182  {
183  return (0);
184  }
185 
186 
187  //--------------------------------------------------------------------------
197  //--------------------------------------------------------------------------
198  cVector3d getTexCoordAtPosition(const unsigned int a_elementIndex,
199  const cVector3d& a_localPos)
200  {
201  cVector3d texCoord(0.0, 0.0, 0.0);
202  return (texCoord);
203  }
204 
205 
207  virtual void render()
208  {
209  }
210 
212  virtual bool computeCollision(const unsigned int a_elementIndex,
213  cGenericObject* a_object,
214  cVector3d& a_segmentPointA,
215  cVector3d& a_segmentPointB,
216  cCollisionRecorder& a_recorder,
217  cCollisionSettings& a_settings) const { return (false); }
218 
219 
220  //--------------------------------------------------------------------------
221  // PUBLIC MEMBERS:
222  //--------------------------------------------------------------------------
223 
224 public:
225 
228 
230  std::vector<unsigned int> m_indices;
231 
233  std::vector<bool> m_allocated;
234 
237 
240 
241 
242  //--------------------------------------------------------------------------
243  // PUBLIC MEMBERS: (OPENGL)
244  //--------------------------------------------------------------------------
245 
246 public:
247 
250 
251 
252  //--------------------------------------------------------------------------
253  // PROTECTED MEMBERS:
254  //--------------------------------------------------------------------------
255 
256 protected:
257 
259  std::list<unsigned int> m_freeElements;
260 };
261 
262 //------------------------------------------------------------------------------
263 } // namespace chai3d
264 //------------------------------------------------------------------------------
265 
266 //------------------------------------------------------------------------------
267 #endif
268 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:88
bool getAllocated(const unsigned int a_index) const
Definition: CGenericArray.h:161
Implements an array of 3D vertices.
std::vector< unsigned int > m_indices
Element indices to vertices.
Definition: CGenericArray.h:230
Implements general geometry utility functions.
std::vector< bool > m_allocated
Element allocation flags.
Definition: CGenericArray.h:233
cGenericArray(cVertexArrayPtr a_vertexArray)
Definition: CGenericArray.h:105
std::list< unsigned int > m_freeElements
List of free elements.
Definition: CGenericArray.h:259
virtual void render()
This method render the OpenGL vertex buffer object.
Definition: CGenericArray.h:207
This class implements a base class for all 2D or 3D objects in CHAI3D.
Definition: CGenericObject.h:112
cVector3d getTexCoordAtPosition(const unsigned int a_elementIndex, const cVector3d &a_localPos)
Definition: CGenericArray.h:198
This class implements a collision detection recorder that stores all collision events that are report...
Definition: CCollisionBasics.h:185
virtual unsigned int getVertexIndex(const unsigned int a_elementIndex, const unsigned int a_vertexNumber) const
Definition: CGenericArray.h:180
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
static cGenericArrayPtr create(cVertexArrayPtr a_vertexArray)
Shared cGenericArray allocator.
Definition: CGenericArray.h:135
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
~cGenericArray()
Definition: CGenericArray.h:120
std::shared_ptr< cVertexArray > cVertexArrayPtr
Definition: CVertexArray.h:107
virtual unsigned int getNumVerticesPerElement()
This method returns the number of vertices per element.
Definition: CGenericArray.h:148
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 element from this array...
Definition: CGenericArray.h:212
Definition: CAudioBuffer.cpp:56
This class implements an abstract class for describing geometrical elements composed of vertices...
Definition: CGenericArray.h:90
void compress()
This method removes non used elements. This compresses the array.
std::shared_ptr< cGenericArray > cGenericArrayPtr
Definition: CGenericArray.h:70
bool m_flagMarkForResize
If true then element array size has changed.
Definition: CGenericArray.h:239
virtual void clear()
This method clear all elements of array.
Definition: CGenericArray.h:124
cVertexArrayPtr m_vertices
Vertex array that contains all vertices used to describe the elements of this array.
Definition: CGenericArray.h:227