GL Studio C++ Runtime API
gls_dynamic_path.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsDynamicPath class and global enumerations.
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 _GLSDYNAMICPATH_H
41 #define _GLSDYNAMICPATH_H
42 
43 #include "gls_cpp_lang_support.h"
44 #include "group.h"
45 
46 //////////////////// Provides support for creating DLLs ////////////////////////
47 #if( defined( GLSGEN_EXPORT_GLSDYNAMICPATH ) || defined( GLSGEN_IMPORT_GLSDYNAMICPATH ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
48  && defined( _MSC_VER )
49 # if defined( GLSGEN_EXPORT_GLSDYNAMICPATH ) || defined( GLS_EXPORT_GENERATED )
50 # define GLSGEN_GLSDYNAMICPATH_EXPORT __declspec( dllexport )
51 # else
52 # define GLSGEN_GLSDYNAMICPATH_EXPORT __declspec( dllimport )
53 # endif
54 #else
55 # define GLSGEN_GLSDYNAMICPATH_EXPORT
56 #endif
57 ///////////////////////////////////////////////////////////////////////////////
58 
59 #define LIB_BASE_NAME "gls_dynamic_path"
60 #include "gls_auto_lib.h"
61 #undef LIB_BASE_NAME
62 
63 namespace disti
64 {
65 // SetValue enumerations
66 enum
67 {
68  GLS_DYNAMICPATH_FIRST_VALUE = GLS_LAST_INITIALIZER + 1,
69  GLS_DYNAMICPATH_AFFECTS_LOCATION_X,
70  GLS_DYNAMICPATH_AFFECTS_LOCATION_Y,
71  GLS_DYNAMICPATH_AFFECTS_LOCATION_Z,
72  GLS_DYNAMICPATH_AFFECTS_ROTATION_X,
73  GLS_DYNAMICPATH_AFFECTS_ROTATION_Y,
74  GLS_DYNAMICPATH_AFFECTS_ROTATION_Z,
75  GLS_DYNAMICPATH_AFFECTS_SCALE_X,
76  GLS_DYNAMICPATH_AFFECTS_SCALE_Y,
77  GLS_DYNAMICPATH_AFFECTS_SCALE_Z,
78  GLS_DYNAMICPATH_USE_SHORT_ROTATION_PATHS,
79  GLS_DYNAMICPATH_STATE_COUNT,
80  GLS_DYNAMICPATH_STATE
81 };
82 
83 /** Runtime implementation of a GlsDynamicPath */
85 {
86  friend class GlsDynamicPathEditor;
87 
88 private:
89  GlsDynamicPath& operator=( const GlsDynamicPath& ) DISTI_SPECIAL_MEM_FUN_DELETE;
90  GlsDynamicPath( const GlsDynamicPath& ) DISTI_SPECIAL_MEM_FUN_DELETE;
91 
92 public:
93  typedef DisplayObject _BaseClass;
94 
95  /** Create a new GlsDynamicPath.
96  * \param generateInstanceName Whether or not to generate an instance name
97  * for this inputdevice */
98  GLSGEN_GLSDYNAMICPATH_EXPORT GlsDynamicPath( bool generateInstanceName = false );
99 
100  /** The copy constructor for GlsDynamicPath
101  *
102  * \param that The GlsDynamicPath object that is being copied
103  * \param generateNames Whether or not to generate a new instance name
104  */
105  GLSGEN_GLSDYNAMICPATH_EXPORT GlsDynamicPath( const GlsDynamicPath& that, const bool generateNames );
106 
107  /** Destructs a GlsDynamicPath object */
108  virtual GLSGEN_GLSDYNAMICPATH_EXPORT ~GlsDynamicPath();
109 
110  static GLSGEN_GLSDYNAMICPATH_EXPORT DisplayObject* CreateInstance();
111 
112  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void SetAvailableAttributes( unsigned int value );
113 
114  virtual GLSGEN_GLSDYNAMICPATH_EXPORT DisplayObject* CloneObject( bool generateNames = false );
115 
116  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void CopyProperties( DisplayObject* src );
117 
118 #ifndef GLES
119  virtual GLSGEN_GLSDYNAMICPATH_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL );
120  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array );
121 #endif
122 
123  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler );
124  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void Draw( void );
125 
126  virtual GLSGEN_GLSDYNAMICPATH_EXPORT DisplayObject* handle( DisplayEvent* ev );
127 
128  virtual GLSGEN_GLSDYNAMICPATH_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint );
129 
130  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void SetValue( int spec, va_list& args );
131 
132  virtual GLSGEN_GLSDYNAMICPATH_EXPORT DistiAttributeBase& Resource( const char* name );
133  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void GetResources( std::ostream& outstr, GlsResourceFilter* filter );
134 
135  //////////////////////////////////////////////////
136  // GlsDynamicPath specific operations
137  //////////////////////////////////////////////////
138 
139  // Controls whether the path will affect the X component of the object's dynamic translation.
140  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsLocationX( const bool& value );
141  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsLocationX() const { return _affectsLocationX; }
142 
143  // Controls whether the path will affect the Y component of the object's dynamic translation.
144  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsLocationY( const bool& value );
145  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsLocationY() const { return _affectsLocationY; }
146 
147  // Controls whether the path will affect the Z component of the object's dynamic translation.
148  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsLocationZ( const bool& value );
149  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsLocationZ() const { return _affectsLocationZ; }
150 
151  // Controls whether the path will affect the X component of the object's dynamic rotation.
152  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsRotationX( const bool& value );
153  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsRotationX() const { return _affectsRotationX; }
154 
155  // Controls whether the path will affect the Y component of the object's dynamic rotation.
156  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsRotationY( const bool& value );
157  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsRotationY() const { return _affectsRotationY; }
158 
159  // Controls whether the path will affect the Z component of the object's dynamic rotation.
160  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsRotationZ( const bool& value );
161  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsRotationZ() const { return _affectsRotationZ; }
162 
163  // Controls whether the path will affect the X component of the object's dynamic scale.
164  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsScaleX( const bool& value );
165  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsScaleX() const { return _affectsScaleX; }
166 
167  // Controls whether the path will affect the Y component of the object's dynamic scale.
168  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsScaleY( const bool& value );
169  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsScaleY() const { return _affectsScaleY; }
170 
171  // Controls whether the path will affect the Z component of the object's dynamic scale.
172  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsScaleZ( const bool& value );
173  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsScaleZ() const { return _affectsScaleZ; }
174 
175  // If true, the shortest path between rotations is taken (360 degrees = no net rotation). If false, the long path is taken.
176  GLSGEN_GLSDYNAMICPATH_EXPORT void UseShortRotationPaths( const bool& value );
177  GLSGEN_GLSDYNAMICPATH_EXPORT bool UseShortRotationPaths() const { return _useShortRotationPaths; }
178 
179  // Contains the data for a state along the path
180  class State
181  {
182  friend class GlsDynamicPath;
183 
184  public:
185  GLSGEN_GLSDYNAMICPATH_EXPORT State();
186  GLSGEN_GLSDYNAMICPATH_EXPORT State( const State& );
187  GLSGEN_GLSDYNAMICPATH_EXPORT ~State();
188 
189  GLSGEN_GLSDYNAMICPATH_EXPORT const State& operator=( const State& );
190  GLSGEN_GLSDYNAMICPATH_EXPORT void MakeAttribDict();
191 
192  DistiAttribDict& Attributes()
193  {
194  if( !_attribDict )
195  MakeAttribDict();
196  return *_attribDict;
197  };
198 
199  void Location( const Vector& value ) { _location = value; }
200  Vector Location() { return _location; }
201  Vector Location() const { return _location; }
202  void Rotation( const Vector& value ) { _rotation = value; }
203  Vector Rotation() { return _rotation; }
204  Vector Rotation() const { return _rotation; }
205  void Scale( const Vector& value ) { _scale = value; }
206  Vector Scale() { return _scale; }
207  Vector Scale() const { return _scale; }
208  void Value( const float& value ) { _value = value; }
209  float Value() { return _value; }
210  float Value() const { return _value; }
211 
212  protected:
213  Vector _location;
214  Vector _rotation;
215  Vector _scale;
216  float _value;
217  DistiAttribDict* _attribDict;
218  };
219 
221 
222  // Returns the StateArray associated with this object. Use this array to modify the states that make up the path.
223  StateArrayType& StateArray() { return _stateArray; }
224  const StateArrayType& StateArray() const { return _stateArray; }
225 
226  // Iterates through the path segments and returns the first one found
227  // that contains the given value.
228  // \param value The value to search for
229  // \param index1 returns the index of the state at the start of the segment or -1 if no segments are found
230  // \param index2 returns the index of the state at the end the segment or -1 if no segments are found
231  // Special cases:
232  // value is before start of the path: index1 == index2 == 0
233  // value is past the end of the path: index1 == index2 == (StateArray().Count()-1)
234  GLSGEN_GLSDYNAMICPATH_EXPORT void FindFirstPathSegmentContainingValue( float value, int* index1, int* index2 );
235 
236  // \returns the Value for the first state or 0 if there are no states
237  float FirstStateValue()
238  {
239  if( _stateArray.Count() )
240  {
241  return _stateArray.InternalArray()[ 0 ].Value();
242  }
243  else
244  {
245  return 0;
246  }
247  }
248 
249  // \returns the Value for the last state or 0 if there are no states
250  float LastStateValue()
251  {
252  if( _stateArray.Count() )
253  {
254  return _stateArray.InternalArray()[ _stateArray.Count() - 1 ].Value();
255  }
256  else
257  {
258  return 0;
259  }
260  }
261 
262  /** Get the linearly interpolated location along the path for the given value.
263  * \param value The value used to get the path location
264  */
265  GLSGEN_GLSDYNAMICPATH_EXPORT Vector GetPathLocation( float value );
266 
267  /** Get the linearly interpolated rotation along the path for the given value.
268  * \param value The value used to get the path rotation
269  */
270  GLSGEN_GLSDYNAMICPATH_EXPORT Vector GetPathRotation( float value );
271 
272  /** Get the linearly interpolated scale along the path for the given value.
273  * \param value The value used to get the path scale
274  */
275  GLSGEN_GLSDYNAMICPATH_EXPORT Vector GetPathScale( float value );
276 
277  /** Moves a DisplayObject to the position along the path corresponding with the given value.
278  * \param obj the DisplayObject to move
279  * \param value The value used to position the object on the path
280  */
281  GLSGEN_GLSDYNAMICPATH_EXPORT void MoveObject( DisplayObject* obj, float value );
282 
283  /** Sets the object to the position corresponding with the given state.
284  * Which values are applied is controlled by the AffectsLocation* and AffectsRotation* properties.
285  * \param obj Pointer to the object to move.
286  * \param stateNumber The index of the state to set the object to. If this value is outside the range [0,StateArray().Count()-1] nothing is done.
287  */
288  GLSGEN_GLSDYNAMICPATH_EXPORT void MoveObjectToState( DisplayObject* obj, int stateNumber );
289 
290 protected:
291 #ifdef GLES
292  /** Set a single attribute from the GLO file.
293  * \param data The attribute to set and its associated data.
294  */
295  virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data );
296 #endif
297 
298  bool _affectsLocationX;
299  bool _affectsLocationY;
300  bool _affectsLocationZ;
301  bool _affectsRotationX;
302  bool _affectsRotationY;
303  bool _affectsRotationZ;
304  bool _affectsScaleX;
305  bool _affectsScaleY;
306  bool _affectsScaleZ;
307 
308  bool _useShortRotationPaths;
309 
310  StateArrayType _stateArray;
311 };
312 
313 } // namespace disti
314 
315 #endif
Definition: cull.h:49
void MoveObjectToState(DisplayObject *obj, int stateNumber)
Definition: dynamic_array.h:62
The disti::Group class. Implements groups of objects.
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:278
Vector GetPathLocation(float value)
Definition: gls_dynamic_path.h:180
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint)
Definition: display.h:97
DisplayObject(float x, float y, float z)
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
virtual DisplayObject * CloneObject(bool generateNames=false)
VertexNoColor Vector
Definition: gls_font_base.h:66
void Count(const unsigned int count)
Definition: dynamic_array.h:115
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
Definition: gls_dynamic_path.h:84
virtual DistiAttributeBase & Resource(const char *name)
virtual void SetAvailableAttributes(unsigned int value)
Definition: disti_metadata.h:174
Definition: events.h:110
T * InternalArray(void)
Definition: dynamic_array.h:388
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler)
Definition: disti_metadata.h:667
The gls_auto_lib.
void MoveObject(DisplayObject *obj, float value)
Definition: vertex.h:83
virtual void SetValue(int spec, va_list &args)
virtual void GetResources(std::ostream &outstr, GlsResourceFilter *filter)
virtual DisplayObject * handle(DisplayEvent *ev)
Definition: gls_resources.h:50
Vector GetPathScale(float value)
Macros and helper code to determine what subset of C++11/14/17 is available.
Definition: bmpimage.h:46
virtual void CopyProperties(DisplayObject *src)
virtual void Draw(void)
Vector GetPathRotation(float value)