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  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
94  typedef DisplayObject _BaseClass;
95  typedef DisplayObject BaseClass;
96 
97  /** Create a new GlsDynamicPath.
98  * \param generateInstanceName Whether or not to generate an instance name
99  * for this inputdevice */
100  GLSGEN_GLSDYNAMICPATH_EXPORT GlsDynamicPath( bool generateInstanceName = false );
101 
102  /** The copy constructor for GlsDynamicPath
103  *
104  * \param that The GlsDynamicPath object that is being copied
105  * \param generateNames Whether or not to generate a new instance name
106  */
107  GLSGEN_GLSDYNAMICPATH_EXPORT GlsDynamicPath( const GlsDynamicPath& that, const bool generateNames );
108 
109  /** Destructs a GlsDynamicPath object */
110  virtual GLSGEN_GLSDYNAMICPATH_EXPORT ~GlsDynamicPath();
111 
112  static GLSGEN_GLSDYNAMICPATH_EXPORT DisplayObject* CreateInstance();
113 
114  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void SetAvailableAttributes( unsigned int value ) DISTI_METHOD_OVERRIDE;
115 
116  virtual GLSGEN_GLSDYNAMICPATH_EXPORT DisplayObject* CloneObject( bool generateNames = false ) DISTI_METHOD_OVERRIDE;
117 
118  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void CopyProperties( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
119 
120 #ifndef GLES
121  virtual GLSGEN_GLSDYNAMICPATH_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
122  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
123 #endif
124 
125  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler ) DISTI_METHOD_OVERRIDE;
126  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void Draw( void ) DISTI_METHOD_OVERRIDE;
127 
128  virtual GLSGEN_GLSDYNAMICPATH_EXPORT DisplayObject* handle( DisplayEvent* ev ) DISTI_METHOD_OVERRIDE;
129 
130  virtual GLSGEN_GLSDYNAMICPATH_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint ) DISTI_METHOD_OVERRIDE;
131 
132  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
133 
134  virtual GLSGEN_GLSDYNAMICPATH_EXPORT DistiAttributeBase& Resource( const char* name ) DISTI_METHOD_OVERRIDE;
135  virtual GLSGEN_GLSDYNAMICPATH_EXPORT void GetResources( std::ostream& outstr, GlsResourceFilter* filter ) DISTI_METHOD_OVERRIDE;
136 
137  //////////////////////////////////////////////////
138  // GlsDynamicPath specific operations
139  //////////////////////////////////////////////////
140 
141  // Controls whether the path will affect the X component of the object's dynamic translation.
142  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsLocationX( const bool& value );
143  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsLocationX() const { return _affectsLocationX; }
144 
145  // Controls whether the path will affect the Y component of the object's dynamic translation.
146  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsLocationY( const bool& value );
147  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsLocationY() const { return _affectsLocationY; }
148 
149  // Controls whether the path will affect the Z component of the object's dynamic translation.
150  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsLocationZ( const bool& value );
151  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsLocationZ() const { return _affectsLocationZ; }
152 
153  // Controls whether the path will affect the X component of the object's dynamic rotation.
154  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsRotationX( const bool& value );
155  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsRotationX() const { return _affectsRotationX; }
156 
157  // Controls whether the path will affect the Y component of the object's dynamic rotation.
158  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsRotationY( const bool& value );
159  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsRotationY() const { return _affectsRotationY; }
160 
161  // Controls whether the path will affect the Z component of the object's dynamic rotation.
162  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsRotationZ( const bool& value );
163  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsRotationZ() const { return _affectsRotationZ; }
164 
165  // Controls whether the path will affect the X component of the object's dynamic scale.
166  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsScaleX( const bool& value );
167  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsScaleX() const { return _affectsScaleX; }
168 
169  // Controls whether the path will affect the Y component of the object's dynamic scale.
170  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsScaleY( const bool& value );
171  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsScaleY() const { return _affectsScaleY; }
172 
173  // Controls whether the path will affect the Z component of the object's dynamic scale.
174  GLSGEN_GLSDYNAMICPATH_EXPORT void AffectsScaleZ( const bool& value );
175  GLSGEN_GLSDYNAMICPATH_EXPORT bool AffectsScaleZ() const { return _affectsScaleZ; }
176 
177  // If true, the shortest path between rotations is taken (360 degrees = no net rotation). If false, the long path is taken.
178  GLSGEN_GLSDYNAMICPATH_EXPORT void UseShortRotationPaths( const bool& value );
179  GLSGEN_GLSDYNAMICPATH_EXPORT bool UseShortRotationPaths() const { return _useShortRotationPaths; }
180 
181  // Contains the data for a state along the path
182  class State
183  {
184  friend class GlsDynamicPath;
185 
186  public:
187  GLSGEN_GLSDYNAMICPATH_EXPORT State();
188  GLSGEN_GLSDYNAMICPATH_EXPORT State( const State& );
189  GLSGEN_GLSDYNAMICPATH_EXPORT ~State();
190 
191  GLSGEN_GLSDYNAMICPATH_EXPORT const State& operator=( const State& );
192  GLSGEN_GLSDYNAMICPATH_EXPORT void MakeAttribDict();
193 
194  DistiAttribDict& Attributes()
195  {
196  if( !_attribDict )
197  MakeAttribDict();
198  return *_attribDict;
199  };
200 
201  void Location( const Vector& value ) { _location = value; }
202  Vector Location() { return _location; }
203  Vector Location() const { return _location; }
204  void Rotation( const Vector& value ) { _rotation = value; }
205  Vector Rotation() { return _rotation; }
206  Vector Rotation() const { return _rotation; }
207  void Scale( const Vector& value ) { _scale = value; }
208  Vector Scale() { return _scale; }
209  Vector Scale() const { return _scale; }
210  void Value( const float& value ) { _value = value; }
211  float Value() { return _value; }
212  float Value() const { return _value; }
213 
214  protected:
215  Vector _location;
216  Vector _rotation;
217  Vector _scale;
218  float _value;
219  DistiAttribDict* _attribDict;
220  };
221 
223 
224  // Returns the StateArray associated with this object. Use this array to modify the states that make up the path.
225  StateArrayType& StateArray() { return _stateArray; }
226  const StateArrayType& StateArray() const { return _stateArray; }
227 
228  // Iterates through the path segments and returns the first one found
229  // that contains the given value.
230  // \param value The value to search for
231  // \param index1 returns the index of the state at the start of the segment or -1 if no segments are found
232  // \param index2 returns the index of the state at the end the segment or -1 if no segments are found
233  // Special cases:
234  // value is before start of the path: index1 == index2 == 0
235  // value is past the end of the path: index1 == index2 == (StateArray().Count()-1)
236  GLSGEN_GLSDYNAMICPATH_EXPORT void FindFirstPathSegmentContainingValue( float value, int* index1, int* index2 );
237 
238  // \returns the Value for the first state or 0 if there are no states
239  float FirstStateValue()
240  {
241  if( _stateArray.Count() )
242  {
243  return _stateArray[ 0 ].Value();
244  }
245  else
246  {
247  return 0;
248  }
249  }
250 
251  // \returns the Value for the last state or 0 if there are no states
252  float LastStateValue()
253  {
254  if( _stateArray.Count() )
255  {
256  return _stateArray[ _stateArray.Count() - 1 ].Value();
257  }
258  else
259  {
260  return 0;
261  }
262  }
263 
264  /** Get the linearly interpolated location along the path for the given value.
265  * \param value The value used to get the path location
266  */
267  GLSGEN_GLSDYNAMICPATH_EXPORT Vector GetPathLocation( float value );
268 
269  /** Get the linearly interpolated rotation along the path for the given value.
270  * \param value The value used to get the path rotation
271  */
272  GLSGEN_GLSDYNAMICPATH_EXPORT Vector GetPathRotation( float value );
273 
274  /** Get the linearly interpolated scale along the path for the given value.
275  * \param value The value used to get the path scale
276  */
277  GLSGEN_GLSDYNAMICPATH_EXPORT Vector GetPathScale( float value );
278 
279  /** Moves a DisplayObject to the position along the path corresponding with the given value.
280  * \param obj the DisplayObject to move
281  * \param value The value used to position the object on the path
282  */
283  GLSGEN_GLSDYNAMICPATH_EXPORT void MoveObject( DisplayObject* obj, float value );
284 
285  /** Sets the object to the position corresponding with the given state.
286  * Which values are applied is controlled by the AffectsLocation* and AffectsRotation* properties.
287  * \param obj Pointer to the object to move.
288  * \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.
289  */
290  GLSGEN_GLSDYNAMICPATH_EXPORT void MoveObjectToState( DisplayObject* obj, int stateNumber );
291 
292 protected:
293 #ifdef GLES
294  /** Set a single attribute from the GLO file.
295  * \param data The attribute to set and its associated data.
296  */
297  virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
298 #endif
299 
300  bool _affectsLocationX;
301  bool _affectsLocationY;
302  bool _affectsLocationZ;
303  bool _affectsRotationX;
304  bool _affectsRotationY;
305  bool _affectsRotationZ;
306  bool _affectsScaleX;
307  bool _affectsScaleY;
308  bool _affectsScaleZ;
309 
310  bool _useShortRotationPaths;
311 
312  StateArrayType _stateArray;
313 };
314 
315 } // namespace disti
316 
317 #endif
Definition: cull.h:49
void MoveObjectToState(DisplayObject *obj, int stateNumber)
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:436
unsigned Count() const
Definition: dynamic_array.h:204
Definition: dynamic_array.h:66
The disti::Group class. Implements groups of objects.
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:473
Vector GetPathLocation(float value)
Definition: gls_dynamic_path.h:182
Definition: display.h:98
virtual DisplayObject * handle(DisplayEvent *ev) DISTI_METHOD_OVERRIDE
virtual void Draw(void) DISTI_METHOD_OVERRIDE
DisplayObject(float x, float y, float z)
virtual void CopyProperties(DisplayObject *src) DISTI_METHOD_OVERRIDE
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array) DISTI_METHOD_OVERRIDE
virtual void SetAvailableAttributes(unsigned int value) DISTI_METHOD_OVERRIDE
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler) DISTI_METHOD_OVERRIDE
VertexNoColor Vector
Definition: gls_font_base.h:66
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) DISTI_METHOD_OVERRIDE
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint) DISTI_METHOD_OVERRIDE
Definition: gls_dynamic_path.h:84
virtual void SetValue(int spec, va_list &args) DISTI_METHOD_OVERRIDE
virtual DisplayObject * CloneObject(bool generateNames=false) DISTI_METHOD_OVERRIDE
Definition: disti_metadata.h:186
Definition: events.h:112
virtual DistiAttributeBase & Resource(const char *name) DISTI_METHOD_OVERRIDE
Definition: disti_metadata.h:668
The gls_auto_lib.
void MoveObject(DisplayObject *obj, float value)
Definition: vertex.h:84
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
Vector GetPathRotation(float value)
virtual void GetResources(std::ostream &outstr, GlsResourceFilter *filter) DISTI_METHOD_OVERRIDE