| GL Studio C++ Runtime API

gls_3d_cable.h
Go to the documentation of this file.
1/*! \file
2 \brief The disti::Gls3DCable class.
3
4 \par Copyright Information
5
6 Copyright (c) 2017 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd; Suite 100<br>
8 Orlando, Florida 32817<br>
9 USA<br>
10 <br>
11 All rights reserved.<br>
12
13 This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19
20 NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26
27 LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35
36 The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38*/
39
40#ifndef _GLS3DCABLE_H
41#define _GLS3DCABLE_H
42
43#include <vector>
44
45#include "glpolygon.h"
46#include "gls_cpp_lang_support.h"
47#include "gls_quaternion.h"
48#include "gltrimesh.h"
49#include "group.h"
50
51/// Provides support for creating DLLs.
52#if( defined( GLSGEN_EXPORT_GLS3DCABLE ) || defined( GLSGEN_IMPORT_GLS3DCABLE ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
53 && defined( _MSC_VER )
54# if defined( GLSGEN_EXPORT_GLS3DCABLE ) || defined( GLS_EXPORT_GENERATED )
55# define GLSGEN_GLS3DCABLE_EXPORT __declspec( dllexport )
56# else
57# define GLSGEN_GLS3DCABLE_EXPORT __declspec( dllimport )
58# endif
59#else
60# define GLSGEN_GLS3DCABLE_EXPORT
61#endif
62///////////////////////////////////////////////////////////////////////////////
63
64/// Automatically link the runtime library plugin (on Windows).
65#define LIB_BASE_NAME "gls_3d_cable"
66#include "gls_auto_lib.h"
67#undef LIB_BASE_NAME
68
69 namespace disti
70{
71// SetValue enumerations
72 enum
73{
74 GLS_3DCABLE_FIRST_VALUE = GLS_LAST_INITIALIZER + 1,
75
76 GLS_3DCABLE_FLEXIBILITY,
77 GLS_3DCABLE_NUMBEROFSEGMENTS,
78 GLS_3DCABLE_NUMBEROFSIDES,
79 GLS_3DCABLE_RADIUS,
80 GLS_3DCABLE_LENGTH,
81 GLS_3DCABLE_GRAVITY,
82 GLS_3DCABLE_SECTIONSLACKPCT,
83 GLS_3DCABLE_SECTIONFLOORDIST,
84 GLS_3DCABLE_COLLISIONSTYLE,
85 GLS_3DCABLE_FILLCOLOR,
86 GLS_3DCABLE_LINECOLOR
87};
88
89 typedef DynamicArray<double> DynamicDoubleArray; ///< Typedef for dynamic array of slack percentages.
90
91/// \details The PreciseVertex class. Uses fuzzy floating point comparison rather than exact matches.
92 class PreciseVertex : public VertexNoColor
93{
94 public:
95 PreciseVertex()
96 : VertexNoColor()
97 {}
98
99 /// Constructor from Vector
100 /// \param vector The vector to construct from.
101 PreciseVertex( const Vector& vector )
102 : VertexNoColor( vector.x, vector.y, vector.z )
103 {}
104
105 /// Constructor from three floats
106 /// \param x The x component to construct from.
107 /// \param y The y component to construct from.
108 /// \param z The z component to construct from.
109 PreciseVertex( float x, float y, float z )
110 : VertexNoColor( x, y, z )
111 {}
112
113 /**
114 If the values are near zero, force them to be Zero!
115 \pre
116 \post
117 */
118 void NearZero()
119 {
120 const float DIFF = 0.0001f;
121
122 if( BETWEEN( x, 0.0 - DIFF, 0.0 + DIFF ) )
123 {
124 x = 0.0f;
125 }
126
127 if( BETWEEN( y, 0.0 - DIFF, 0.0 + DIFF ) )
128 {
129 y = 0.0f;
130 }
131
132 if( BETWEEN( z, 0.0 - DIFF, 0.0 + DIFF ) )
133 {
134 z = 0.0f;
135 }
136 }
137
138 /** Normalizes the vector into a unit vector */
139 void Normalize()
140 {
141 double length = Magnitude();
142
143 // how close to zero do we want to be?
144 const double DIFF = 0.0001;
145
146 if( !BETWEEN( length, 0.0 - DIFF, 0.0 + DIFF ) )
147 {
148 // Divide is slow so calculate 1/length and multiply to save time
149 double inv_length = 1.0 / length;
150
151 x = float( x * inv_length );
152 y = float( y * inv_length );
153 z = float( z * inv_length );
154 }
155 else
156 {
157 x = 0.0f;
158 y = 0.0f;
159 z = 0.0f;
160 }
161 }
162
163 /** Determines if the vertex is identical to the supplied vertex, ignoring color
164 \param arg vertex to compare to
165 \return TRUE if equal, else FALSE
166 */
167 bool operator==( const VertexNoColor& arg ) const
168 {
169 const double DIFF = 0.0001;
170 return ( BETWEEN( x, arg.x - DIFF, arg.x + DIFF ) && BETWEEN( y, arg.y - DIFF, arg.y + DIFF ) && BETWEEN( z, arg.z - DIFF, arg.z + DIFF ) );
171 }
172
173 /** Determines if the vertex is identical to the supplied vertex, ignoring color
174 \param arg vertex to compare to
175 \return TRUE if equal, else FALSE
176 */
177 bool operator!=( const VertexNoColor& arg ) const
178 {
179 const double DIFF = 0.0001;
180 return ( !BETWEEN( x, arg.x - DIFF, arg.x + DIFF ) || !BETWEEN( y, arg.y - DIFF, arg.y + DIFF ) || !BETWEEN( z, arg.z - DIFF, arg.z + DIFF ) );
181 }
182};
183
184/**
185 Runtime implementation of a Gls3DCable. The Gls3DCable is a cable mesh between
186 two or more endpoint objects. The user controls the length, the flexibility, the
187 diameter, the smoothness (segments and sides), and the droop of the cable.
188*/
189 class Gls3DCable : public Group
190{
191 public:
192 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
193 typedef Group _BaseClass; ///< Deprecated typedef for the base class.
194 typedef Group BaseClass; ///< Typedef for the base class.
195
196 enum
197 {
198 TEXTUREPOINT_MULT = 50
199 };
200
201 /** Sides limits */
202 enum
203 {
204 MIN_NUMBER_OF_SIDES = 1,
205 MAX_NUMBER_OF_SIDES = 100 // visually 50 looked good, 100 gives the user room
206 };
207
208 /** Segement limits */
209 enum
210 {
211 MIN_SEGEMENTS = 1,
212 MAX_SEGEMENTS = 10000 // Seems like 10,000 segements should be way big enough
213 };
214
215 /// Collision model
216 enum ECollisionStyle
217 {
218 COLLISIONSTYLE_NONE = 0,
219 COLLISIONSTYLE_FAST
220#if defined( USE_COLLISIONSTYLE_SLOW )
221 ,
222 COLLISIONSTYLE_SLOW
223#endif
224 };
225
226 friend class Gls3DCableEditor;
227
228 /// Create a new Gls3DCable.
229 /// \param generateInstance Whether or not to generate an instance name for this object.
230 GLSGEN_GLS3DCABLE_EXPORT Gls3DCable( bool generateInstance = false );
231
232 /// Copy constructor for Gls3DCable
233 /// \param that The Gls3DCable to be copied from.
234 /// \param generateNames Whether or not to generate a new instance name.
235 GLSGEN_GLS3DCABLE_EXPORT Gls3DCable( const Gls3DCable& that, const bool generateNames );
236
237 /** Destructs a Gls3DCable object */
238 virtual GLSGEN_GLS3DCABLE_EXPORT ~Gls3DCable();
239
240 /// \return A pointer to a new Gls3DCable.
241 static GLSGEN_GLS3DCABLE_EXPORT DisplayObject* CreateInstance();
242
243 //////////////////////////////////////////////////
244 // Overridden base class methods
245 // The base class methods are overridden so that the Group Class methods
246 // are not called, generally DisplayObject methods are called, there
247 // are a few exceptions.
248 //////////////////////////////////////////////////
249
250 /// \copydoc DisplayObject::GetResources
251 virtual void GetResources( std::ostream& outstr, GlsResourceFilter* filter ) DISTI_METHOD_OVERRIDE;
252 /// \copydoc DisplayObject::Resource
253 virtual DistiAttributeBase& Resource( const char* name ) DISTI_METHOD_OVERRIDE;
254 /// \copydoc DisplayObject::SetAvailableAttributes
255 virtual GLSGEN_GLS3DCABLE_EXPORT void SetAvailableAttributes( unsigned int value ) DISTI_METHOD_OVERRIDE;
256 /// \copydoc DisplayObject::CloneObject
257 virtual GLSGEN_GLS3DCABLE_EXPORT DisplayObject* CloneObject( bool generateNames = false ) DISTI_METHOD_OVERRIDE;
258 /// \copydoc DisplayObject::CopyProperties
259 virtual GLSGEN_GLS3DCABLE_EXPORT void CopyProperties( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
260#ifndef GLES
261 /// \copydoc DisplayObject::GetCppInterfaceDescription
262 virtual GLSGEN_GLS3DCABLE_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
263 /// \copydoc DisplayObject::GetCppInterfaceDescriptionFree
264 virtual GLSGEN_GLS3DCABLE_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
265#endif
266 /// \copydoc DisplayObject::PreDraw
267 virtual GLSGEN_GLS3DCABLE_EXPORT void PreDraw( const OpenGLMatrices& current, Culler& culler ) DISTI_METHOD_OVERRIDE;
268 /// \copydoc DisplayObject::Draw
269 virtual GLSGEN_GLS3DCABLE_EXPORT void Draw() DISTI_METHOD_OVERRIDE;
270 /// \copydoc DisplayObject::Calculate
271 virtual GLSGEN_GLS3DCABLE_EXPORT void Calculate( double time ) DISTI_METHOD_OVERRIDE;
272 /// \copydoc DisplayObject::handle
273 virtual GLSGEN_GLS3DCABLE_EXPORT DisplayObject* handle( DisplayEvent* ev ) DISTI_METHOD_OVERRIDE;
274 /// \copydoc DisplayObject::SetValue
275 virtual GLSGEN_GLS3DCABLE_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
276 /// \copydoc Group::CalculateBoundingBox
277 virtual GLSGEN_GLS3DCABLE_EXPORT void CalculateBoundingBox() DISTI_METHOD_OVERRIDE;
278 /// \copydoc DisplayObject::Hit
279 virtual GLSGEN_GLS3DCABLE_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint ) DISTI_METHOD_OVERRIDE;
280
281 /// \copydoc DisplayObject::Pick3D
282 virtual GLSGEN_GLS3DCABLE_EXPORT DisplayObject* Pick3D( const Vector& winLoc, const Vector& logicalCoords, float scale,
283 const Vector& directionVector, Vector& collisionWinLoc, const OpenGLMatrices& drawnMatrices ) DISTI_METHOD_OVERRIDE;
284
285 /// \copydoc DisplayObject::CalculateTextureCoordinates
286 virtual GLSGEN_GLS3DCABLE_EXPORT void CalculateTextureCoordinates() DISTI_METHOD_OVERRIDE;
287 /// \copydoc DisplayObject::LineWidth(float)
288 virtual GLSGEN_GLS3DCABLE_EXPORT void LineWidth( float width ) DISTI_METHOD_OVERRIDE;
289 /// \copydoc DisplayObject::LineWidth()
290 virtual GLSGEN_GLS3DCABLE_EXPORT float LineWidth() DISTI_METHOD_OVERRIDE;
291 /// \copydoc DisplayObject::LineStipplePattern(int)
292 virtual GLSGEN_GLS3DCABLE_EXPORT void LineStipplePattern( int pattern ) DISTI_METHOD_OVERRIDE;
293 /// \copydoc DisplayObject::LineStipplePattern()
294 virtual GLSGEN_GLS3DCABLE_EXPORT int LineStipplePattern() DISTI_METHOD_OVERRIDE;
295 /// \copydoc DisplayObject::LineStippleMultiplier(int)
296 virtual GLSGEN_GLS3DCABLE_EXPORT void LineStippleMultiplier( int mult ) DISTI_METHOD_OVERRIDE;
297 /// \copydoc DisplayObject::LineStippleMultiplier()
298 virtual GLSGEN_GLS3DCABLE_EXPORT int LineStippleMultiplier() DISTI_METHOD_OVERRIDE;
299 /// \copydoc DisplayObject::PolygonMode()
300 virtual GLSGEN_GLS3DCABLE_EXPORT int PolygonMode() DISTI_METHOD_OVERRIDE;
301 /// \copydoc DisplayObject::PolygonMode(int)
302 virtual GLSGEN_GLS3DCABLE_EXPORT void PolygonMode( int mode ) DISTI_METHOD_OVERRIDE;
303 /// \copydoc DisplayObject::PolygonEnd(const int)
304 virtual GLSGEN_GLS3DCABLE_EXPORT void PolygonEnd( const int end ) DISTI_METHOD_OVERRIDE;
305 /// \copydoc DisplayObject::PolygonEnd()
306 virtual GLSGEN_GLS3DCABLE_EXPORT int PolygonEnd() DISTI_METHOD_OVERRIDE;
307 /// \copydoc DisplayObject::Shading(const int)
308 virtual GLSGEN_GLS3DCABLE_EXPORT void Shading( const int shading ) DISTI_METHOD_OVERRIDE;
309 /// \copydoc DisplayObject::Shading()
310 virtual GLSGEN_GLS3DCABLE_EXPORT int Shading() DISTI_METHOD_OVERRIDE;
311 /// \copydoc DisplayObject::DepthTest(unsigned char)
312 virtual GLSGEN_GLS3DCABLE_EXPORT void DepthTest( unsigned char zbuf ) DISTI_METHOD_OVERRIDE;
313 /// \copydoc DisplayObject::DepthTest()
314 virtual GLSGEN_GLS3DCABLE_EXPORT int DepthTest() DISTI_METHOD_OVERRIDE;
315 /// \copydoc DisplayObject::AntiAlias(bool)
316 virtual GLSGEN_GLS3DCABLE_EXPORT void AntiAlias( bool alias ) DISTI_METHOD_OVERRIDE;
317 /// \copydoc DisplayObject::AntiAlias()
318 virtual GLSGEN_GLS3DCABLE_EXPORT bool AntiAlias() DISTI_METHOD_OVERRIDE;
319 /// \copydoc DisplayObject::AlphaMode(int)
320 virtual GLSGEN_GLS3DCABLE_EXPORT void AlphaMode( int mode ) DISTI_METHOD_OVERRIDE;
321 /// \copydoc DisplayObject::AlphaMode()
322 virtual GLSGEN_GLS3DCABLE_EXPORT int AlphaMode() DISTI_METHOD_OVERRIDE;
323 /// \copydoc DisplayObject::CullBackFace(const bool)
324 virtual GLSGEN_GLS3DCABLE_EXPORT void CullBackFace( const bool val ) DISTI_METHOD_OVERRIDE;
325 /// \copydoc DisplayObject::CullBackFace()
326 virtual GLSGEN_GLS3DCABLE_EXPORT bool CullBackFace() DISTI_METHOD_OVERRIDE;
327 /// \copydoc DisplayObject::LightingEnabled()
328 virtual GLSGEN_GLS3DCABLE_EXPORT bool LightingEnabled() DISTI_METHOD_OVERRIDE;
329 /// \copydoc DisplayObject::LightingEnabled(bool)
330 virtual GLSGEN_GLS3DCABLE_EXPORT void LightingEnabled( bool lighting ) DISTI_METHOD_OVERRIDE;
331 /// \copydoc DisplayObject::SetBlendColor(const GlsColor&)
332 virtual GLSGEN_GLS3DCABLE_EXPORT void SetBlendColor( const GlsColor& color ) DISTI_METHOD_OVERRIDE;
333 /// \copydoc DisplayObject::GetBlendColor()
334 virtual GLSGEN_GLS3DCABLE_EXPORT GlsColor GetBlendColor() DISTI_METHOD_OVERRIDE;
335 /// \copydoc DisplayObject::SetColor(const GlsColor&)
336 virtual GLSGEN_GLS3DCABLE_EXPORT void SetColor( const GlsColor& color ) DISTI_METHOD_OVERRIDE;
337 /// \copydoc DisplayObject::GetColor()
338 virtual GLSGEN_GLS3DCABLE_EXPORT GlsColor GetColor() DISTI_METHOD_OVERRIDE;
339 /// \copydoc DisplayObject::SetFillColor(const GlsColor&)
340 virtual GLSGEN_GLS3DCABLE_EXPORT void SetFillColor( const GlsColor& color ) DISTI_METHOD_OVERRIDE;
341 /// \copydoc DisplayObject::GetFillColor()
342 virtual GLSGEN_GLS3DCABLE_EXPORT GlsColor GetFillColor() DISTI_METHOD_OVERRIDE;
343 /// \copydoc DisplayObject::TextureRepeat(const int)
344 virtual GLSGEN_GLS3DCABLE_EXPORT void TextureRepeat( const int rep ) DISTI_METHOD_OVERRIDE;
345 /// \copydoc DisplayObject::TextureRepeat()
346 virtual GLSGEN_GLS3DCABLE_EXPORT bool TextureRepeat() DISTI_METHOD_OVERRIDE;
347 /// \copydoc DisplayObject::TextureMappingTechnique(const int)
348 virtual GLSGEN_GLS3DCABLE_EXPORT void TextureMappingTechnique( const int map ) DISTI_METHOD_OVERRIDE;
349 /// \copydoc DisplayObject::TextureMappingTechnique()
350 virtual GLSGEN_GLS3DCABLE_EXPORT int TextureMappingTechnique() DISTI_METHOD_OVERRIDE;
351 /// \copydoc DisplayObject::TextureMinificationFilter(const int)
352 virtual GLSGEN_GLS3DCABLE_EXPORT void TextureMinificationFilter( const int filter ) DISTI_METHOD_OVERRIDE;
353 /// \copydoc DisplayObject::TextureMinificationFilter()
354 virtual GLSGEN_GLS3DCABLE_EXPORT int TextureMinificationFilter() DISTI_METHOD_OVERRIDE;
355 /// \copydoc DisplayObject::TextureMagnificationFilter(const int)
356 virtual GLSGEN_GLS3DCABLE_EXPORT void TextureMagnificationFilter( const int filter ) DISTI_METHOD_OVERRIDE;
357 /// \copydoc DisplayObject::TextureMagnificationFilter()
358 virtual GLSGEN_GLS3DCABLE_EXPORT int TextureMagnificationFilter() DISTI_METHOD_OVERRIDE;
359
360 //////////////////////////////////////////////////
361 // Gls3DCable specific operations
362 //////////////////////////////////////////////////
363
364 /** Sets flexibility.
365 * \param value Controls how stiff the cable is. The value should be in the
366 range of 0 to 1, inclusive. 0 is very inflexible, while 1 is very flexible.
367 \pre value must be in the range of 0 to 1
368 \post None
369 */
370 GLSGEN_GLS3DCABLE_EXPORT void Flexibility( const float& value );
371 /** Gets flexibility.
372 * \return How stiff the cable is.
373 */
374 GLSGEN_GLS3DCABLE_EXPORT float Flexibility();
375
376 /** Sets Number of Segements.
377 * \param value The number of cylindrical segments that will traverse
378 * the entire length of the cable. A cable with one section
379 * (that is, with only two control objects) would be a straight cylinder
380 * connecting two points, incapable of bending.
381 * The higher this number, the smoother your cable will appear.
382 \pre value must be in the range MIN_SEGEMENTS to MAX_SEGEMENTS
383 \post none
384 */
385 GLSGEN_GLS3DCABLE_EXPORT void NumberOfSegments( const unsigned int& value );
386
387 /** Gets the Number of Segements.
388 * \return The Number of Segments
389 */
390 GLSGEN_GLS3DCABLE_EXPORT unsigned int NumberOfSegments();
391
392 /** Sets the Number Of Sides.
393 * \param value The number of sides the cable "tube" will have.
394 * The more sides, the smoother the cable will appear.
395 * A value of two will produce a ribbon-like cable.
396 * A value of one will render only a line.
397 \pre value must be in the range of 1 to 100 inclusive.
398 \post None
399 */
400 GLSGEN_GLS3DCABLE_EXPORT void NumberOfSides( const unsigned int& value );
401
402 /** Gets the Number of Sides.
403 * \return The number of sides
404 */
405 GLSGEN_GLS3DCABLE_EXPORT unsigned int NumberOfSides();
406
407 /** Sets the Radius of the cable in logical units
408 \param value The radius in logical units.
409 \pre value must be plus/minus MAX_FLT
410 \post none
411 */
412 GLSGEN_GLS3DCABLE_EXPORT void Radius( const float& value );
413
414 /** Gets the Radius of the cable
415 * \return The radius in logical units
416 */
417 GLSGEN_GLS3DCABLE_EXPORT float Radius();
418
419 /** Sets the Length of the cable.
420 * when not under duress (the cable will stretch when the end-points
421 * are moved too far from each other).
422 * \param value The approximate length of the cable in logical units
423 \pre value must be 0.0 to MAX_FLT
424 \post None
425 */
426 GLSGEN_GLS3DCABLE_EXPORT void Length( const float& value );
427
428 /** Gets the Length of the cable.
429 * \return The length of the cable in logical units
430 */
431 GLSGEN_GLS3DCABLE_EXPORT float Length();
432
433 /** Sets the CollisionStyle.
434 * \param value The collision mode for the cable.
435 * COLLISIONSTYLE_NONE will disable all collision detection and
436 * therefore any cable deformation caused thereby.
437 * COLLISIONSTYLE_FAST will check for collisions with other objects in
438 * the scene, but will only move / orient the cable midpoint such that it
439 * appears as though the cable is laying flat on a single surface.
440 *
441 * Check if USE_COLLISIONSTYLE_SLOW is defined before using Slow.
442 */
443 GLSGEN_GLS3DCABLE_EXPORT void CollisionStyle( const int& value );
444
445 /** Gets the Collision Style
446 * \return The current Collision Style
447 */
448 GLSGEN_GLS3DCABLE_EXPORT int CollisionStyle();
449
450 /** Sets the Slack Percentage
451 * \param section Which section of the cable, 0 based
452 * \param pct The percent of the slace (0.0 -> 1.0)
453 * This will adjust the slack percentage in the cable for the section,
454 * the caller must ensure that all percents sum up to 1.0.
455 \pre section must be < _sectionSlackPct.Count(), and pct must be 0.0-1.0
456 \post Slack percentage will not change if preconditions are not met.
457 */
458 GLSGEN_GLS3DCABLE_EXPORT void SlackPct( unsigned int section, double pct );
459
460 /** Gets the Slack Percentage for a particular section
461 * \param section The section of interest.
462 * \return The slack percentage for the specified section.
463 \pre section must be < _sectionSlackPct.Count()
464 \post if preconditions are not met 0.0 is returned
465 */
466 GLSGEN_GLS3DCABLE_EXPORT double SlackPct( unsigned int section );
467
468 /**
469 How many Slack Sections are there? Can be used with SlackPct() to
470 get set Slack Sections.
471 \return Return the number of Slack Sections, 0 to N
472 \pre none
473 \post none
474 */
475 GLSGEN_GLS3DCABLE_EXPORT unsigned int SlackSectionCount() const;
476
477 /**
478 Sometimes an outside source may need to recalculate the cable, such as
479 when the scene changes and the cable may not be colliding with another
480 object in the scene.
481 \pre None
482 \post None
483 */
484 GLSGEN_GLS3DCABLE_EXPORT void ForceCableRecalc();
485
486 /// Whether or not to simulate gravity on the cable.
487 /// \param value The new gravity flag value.
488 GLSGEN_GLS3DCABLE_EXPORT void Gravity( const bool& value );
489
490 /**
491 Returns wether or not gavity is simulated on the cable.
492 \return Returns wether or not gavity is simulated on the cable
493 \pre none
494 \post none
495 */
496 GLSGEN_GLS3DCABLE_EXPORT bool Gravity()
497 {
498 return _gravity;
499 }
500
501 private:
502 /**
503 Reallocate, but do not set the vertices that make up the cable line
504 \pre None
505 \post Will clear _needNewLineVerts, and will set _needCableRecalc
506 */
507 void AllocateLineVertices();
508
509 /**
510 \param *root Pointer to a list of objects to search for a collision
511 \param &pos Starting point of the ray
512 \param &vec Direction vector of the ray
513 \param *mag_pct_chg If a float pointer is provided, this will return the percent
514 change between the new/old Ray magnitude.
515 This is an optional parameter.
516 \return Return true if the new magnitude is smaller than the old
517 \pre root must exist
518 \post
519 */
520 bool RaycastAdjusted( DisplayObject* root, Vector& pos, Vector& vec, float* mag_pct_chg = NULL );
521
522 /**
523 Determine if something is colliding with the cable.
524 \param *root Pointer to a list of objects to search for a collision
525 \param x The x starting location of the ray
526 \param y The y starting location of the ray
527 \param z The z starting location of the ray
528 \param scale The Scale factor of the window
529 \param directionVector Direction vector of the ray
530 \param &collideDist Return the distance to the collision point from the start point
531 \param *collisionPoint Return the closest collision point
532 \return true if a hit occurs
533 \pre root must exist
534 \post None
535 */
536 bool GlobalHit( DisplayObject* root, float x, float y, float z, float scale, const Vector& directionVector, float& collideDist, Vector* collisionPoint );
537
538 /**
539 Recompute the line vertices of the cable.
540 \return success or failure
541 \pre
542 \post will clear _needCableRecalc
543 */
544 bool RecalculateCable();
545
546 /**
547 Fill out/calculate the cable mesh.
548 \pre None
549 \post None
550 */
551 void TubeGeneration();
552
553 protected:
554 /**
555 How flexibile is the cable, more flexibility gives a more rounded cable
556 This has a range of 0 to 1, 0 is inflexible, 1 is flexible.
557 */
558 float _flexibility;
559
560 /**
561 The number of pieces that the entire cable has, the more
562 segements the more smooth a cable will appear, e.g., 1 segment
563 gives you a straight line, two gives you a 'V', etc.
564 This has a range of MIN_SEGEMENTS to MAX_SEGEMENTS
565 */
566 unsigned int _numberOfSegments;
567
568 /**
569 How many sides does the cable have. 1 is a wire
570 2 is a ribbon cable, 3 a triangle, 4 a sqaure, etc. the more
571 sides the closer to a circle you get.
572 This has a range of MIN_NUMBER_OF_SIDES to MAX_NUMBER_OF_SIDES.
573 */
574 unsigned int _numberOfSides;
575
576 /**
577 The Radius of the cable. Units are in pixels.
578 This has a range of plus/minus FLT_MAX
579 */
580 float _radius;
581
582 /**
583 The requested length of the cable, the cable may be longer, if needed to
584 reach between the end points. A zero length cable can be used to "hide"
585 the cable, while leaving the end points intact. Units are in logical units.
586 This has a range of zero to FLT_MAX.
587 */
588 float _length;
589
590 /**
591 Does RecalculateCable () need to be called next frame?
592 */
593 bool _needCableRecalc;
594
595 /**
596 Does TubeGeneration () need to be called next frame?
597 */
598 bool _needTubeGeneration;
599
600 /**
601 Prevents "Hit()" from being called from within RecalculateCable()
602 */
603 bool _inCableRecalc;
604
605 /**
606 The _lineVerts are stored in the _line object. The _line object is used
607 for drawing if sides == 1.
608 */
609 GLPolygon _line;
610
611 /**
612 The Mesh Verts, Normals, and TexCoords are stored in this object. The _mesh object
613 is used for drawing when sides > 1.
614 */
615 GLTriMesh _mesh;
616
617 /**
618 Stores the locations of all of the "EndPoint" objects for ease of use in future calculations.
619 Also used to check if any of the positions have changed.
620 Endpoints, can be in the middle section of the cable, by "endpoints" it is meant the ends of the sections.
621 */
622 std::vector<Vector> _endPointPos;
623
624 /**
625 Stores the dcs orientations of all of the "EndPoint" objects for ease of use in future calculations.
626 Also used to check if any of the orientations have changed.
627 Endpoints, can be in the middle section of the cable, by "endpoints" it is meant the ends of the sections.
628 */
629 std::vector<GlsMatrixAffineD> _endPointOri;
630
631 /**
632 The percentage of slack that each cable segment has (starts out equally divided)...
633 but the User can set the percentages.
634 This has a range of >= 0 and <= 1. The total of all sections should add to 1.
635 */
636 DynamicDoubleArray _sectionSlackPct;
637
638 /**
639 Store the DCS Rotation matrix used to calculate the mesh object. The
640 Z is the direction of gravity, so this will effect the slack in the cable.
641 Compare this old DCS with the current to determine if we need to recalculate
642 the mesh.
643 */
644 GlsMatrixAffineD _cableDcs;
645
646 /**
647 The collision type.
648 */
649 ECollisionStyle _collisionStyle;
650
651 bool _gravity; ///< If true, gravity will be simulated on this cable.
652
653 /// The number of vertices in the cable line, for each section of the cable.
654 /// This INCLUDES the first vertex and the last vertex of each section.
655 int _lineVertsPerSection;
656
657 /// This will be the summed arc length for all sections.
658 /// It is stored because it is used for tube generation.
659 float _realCableLength;
660
661 private:
662 // Disable implicit generated Members
663 Gls3DCable& operator=( const Gls3DCable& rhs ) DISTI_SPECIAL_MEM_FUN_DELETE;
664 Gls3DCable( const Gls3DCable& src ) DISTI_SPECIAL_MEM_FUN_DELETE;
665};
666
667} // namespace disti
668
669#endif
disti::Culler
Definition: cull.h:50
disti::DisplayEvent
Definition: events.h:113
disti::DisplayObject
Definition: display.h:96
disti::DistiAttributeBase
Definition: disti_metadata.h:220
disti::DynamicArray< double >
disti::GLPolygon
The Polygon class. Implements Polygons.
Definition: glpolygon.h:56
disti::GLTriMesh
The glTriMesh class. Implements Triangle Meshes.
Definition: gltrimesh.h:95
disti::Gls3DCable
Definition: gls_3d_cable.h:190
disti::Gls3DCable::CalculateTextureCoordinates
virtual void CalculateTextureCoordinates() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::SlackPct
void SlackPct(unsigned int section, double pct)
disti::Gls3DCable::SetAvailableAttributes
virtual void SetAvailableAttributes(unsigned int value) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::LineStipplePattern
virtual int LineStipplePattern() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::Draw
virtual void Draw() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::TextureMagnificationFilter
virtual int TextureMagnificationFilter() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::PolygonEnd
virtual int PolygonEnd() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::Gravity
bool Gravity()
Definition: gls_3d_cable.h:496
disti::Gls3DCable::CalculateBoundingBox
virtual void CalculateBoundingBox() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::_radius
float _radius
Definition: gls_3d_cable.h:580
disti::Gls3DCable::Radius
float Radius()
disti::Gls3DCable::_gravity
bool _gravity
If true, gravity will be simulated on this cable.
Definition: gls_3d_cable.h:651
disti::Gls3DCable::SetColor
virtual void SetColor(const GlsColor &color) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::_cableDcs
GlsMatrixAffineD _cableDcs
Definition: gls_3d_cable.h:644
disti::Gls3DCable::_length
float _length
Definition: gls_3d_cable.h:588
disti::Gls3DCable::CloneObject
virtual DisplayObject * CloneObject(bool generateNames=false) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::Gls3DCable
Gls3DCable(bool generateInstance=false)
disti::Gls3DCable::SetBlendColor
virtual void SetBlendColor(const GlsColor &color) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::TextureMinificationFilter
virtual int TextureMinificationFilter() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::CullBackFace
virtual bool CullBackFace() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::GetColor
virtual GlsColor GetColor() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::Hit
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::_needTubeGeneration
bool _needTubeGeneration
Definition: gls_3d_cable.h:598
disti::Gls3DCable::handle
virtual DisplayObject * handle(DisplayEvent *ev) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::LineStippleMultiplier
virtual int LineStippleMultiplier() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::SetValue
virtual void SetValue(int spec, va_list &args) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::GetBlendColor
virtual GlsColor GetBlendColor() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::PreDraw
virtual void PreDraw(const OpenGLMatrices &current, Culler &culler) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::GetResources
virtual void GetResources(std::ostream &outstr, GlsResourceFilter *filter) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::TextureRepeat
virtual bool TextureRepeat() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::_inCableRecalc
bool _inCableRecalc
Definition: gls_3d_cable.h:603
disti::Gls3DCable::_numberOfSides
unsigned int _numberOfSides
Definition: gls_3d_cable.h:574
disti::Gls3DCable::_collisionStyle
ECollisionStyle _collisionStyle
Definition: gls_3d_cable.h:649
disti::Gls3DCable::SlackSectionCount
unsigned int SlackSectionCount() const
disti::Gls3DCable::PolygonMode
virtual int PolygonMode() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::NumberOfSegments
unsigned int NumberOfSegments()
disti::Gls3DCable::CollisionStyle
int CollisionStyle()
disti::Gls3DCable::Shading
virtual int Shading() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::Calculate
virtual void Calculate(double time) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::CreateInstance
static DisplayObject * CreateInstance()
disti::Gls3DCable::ForceCableRecalc
void ForceCableRecalc()
disti::Gls3DCable::Gls3DCable
Gls3DCable(const Gls3DCable &that, const bool generateNames)
disti::Gls3DCable::_mesh
GLTriMesh _mesh
Definition: gls_3d_cable.h:615
disti::Gls3DCable::DepthTest
virtual int DepthTest() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::_flexibility
float _flexibility
Definition: gls_3d_cable.h:558
disti::Gls3DCable::Resource
virtual DistiAttributeBase & Resource(const char *name) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::Length
float Length()
disti::Gls3DCable::_line
GLPolygon _line
Definition: gls_3d_cable.h:609
disti::Gls3DCable::~Gls3DCable
virtual ~Gls3DCable()
disti::Gls3DCable::TextureMappingTechnique
virtual int TextureMappingTechnique() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::Pick3D
virtual DisplayObject * Pick3D(const Vector &winLoc, const Vector &logicalCoords, float scale, const Vector &directionVector, Vector &collisionWinLoc, const OpenGLMatrices &drawnMatrices) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::CopyProperties
virtual void CopyProperties(DisplayObject *src) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::_sectionSlackPct
DynamicDoubleArray _sectionSlackPct
Definition: gls_3d_cable.h:636
disti::Gls3DCable::Flexibility
float Flexibility()
disti::Gls3DCable::_realCableLength
float _realCableLength
Definition: gls_3d_cable.h:659
disti::Gls3DCable::AntiAlias
virtual bool AntiAlias() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::ECollisionStyle
ECollisionStyle
Collision model.
Definition: gls_3d_cable.h:217
disti::Gls3DCable::LightingEnabled
virtual bool LightingEnabled() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::GetFillColor
virtual GlsColor GetFillColor() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::_numberOfSegments
unsigned int _numberOfSegments
Definition: gls_3d_cable.h:566
disti::Gls3DCable::LineWidth
virtual float LineWidth() DISTI_METHOD_OVERRIDE
disti::Gls3DCable::_endPointPos
std::vector< Vector > _endPointPos
Definition: gls_3d_cable.h:622
disti::Gls3DCable::SetFillColor
virtual void SetFillColor(const GlsColor &color) DISTI_METHOD_OVERRIDE
disti::Gls3DCable::_lineVertsPerSection
int _lineVertsPerSection
Definition: gls_3d_cable.h:655
disti::Gls3DCable::NumberOfSides
unsigned int NumberOfSides()
disti::Gls3DCable::_needCableRecalc
bool _needCableRecalc
Definition: gls_3d_cable.h:593
disti::Gls3DCable::_endPointOri
std::vector< GlsMatrixAffineD > _endPointOri
Definition: gls_3d_cable.h:629
disti::Gls3DCable::AlphaMode
virtual int AlphaMode() DISTI_METHOD_OVERRIDE
disti::GlsColor
Definition: gls_color.h:54
disti::GlsMatrixAffine< double >
disti::GlsResourceFilter
Definition: gls_resources.h:51
disti::Group
Definition: group.h:53
disti::OpenGLMatrices
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:544
disti::PreciseVertex
Definition: gls_3d_cable.h:93
disti::PreciseVertex::operator==
bool operator==(const VertexNoColor &arg) const
Definition: gls_3d_cable.h:167
disti::PreciseVertex::NearZero
void NearZero()
Definition: gls_3d_cable.h:118
disti::PreciseVertex::PreciseVertex
PreciseVertex(float x, float y, float z)
Definition: gls_3d_cable.h:109
disti::PreciseVertex::operator!=
bool operator!=(const VertexNoColor &arg) const
Definition: gls_3d_cable.h:177
disti::PreciseVertex::Normalize
void Normalize()
Definition: gls_3d_cable.h:139
disti::PreciseVertex::PreciseVertex
PreciseVertex(const Vector &vector)
Definition: gls_3d_cable.h:101
disti::VertexNoColor
Definition: vertex.h:85
disti::VertexNoColor::y
float y
The Y component.
Definition: vertex.h:88
disti::VertexNoColor::VertexNoColor
VertexNoColor()
Definition: vertex.h:92
disti::VertexNoColor::x
float x
The X component.
Definition: vertex.h:87
disti::VertexNoColor::Magnitude
float Magnitude() const
Definition: vertex.h:330
disti::VertexNoColor::z
float z
The Z component.
Definition: vertex.h:89
glpolygon.h
The disti::GLPolygon class. Implements Polygons.
GLSGEN_GLS3DCABLE_EXPORT
#define GLSGEN_GLS3DCABLE_EXPORT
Provides support for creating DLLs.
Definition: gls_3d_cable.h:60
gls_auto_lib.h
The gls_auto_lib.
gls_cpp_lang_support.h
Macros and helper code to determine what subset of C++11/14/17 is available.
DISTI_SPECIAL_MEM_FUN_DELETE
#define DISTI_SPECIAL_MEM_FUN_DELETE
Macro to wrap function deletion, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:246
DISTI_DEPRECATED
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:488
DISTI_METHOD_OVERRIDE
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:222
gls_quaternion.h
The disti::GlsQuaternion class.
gltrimesh.h
The disti::GLTriMesh class. Implements Triangle Meshes.
group.h
The disti::Group class. Implements groups of objects.
disti
Definition: bmpimage.h:47
disti::BETWEEN
bool BETWEEN(const X &x, const X1 &x1, const X2 &x2)
Definition: util.h:131
disti::DynamicDoubleArray
DynamicArray< double > DynamicDoubleArray
Typedef for dynamic array of slack percentages.
Definition: gls_3d_cable.h:89
disti::end
DistiAttribDict::const_iterator end(const DistiAttribDict &dict)
Definition: disti_metadata.h:975