CMultiSegment.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: 2161 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CMultiSegmentH
46 #define CMultiSegmentH
47 //------------------------------------------------------------------------------
48 #include "world/CGenericObject.h"
49 #include "materials/CMaterial.h"
50 #include "materials/CTexture2d.h"
51 #include "graphics/CColor.h"
52 //------------------------------------------------------------------------------
53 #include <vector>
54 #include <list>
55 //------------------------------------------------------------------------------
56 
57 //------------------------------------------------------------------------------
58 namespace chai3d {
59 //------------------------------------------------------------------------------
60 
61 //------------------------------------------------------------------------------
62 class cWorld;
63 //------------------------------------------------------------------------------
64 
65 //==============================================================================
72 //==============================================================================
73 
74 //------------------------------------------------------------------------------
76 class cVertexArray;
77 typedef std::shared_ptr<cVertexArray> cVertexArrayPtr;
78 
80 class cSegmentArray;
81 typedef std::shared_ptr<cSegmentArray> cSegmentArrayPtr;
82 //------------------------------------------------------------------------------
83 
84 //==============================================================================
95 //==============================================================================
97 {
98  //--------------------------------------------------------------------------
99  // CONSTRUCTOR & DESTRUCTOR:
100  //--------------------------------------------------------------------------
101 
102 public:
103 
105  cMultiSegment();
106 
108  virtual ~cMultiSegment();
109 
110 
111  //--------------------------------------------------------------------------
112  // PUBLIC METHODS - GENERAL
113  //--------------------------------------------------------------------------
114 
115 public:
116 
118  virtual cMultiSegment* copy(const bool a_duplicateMaterialData = false,
119  const bool a_duplicateTextureData = false,
120  const bool a_duplicateMeshData = false,
121  const bool a_buildCollisionDetector = false);
122 
123 
124  //--------------------------------------------------------------------------
125  // PUBLIC METHODS - VERTICES
126  //--------------------------------------------------------------------------
127 
128 public:
129 
130 
132  unsigned int newVertex(const double a_x = 0.0,
133  const double a_y = 0.0,
134  const double a_z = 0.0);
135 
137  unsigned int newVertex(const cVector3d& a_pos,
138  const cColorf& a_color = cColorf(0,0,0,1));
139 
141  inline unsigned int getNumVertices() const { return (unsigned int)(m_vertices->getNumElements()); }
142 
143 
144  //--------------------------------------------------------------------------
145  // PUBLIC METHODS - SEGMENTS
146  //--------------------------------------------------------------------------
147 
148 public:
149 
151  unsigned int newSegment(const unsigned int a_indexVertex0,
152  const unsigned int a_indexVertex1);
153 
155  unsigned int newSegment(const cVector3d& a_vertex0 = cVector3d(0,0,0),
156  const cVector3d& a_vertex1 = cVector3d(0,0,0),
157  const cColorf& a_colorVertex0 = cColorf(0,0,0,1),
158  const cColorf& a_colorVertex1 = cColorf(0,0,0,1));
159 
161  bool removeSegment(const unsigned int a_index);
162 
164  unsigned int getNumSegments();
165 
167  void clear();
168 
169 
170  //-----------------------------------------------------------------------
171  // PUBLIC METHODS - GRAPHIC PROPERTIES:
172  //-----------------------------------------------------------------------
173 
174 public:
175 
177  virtual void setTransparencyLevel(const float a_level,
178  const bool a_applyToVertices = false,
179  const bool a_applyToTextures = false,
180  const bool a_affectChildren = false);
181 
182 
183  //-----------------------------------------------------------------------
184  // PUBLIC METHODS - DISPLAY LISTS:
185  //-----------------------------------------------------------------------
186 
187 public:
188 
190  virtual void markForUpdate(const bool a_affectChildren = false);
191 
192 
193  //--------------------------------------------------------------------------
194  // PUBLIC METHODS - LINE GRAPHIC PROPERTIES
195  //--------------------------------------------------------------------------
196 
197 public:
198 
200  void setLineColor(const cColorf& a_color);
201 
203  inline void setLineWidth(const double a_lineWidth) { m_lineWidth = fabs(a_lineWidth); }
204 
206  inline double getLineWidth() const { return (m_lineWidth); }
207 
209  void setLineStipple(const GLint a_stippleFactor, const GLushort a_stipplePattern);
210 
212  GLint getLineStippleFactor() { return (m_stippleFactor); }
213 
215  GLushort getLineStipplePattern() { return (m_stipplePattern); }
216 
217 
218  //--------------------------------------------------------------------------
219  // PUBLIC METHODS - COLLISION DETECTION:
220  //--------------------------------------------------------------------------
221 
222 public:
223 
225  virtual void createBruteForceCollisionDetector();
226 
228  virtual void createAABBCollisionDetector(const double a_radius);
229 
230 
231  //--------------------------------------------------------------------------
232  // PUBLIC METHODS - GEOMETRY:
233  //--------------------------------------------------------------------------
234 
235 public:
236 
238  void scaleXYZ(const double a_scaleX, const double a_scaleY, const double a_scaleZ);
239 
241  virtual void offsetVertices(const cVector3d& a_offset,
242  const bool a_updateCollisionDetector = true);
243 
245  virtual cVector3d getCenterOfMass();
246 
247 
248  //--------------------------------------------------------------------------
249  // PROTECTED METHODS - INTERNAL
250  //--------------------------------------------------------------------------
251 
252 protected:
253 
255  virtual void render(cRenderOptions& a_options);
256 
258  virtual void renderSegments(cRenderOptions& a_options);
259 
261  virtual void updateGlobalPositions(const bool a_frameOnly);
262 
264  virtual void updateBoundaryBox();
265 
268  const bool a_duplicateMaterialData = false,
269  const bool a_duplicateTextureData = false,
270  const bool a_duplicateMeshData = false,
271  const bool a_buildCollisionDetector = false);
272 
274  virtual void scaleObject(const double& a_scaleFactor) { scaleXYZ(a_scaleFactor, a_scaleFactor, a_scaleFactor); }
275 
276 
277  //--------------------------------------------------------------------------
278  // PROTECTED MEMBERS - DISPLAY PROPERTIES:
279  //--------------------------------------------------------------------------
280 
281 protected:
282 
285 
287  double m_lineWidth;
288 
291 
294 
295 
296  //--------------------------------------------------------------------------
297  // PUBLIC MEMBERS - SEGMENT AND VERTEX DATA:
298  //--------------------------------------------------------------------------
299 
300 public:
301 
303  cVertexArrayPtr m_vertices;
304 
306  cSegmentArrayPtr m_segments;
307 };
308 
309 //------------------------------------------------------------------------------
310 } // namespace chai3d
311 //------------------------------------------------------------------------------
312 
313 //------------------------------------------------------------------------------
314 #endif
315 //------------------------------------------------------------------------------
316 
This class implements a 3D vector.
Definition: CVector3d.h:88
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition: CRenderOptions.h:82
void clear()
This method clears all segments and vertices.
Definition: CMultiSegment.cpp:383
virtual void createAABBCollisionDetector(const double a_radius)
This method builds an AABB collision detector for this mesh.
Definition: CMultiSegment.cpp:633
This class implements a collection 3D segments.
Definition: CMultiSegment.h:96
GLint getLineStippleFactor()
This method returns the line stipple factor value.
Definition: CMultiSegment.h:212
virtual void render(cRenderOptions &a_options)
This method renders this object graphically using OpenGL.
Definition: CMultiSegment.cpp:658
virtual void renderSegments(cRenderOptions &a_options)
This method rendres all segments.
Definition: CMultiSegment.cpp:691
std::shared_ptr< cSegmentArray > cSegmentArrayPtr
Definition: CSegmentArray.h:65
void setLineColor(const cColorf &a_color)
This method sets the color of all segments.
Definition: CMultiSegment.cpp:496
GLushort getLineStipplePattern()
This method returns the line stipple pattern value.
Definition: CMultiSegment.h:215
virtual void updateGlobalPositions(const bool a_frameOnly)
This method updates the global position of each vertex.
Definition: CMultiSegment.cpp:424
bool removeSegment(const unsigned int a_index)
This method removes a selected segment.
Definition: CMultiSegment.cpp:366
virtual cVector3d getCenterOfMass()
This method computes the center of mass of this object, based on vertex positions.
Definition: CMultiSegment.cpp:215
cSegmentArrayPtr m_segments
Array of triangles.
Definition: CMultiSegment.h:306
virtual cMultiSegment * copy(const bool a_duplicateMaterialData=false, const bool a_duplicateTextureData=false, const bool a_duplicateMeshData=false, const bool a_buildCollisionDetector=false)
This method creates a copy of itself.
Definition: CMultiSegment.cpp:123
virtual ~cMultiSegment()
Destructor of cMultiSegment.
Definition: CMultiSegment.cpp:104
double getLineWidth() const
This method returns the line width.
Definition: CMultiSegment.h:206
double m_lineWidth
Line width.
Definition: CMultiSegment.h:287
virtual void scaleObject(const double &a_scaleFactor)
This method scales this object by a scale factor.
Definition: CMultiSegment.h:274
unsigned int newVertex(const double a_x=0.0, const double a_y=0.0, const double a_z=0.0)
This method creates a new vertex and adds it to the vertex list.
Definition: CMultiSegment.cpp:258
virtual void updateBoundaryBox()
This method updates the boundary box dimensions based on the vertices.
Definition: CMultiSegment.cpp:545
void setLineStipple(const GLint a_stippleFactor, const GLushort a_stipplePattern)
This method specifies the line stipple pattern.
This class implements a base class for all 2D or 3D objects in CHAI3D.
Definition: CGenericObject.h:112
void scaleXYZ(const double a_scaleX, const double a_scaleY, const double a_scaleZ)
This method scales this object by using different scale factors along X,Y and Z axes.
Definition: CMultiSegment.cpp:403
void setLineWidth(const double a_lineWidth)
This method sets the line width of all segments.
Definition: CMultiSegment.h:203
Implements a base class for all objects.
void copyMultiSegmentProperties(cMultiSegment *a_obj, const bool a_duplicateMaterialData=false, const bool a_duplicateTextureData=false, const bool a_duplicateMeshData=false, const bool a_buildCollisionDetector=false)
This method copies all properties of this object to another.
Definition: CMultiSegment.cpp:154
std::shared_ptr< cVertexArray > cVertexArrayPtr
Definition: CVertexArray.h:107
This class defines a color using a GLfloat representation for each component.
Definition: CColor.h:138
Implements color properties.
GLint m_stippleFactor
Specifies a multiplier for each bit in the line stipple pattern.
Definition: CMultiSegment.h:290
cVertexArrayPtr m_vertices
Array of vertices.
Definition: CMultiSegment.h:303
unsigned int getNumSegments()
This method returns the number of stored segments.
Definition: CMultiSegment.cpp:241
Implements material properties.
unsigned int getNumVertices() const
This method returns the number of stored vertices.
Definition: CMultiSegment.h:141
virtual void offsetVertices(const cVector3d &a_offset, const bool a_updateCollisionDetector=true)
This method shifts all vertex positions by the specified amount.
Definition: CMultiSegment.cpp:516
virtual void markForUpdate(const bool a_affectChildren=false)
This method invalidates any existing display lists and marks the mesh for update. ...
Definition: CMultiSegment.cpp:446
bool m_showSegments
If true, then segments are displayed.
Definition: CMultiSegment.h:284
Definition: CAudioBuffer.cpp:56
Implements 2D textures.
virtual void createBruteForceCollisionDetector()
This method builds a brute force collision detector for this mesh.
Definition: CMultiSegment.cpp:611
cMultiSegment()
Constructor of cMultiSegment.
Definition: CMultiSegment.cpp:70
GLushort m_stipplePattern
Specifies a 16-bit integer whose bit pattern determine which fragments of a line will be drawn when t...
Definition: CMultiSegment.h:293
virtual void setTransparencyLevel(const float a_level, const bool a_applyToVertices=false, const bool a_applyToTextures=false, const bool a_affectChildren=false)
This method sets the alpha value at each vertex and in all of my material colors. ...
Definition: CMultiSegment.cpp:467
unsigned int newSegment(const unsigned int a_indexVertex0, const unsigned int a_indexVertex1)
This method creates a new segment by passing two vertex indices.
Definition: CMultiSegment.cpp:306