CHAI3D  3.0.0
CMultiSegment.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2015, 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  \author Dan Morris
41  \author Chris Sewell
42  \version 3.0.0 $Rev: 1502 $
43 */
44 //==============================================================================
45 
46 //------------------------------------------------------------------------------
47 #ifndef CMultiSegmentH
48 #define CMultiSegmentH
49 //------------------------------------------------------------------------------
50 #include "world/CGenericObject.h"
51 #include "materials/CMaterial.h"
52 #include "materials/CTexture2d.h"
53 #include "graphics/CColor.h"
54 //------------------------------------------------------------------------------
55 #include <vector>
56 #include <list>
57 //------------------------------------------------------------------------------
58 
59 //------------------------------------------------------------------------------
60 namespace chai3d {
61 //------------------------------------------------------------------------------
62 
63 //------------------------------------------------------------------------------
64 class cWorld;
65 //------------------------------------------------------------------------------
66 
67 //==============================================================================
74 //==============================================================================
75 
76 //------------------------------------------------------------------------------
78 class cVertexArray;
79 typedef std::shared_ptr<cVertexArray> cVertexArrayPtr;
80 
82 class cSegmentArray;
83 typedef std::shared_ptr<cSegmentArray> cSegmentArrayPtr;
84 //------------------------------------------------------------------------------
85 
86 //==============================================================================
97 //==============================================================================
99 {
100  //--------------------------------------------------------------------------
101  // CONSTRUCTOR & DESTRUCTOR:
102  //--------------------------------------------------------------------------
103 
104 public:
105 
107  cMultiSegment();
108 
110  virtual ~cMultiSegment();
111 
112 
113  //--------------------------------------------------------------------------
114  // PUBLIC METHODS - GENERAL
115  //--------------------------------------------------------------------------
116 
117 public:
118 
120  virtual cMultiSegment* copy(const bool a_duplicateMaterialData = false,
121  const bool a_duplicateTextureData = false,
122  const bool a_duplicateMeshData = false,
123  const bool a_buildCollisionDetector = false);
124 
125 
126  //--------------------------------------------------------------------------
127  // PUBLIC METHODS - VERTICES
128  //--------------------------------------------------------------------------
129 
130 public:
131 
132 
134  unsigned int newVertex(const double a_x = 0.0,
135  const double a_y = 0.0,
136  const double a_z = 0.0);
137 
139  unsigned int newVertex(const cVector3d& a_pos,
140  const cColorf& a_color = cColorf(0,0,0,1));
141 
143  inline unsigned int getNumVertices() const { return (unsigned int)(m_vertices->getNumVertices()); }
144 
145 
146  //--------------------------------------------------------------------------
147  // PUBLIC METHODS - SEGMENTS
148  //--------------------------------------------------------------------------
149 
150 public:
151 
153  unsigned int newSegment(const unsigned int a_indexVertex0,
154  const unsigned int a_indexVertex1);
155 
157  unsigned int newSegment(const cVector3d& a_vertex0 = cVector3d(0,0,0),
158  const cVector3d& a_vertex1 = cVector3d(0,0,0),
159  const cColorf& a_colorVertex0 = cColorf(0,0,0,1),
160  const cColorf& a_colorVertex1 = cColorf(0,0,0,1));
161 
163  bool removeSegment(const unsigned int a_index);
164 
166  unsigned int getNumSegments();
167 
169  void clear();
170 
171 
172  //-----------------------------------------------------------------------
173  // PUBLIC METHODS - GRAPHIC PROPERTIES:
174  //-----------------------------------------------------------------------
175 
176 public:
177 
179  virtual void setTransparencyLevel(const float a_level,
180  const bool a_applyToTextures = false,
181  const bool a_affectChildren = false);
182 
183 
184  //-----------------------------------------------------------------------
185  // PUBLIC METHODS - DISPLAY LISTS:
186  //-----------------------------------------------------------------------
187 
188 public:
189 
191  virtual void markForUpdate(const bool a_affectChildren = false);
192 
193 
194  //--------------------------------------------------------------------------
195  // PUBLIC METHODS - LINE GRAPHIC PROPERTIES
196  //--------------------------------------------------------------------------
197 
198 public:
199 
201  void setLineColor(const cColorf& a_color);
202 
204  inline void setLineWidth(const double a_lineWidth) { m_lineWidth = fabs(a_lineWidth); }
205 
207  inline double getLineWidth() const { return (m_lineWidth); }
208 
210  void setLineStipple(const GLint a_stippleFactor, const GLushort a_stipplePattern);
211 
213  GLint getLineStippleFactor() { return (m_stippleFactor); }
214 
216  GLushort getLineStipplePattern() { return (m_stipplePattern); }
217 
218 
219  //--------------------------------------------------------------------------
220  // PUBLIC METHODS - COLLISION DETECTION:
221  //--------------------------------------------------------------------------
222 
223 public:
224 
226  virtual void createBruteForceCollisionDetector();
227 
229  virtual void createAABBCollisionDetector(const double a_radius);
230 
231 
232  //--------------------------------------------------------------------------
233  // PUBLIC METHODS - GEOMETRY:
234  //--------------------------------------------------------------------------
235 
236 public:
237 
239  void scaleXYZ(const double a_scaleX, const double a_scaleY, const double a_scaleZ);
240 
242  virtual void offsetVertices(const cVector3d& a_offset,
243  const bool a_updateCollisionDetector = true);
244 
246  virtual cVector3d getCenterOfMass();
247 
248 
249  //--------------------------------------------------------------------------
250  // PROTECTED METHODS - INTERNAL
251  //--------------------------------------------------------------------------
252 
253 protected:
254 
256  virtual void render(cRenderOptions& a_options);
257 
259  virtual void renderSegments(cRenderOptions& a_options);
260 
262  virtual void updateGlobalPositions(const bool a_frameOnly);
263 
265  virtual void updateBoundaryBox();
266 
269  const bool a_duplicateMaterialData = false,
270  const bool a_duplicateTextureData = false,
271  const bool a_duplicateMeshData = false,
272  const bool a_buildCollisionDetector = false);
273 
275  virtual void scaleObject(const double& a_scaleFactor) { scaleXYZ(a_scaleFactor, a_scaleFactor, a_scaleFactor); }
276 
277 
278  //--------------------------------------------------------------------------
279  // PROTECTED MEMBERS - DISPLAY PROPERTIES:
280  //--------------------------------------------------------------------------
281 
282 protected:
283 
286 
288  double m_lineWidth;
289 
292 
295 
296 
297  //--------------------------------------------------------------------------
298  // PUBLIC MEMBERS - SEGMENT AND VERTEX DATA:
299  //--------------------------------------------------------------------------
300 
301 public:
302 
304  cVertexArrayPtr m_vertices;
305 
307  cSegmentArrayPtr m_segments;
308 };
309 
310 //------------------------------------------------------------------------------
311 } // namespace chai3d
312 //------------------------------------------------------------------------------
313 
314 //------------------------------------------------------------------------------
315 #endif
316 //------------------------------------------------------------------------------
317 
This class implements a 3D vector.
Definition: CVector3d.h:85
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:630
This class implements a collection 3D segments.
Definition: CMultiSegment.h:98
GLint getLineStippleFactor()
This method returns the line stipple factor value.
Definition: CMultiSegment.h:213
virtual void render(cRenderOptions &a_options)
This method renders this object graphically using OpenGL.
Definition: CMultiSegment.cpp:655
virtual void renderSegments(cRenderOptions &a_options)
This method rendres all segments.
Definition: CMultiSegment.cpp:688
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:489
GLushort getLineStipplePattern()
This method returns the line stipple pattern value.
Definition: CMultiSegment.h:216
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:307
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:207
double m_lineWidth
Line width.
Definition: CMultiSegment.h:288
virtual void scaleObject(const double &a_scaleFactor)
This method scales this object by a scale factor.
Definition: CMultiSegment.h:275
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:538
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:204
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:291
cVertexArrayPtr m_vertices
Array of vertices.
Definition: CMultiSegment.h:304
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:143
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:509
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:285
Definition: CAudioBuffer.cpp:56
Implements 2D textures.
virtual void setTransparencyLevel(const float a_level, 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:466
virtual void createBruteForceCollisionDetector()
This method builds a brute force collision detector for this mesh.
Definition: CMultiSegment.cpp:604
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:294
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

CHAI3D 3.0.0 documentation
Please address any questions to support@chai3d.org
(C) 2003-2015 - CHAI3D
All Rights Reserved.