My Project
Loading...
Searching...
No Matches
CMultiSegment.h
Go to the documentation of this file.
1//==============================================================================
2/*
3 Software License Agreement (BSD License)
4 Copyright (c) 2003-2024, 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.3.0
41*/
42//==============================================================================
43
44//------------------------------------------------------------------------------
45#ifndef CMultiSegmentH
46#define CMultiSegmentH
47//------------------------------------------------------------------------------
49#include "materials/CMaterial.h"
51#include "graphics/CColor.h"
52//------------------------------------------------------------------------------
53#include <vector>
54#include <list>
55//------------------------------------------------------------------------------
56
57//------------------------------------------------------------------------------
58namespace chai3d {
59//------------------------------------------------------------------------------
60
61//------------------------------------------------------------------------------
62class cWorld;
63//------------------------------------------------------------------------------
64
65//==============================================================================
72//==============================================================================
73
74//------------------------------------------------------------------------------
76class cVertexArray;
77typedef std::shared_ptr<cVertexArray> cVertexArrayPtr;
78
80class cSegmentArray;
81typedef std::shared_ptr<cSegmentArray> cSegmentArrayPtr;
82//------------------------------------------------------------------------------
83
84//==============================================================================
95//==============================================================================
97{
98 //--------------------------------------------------------------------------
99 // CONSTRUCTOR & DESTRUCTOR:
100 //--------------------------------------------------------------------------
101
102public:
103
106
108 virtual ~cMultiSegment();
109
110
111 //--------------------------------------------------------------------------
112 // PUBLIC METHODS - GENERAL
113 //--------------------------------------------------------------------------
114
115public:
116
118 virtual std::string getClassName() { return ("MultiSegment"); }
119
121 virtual cMultiSegment* copy(const bool a_duplicateMaterialData = false,
122 const bool a_duplicateTextureData = false,
123 const bool a_duplicateMeshData = false,
124 const bool a_buildCollisionDetector = false);
125
126
127 //--------------------------------------------------------------------------
128 // PUBLIC METHODS - VERTICES
129 //--------------------------------------------------------------------------
130
131public:
132
133
135 unsigned int newVertex(const double a_x = 0.0,
136 const double a_y = 0.0,
137 const double a_z = 0.0);
138
140 unsigned int newVertex(const cVector3d& a_pos,
141 const cColorf& a_color = cColorf(0,0,0,1));
142
144 inline unsigned int getNumVertices() const { return (unsigned int)(m_vertices->getNumElements()); }
145
146
147 //--------------------------------------------------------------------------
148 // PUBLIC METHODS - SEGMENTS
149 //--------------------------------------------------------------------------
150
151public:
152
154 unsigned int newSegment(const unsigned int a_indexVertex0,
155 const unsigned int a_indexVertex1);
156
158 unsigned int newSegment(const cVector3d& a_vertex0 = cVector3d(0,0,0),
159 const cVector3d& a_vertex1 = cVector3d(0,0,0),
160 const cColorf& a_colorVertex0 = cColorf(0,0,0,1),
161 const cColorf& a_colorVertex1 = cColorf(0,0,0,1));
162
164 bool removeSegment(const unsigned int a_index);
165
167 unsigned int getNumSegments();
168
170 void clear();
171
172
173 //-----------------------------------------------------------------------
174 // PUBLIC METHODS - GRAPHIC PROPERTIES:
175 //-----------------------------------------------------------------------
176
177public:
178
180 virtual void setTransparencyLevel(const float a_level,
181 const bool a_applyToVertices = false,
182 const bool a_applyToTextures = false,
183 const bool a_affectChildren = false,
184 const bool a_affectComponents = true);
185
186
187 //-----------------------------------------------------------------------
188 // PUBLIC METHODS - DISPLAY LISTS:
189 //-----------------------------------------------------------------------
190
191public:
192
194 virtual void markForUpdate(const bool a_affectChildren = false, const bool a_affectComponents = true);
195
196
197 //--------------------------------------------------------------------------
198 // PUBLIC METHODS - LINE GRAPHIC PROPERTIES
199 //--------------------------------------------------------------------------
200
201public:
202
204 void setLineColor(const cColorf& a_color);
205
207 inline void setLineWidth(const double a_lineWidth) { m_lineWidth = fabs(a_lineWidth); }
208
210 inline double getLineWidth() const { return (m_lineWidth); }
211
213 void setLineStipple(const GLint a_stippleFactor, const GLushort a_stipplePattern);
214
217
220
221
222 //--------------------------------------------------------------------------
223 // PUBLIC METHODS - COLLISION DETECTION:
224 //--------------------------------------------------------------------------
225
226public:
227
230
232 virtual void createAABBCollisionDetector(const double a_radius);
233
234
235 //--------------------------------------------------------------------------
236 // PUBLIC METHODS - GEOMETRY:
237 //--------------------------------------------------------------------------
238
239public:
240
242 void scaleXYZ(const double a_scaleX, const double a_scaleY, const double a_scaleZ);
243
245 virtual void offsetVertices(const cVector3d& a_offset,
246 const bool a_updateCollisionDetector = true);
247
249 virtual cVector3d getCenterOfMass();
250
251
252 //--------------------------------------------------------------------------
253 // PROTECTED METHODS - INTERNAL
254 //--------------------------------------------------------------------------
255
256protected:
257
259 virtual void render(cRenderOptions& a_options);
260
262 virtual void renderSegments(cRenderOptions& a_options);
263
265 virtual void updateGlobalPositions(const bool a_frameOnly);
266
268 virtual void updateBoundaryBox();
269
272 const bool a_duplicateMaterialData = false,
273 const bool a_duplicateTextureData = false,
274 const bool a_duplicateMeshData = false,
275 const bool a_buildCollisionDetector = false);
276
278 virtual void scaleObject(const double& a_scaleFactor) { scaleXYZ(a_scaleFactor, a_scaleFactor, a_scaleFactor); }
279
280
281 //--------------------------------------------------------------------------
282 // PROTECTED MEMBERS - DISPLAY PROPERTIES:
283 //--------------------------------------------------------------------------
284
285protected:
286
289
292
295
298
299
300 //--------------------------------------------------------------------------
301 // PUBLIC MEMBERS - SEGMENT AND VERTEX DATA:
302 //--------------------------------------------------------------------------
303
304public:
305
308
311};
312
313//------------------------------------------------------------------------------
314} // namespace chai3d
315//------------------------------------------------------------------------------
316
317//------------------------------------------------------------------------------
318#endif
319//------------------------------------------------------------------------------
320
Implements color properties.
Implements a base class for all objects.
Implements material properties.
Implements 2D textures.
This class implements a base class for all 2D or 3D objects in CHAI3D.
Definition CGenericObject.h:113
This class implements a collection 3D segments.
Definition CMultiSegment.h:97
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:297
GLushort getLineStipplePattern()
This method returns the line stipple pattern value.
Definition CMultiSegment.h:219
unsigned int getNumSegments()
This method returns the number of stored segments.
Definition CMultiSegment.cpp:241
double getLineWidth() const
This method returns the line width.
Definition CMultiSegment.h:210
virtual void updateBoundaryBox()
This method updates the boundary box dimensions based on the vertices.
Definition CMultiSegment.cpp:548
GLint getLineStippleFactor()
This method returns the line stipple factor value.
Definition CMultiSegment.h:216
void clear()
This method clears all segments and vertices.
Definition CMultiSegment.cpp:383
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
double m_lineWidth
Line width.
Definition CMultiSegment.h:291
virtual void scaleObject(const double &a_scaleFactor)
This method scales this object by a scale factor.
Definition CMultiSegment.h:278
cSegmentArrayPtr m_segments
Array of triangles.
Definition CMultiSegment.h:310
GLint m_stippleFactor
Specifies a multiplier for each bit in the line stipple pattern.
Definition CMultiSegment.h:294
virtual ~cMultiSegment()
Destructor of cMultiSegment.
Definition CMultiSegment.cpp:104
virtual void render(cRenderOptions &a_options)
This method renders this object graphically using OpenGL.
Definition CMultiSegment.cpp:661
virtual std::string getClassName()
This method returns the name of the object class.
Definition CMultiSegment.h:118
bool m_showSegments
If true, then segments are displayed.
Definition CMultiSegment.h:288
void setLineWidth(const double a_lineWidth)
This method sets the line width of all segments.
Definition CMultiSegment.h:207
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
unsigned int getNumVertices() const
This method returns the number of stored vertices.
Definition CMultiSegment.h:144
virtual void setTransparencyLevel(const float a_level, const bool a_applyToVertices=false, const bool a_applyToTextures=false, const bool a_affectChildren=false, const bool a_affectComponents=true)
This method sets the alpha value at each vertex and in all of my material colors.
Definition CMultiSegment.cpp:469
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
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 markForUpdate(const bool a_affectChildren=false, const bool a_affectComponents=true)
This method invalidates any existing display lists and marks the mesh for update.
Definition CMultiSegment.cpp:447
virtual void createBruteForceCollisionDetector()
This method builds a brute force collision detector for this mesh.
Definition CMultiSegment.cpp:614
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 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
void setLineStipple(const GLint a_stippleFactor, const GLushort a_stipplePattern)
This method specifies the line stipple pattern.
cMultiSegment()
Constructor of cMultiSegment.
Definition CMultiSegment.cpp:70
virtual void createAABBCollisionDetector(const double a_radius)
This method builds an AABB collision detector for this mesh.
Definition CMultiSegment.cpp:636
virtual void renderSegments(cRenderOptions &a_options)
This method rendres all segments.
Definition CMultiSegment.cpp:694
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:519
void setLineColor(const cColorf &a_color)
This method sets the color of all segments.
Definition CMultiSegment.cpp:499
virtual cVector3d getCenterOfMass()
This method computes the center of mass of this object, based on vertex positions.
Definition CMultiSegment.cpp:215
cVertexArrayPtr m_vertices
Array of vertices.
Definition CMultiSegment.h:307
Definition CAudioBuffer.cpp:57
std::shared_ptr< cSegmentArray > cSegmentArrayPtr
Definition CSegmentArray.h:66
std::shared_ptr< cVertexArray > cVertexArrayPtr
Definition CVertexArray.h:108
This class defines a color using a GLfloat representation for each component.
Definition CColor.h:139
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition CRenderOptions.h:83
This class implements a 3D vector.
Definition CVector3d.h:89