GL Studio C++ Runtime API
gls_moving_eye.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsMovingEye 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 _GLSMOVINGEYE_H
41 #define _GLSMOVINGEYE_H
42 
43 #include <queue>
44 
45 #include "gls_cpp_lang_support.h"
46 #include "gls_eyepoint.h"
47 
48 /// Provides support for creating DLLs
49 #if( defined( GLSGEN_EXPORT_GLSMOVINGEYE ) || defined( GLSGEN_IMPORT_GLSMOVINGEYE ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
50  && defined( _MSC_VER )
51 # if defined( GLSGEN_EXPORT_GLSMOVINGEYE ) || defined( GLS_EXPORT_GENERATED )
52 # define GLSGEN_GLSMOVINGEYE_EXPORT __declspec( dllexport )
53 # else
54 # define GLSGEN_GLSMOVINGEYE_EXPORT __declspec( dllimport )
55 # endif
56 #else
57 # define GLSGEN_GLSMOVINGEYE_EXPORT
58 #endif
59 ///////////////////////////////////////////////////////////////////////////////
60 
61 #define LIB_BASE_NAME "gls_moving_eye"
62 #include "gls_auto_lib.h"
63 #undef LIB_BASE_NAME
64 
65 namespace disti
66 {
67 // SetValue enumerations
68 enum
69 {
70  GLS_MOVINGEYE_EMIT_EVENT = GLS_EYEPOINT_VIEW_VECTORS + 1,
71  GLS_MOVINGEYE_LOOK_AT_OBJECT,
72  GLS_MOVINGEYE_MAX_SPEED,
73  GLS_MOVINGEYE_MOVEMENT,
74  GLS_MOVINGEYE_ROUTE,
75  GLS_MOVINGEYE_DISABLE_HISTORY
76 };
77 
78 //------------------------------------------------------------------------
79 /**
80 * Runtime implementation of a GlsMovingEye
81 */
82 class GlsMovingEye : public GlsEyePoint
83 {
84 private:
85  GlsMovingEye& operator=( const GlsMovingEye& ) DISTI_SPECIAL_MEM_FUN_DELETE;
86  GlsMovingEye( const GlsMovingEye& ) DISTI_SPECIAL_MEM_FUN_DELETE;
87 
88 public:
89  typedef GlsEyePoint _BaseClass;
90 
91  /// This specifies the type of route taken from one eyepoint to another.
93  {
94  CONSTANT = 0,
95  SINUSOIDAL = 1
96  };
97 
98  /// This specifies the type of route taken from one eyepoint to another.
99  enum Route_t
100  {
101  DIRECT = 0,
102  ARC = 1
103  };
104 
105  // Name of the event emitted when a move is completed
106  static const char* MOVE_COMPLETE_EVENT_NAME;
107 
108  //------------------------------------------------------------------------
109  /**
110  * Create a new GlsMovingEye.
111  */
113 
114  GLSGEN_GLSMOVINGEYE_EXPORT GlsMovingEye( const GlsMovingEye& that, const bool generateNames );
115 
116  //------------------------------------------------------------------------
117  /**
118  * GlsMovingEyeEditor destructor
119  */
121 
122  //------------------------------------------------------------------------
123  /**
124  * Returns true if the we're at the beginning of the history of movements.
125  */
126  bool AtStartOfHistory() const
127  {
128  return _historyPos == 0;
129  }
130 
131  //------------------------------------------------------------------------
132  /**
133  * Returns true if the we're at the end of the history of movements.
134  */
135  bool AtEndOfHistory() const
136  {
137  return _historyPos == _moveHistory.size() - 1;
138  }
139 
140  //------------------------------------------------------------------------
141  /**
142  * Aborts any move currently in progress.
143  */
145 
146  virtual GLSGEN_GLSMOVINGEYE_EXPORT void SetAvailableAttributes( unsigned int value );
147 
148  //------------------------------------------------------------------------
149  /* See base class */
150  virtual GLSGEN_GLSMOVINGEYE_EXPORT void Calculate( double time );
151 
152  //------------------------------------------------------------------------
153  /* See base class */
156  CloneObject( bool generateNames = false );
157 
158  //------------------------------------------------------------------------
159  /* See base class */
161 
162  //------------------------------------------------------------------------
163  /**
164  * Creates a new, blank GlsMovingEye object.
165  * \return DisplayObject type pointer to the new GlsMovingEye.
166  */
168 
169  //------------------------------------------------------------------------
170  /* See base class */
171  virtual GLSGEN_GLSMOVINGEYE_EXPORT void Draw();
172 
173  //------------------------------------------------------------------------
174  /**
175  * Returns whether or not an event is emitted upon completion of a
176  * commanded movement.
177  */
178  bool EmitEvent() const { return _emitEvent; }
179 
180  //------------------------------------------------------------------------
181  /**
182  * Sets whether or not an event is emitted upon completion of a
183  * commanded movement.
184  */
185  void EmitEvent( bool emitEvent );
186 
187  //------------------------------------------------------------------------
188  /**
189  * Returns whether or not an the move history is disabled.
190  */
191  bool DisableMoveHistory() const { return _disableMoveHistory; }
192 
193  //------------------------------------------------------------------------
194  /**
195  * Sets whether or not the move history is disabled.
196  */
197  void DisableMoveHistory( bool his );
198 
199  //------------------------------------------------------------------------
200  /* See base class */
201  virtual GLSGEN_GLSMOVINGEYE_EXPORT void GenerateInstanceName();
202 
203 #ifndef GLES
204  //------------------------------------------------------------------------
205  /* See base class */
209  InterfaceListType* addToThisList = 0 );
210 
211  //------------------------------------------------------------------------
212  /* See base class */
214 #endif
215  //------------------------------------------------------------------------
216  /**
217  * \return The name of the object that the eyepoint should be always
218  * looking at.
219  * Lifetime is guaranteed to coincide with the GlsMovingEye's lifetime
220  * or until LookAtObject is changed.
221  */
222  const std::string& LookAtObject() const { return _lookAtObject; }
223 
224  //------------------------------------------------------------------------
225  /**
226  * Sets the name of the object that the eyepoint should be always
227  * looking at.
228  */
229  void LookAtObject( const std::string& name );
230 
231  //------------------------------------------------------------------------
232  /**
233  * Returns the maximum speed in logical units/second which will
234  * be used to achive the transition between eyepoints.
235  */
236  float MaxSpeed() const { return _maxSpeed; }
237 
238  //------------------------------------------------------------------------
239  /**
240  * Sets the maximum speed in logical units/second which will
241  * be used to achive the transition between eyepoints.
242  */
243  void MaxSpeed( float speed );
244 
245  //------------------------------------------------------------------------
246  /**
247  * Returns the type of movement algorithm to use when moving to another
248  * eyepoint.
249  */
250  Movement_t Movement() const { return _movement; }
251 
252  //------------------------------------------------------------------------
253  /**
254  * Sets the type of movement algorithm to use when moving to another
255  * eyepoint.
256  */
257  void Movement( Movement_t movementType );
258 
259  //------------------------------------------------------------------------
260  /**
261  * Moves this eyepoint to the previously set eyepoint. If a move is
262  * already in progress, it will be immediately stopped, and this move
263  * will start.
264  */
266 
267  //------------------------------------------------------------------------
268  /**
269  * Moves this eyepoint to the eyepoint which was last achieved from a
270  * MoveBack(). If a move is already in progress, it will be immediately
271  * stopped, and this move will start.
272  */
274 
275  //------------------------------------------------------------------------
276  /**
277  * Causes this eye to move from its current state to the state specified
278  * by the targetEye. It will take moveTime to get there. If a move is
279  * already in progress, it will be immediately stopped, and this move
280  * will start.
281  */
283  void MoveToEye( GlsEyePoint* eye, float moveTime = 2.0f );
284 
285  //------------------------------------------------------------------------
286  /**
287  * Causes the eye to move from its current state to each eyepoint in the
288  * specified group ending with the last eye in the group. If a move is
289  * already in progress, it will be immediately stopped, and this move
290  * will start.
291  */
293  void MoveToEye( Group* eyeGroup, float moveTime = 2.0f );
294 
295  //------------------------------------------------------------------------
296  /**
297  * Causes the specified eye to be added to the end of the list of eyes
298  * which should be moved through.
299  */
301  void MoveToEyeAdd( GlsEyePoint* eye, float moveTime = 2.0f );
302 
303  //------------------------------------------------------------------------
304  /**
305  * Causes the specified eyes to be added to the end of the list of eyes
306  * which should be moved through.
307  */
309  void MoveToEyeAdd( Group* eyeGroup, float moveTime = 2.0f );
310 
311  //------------------------------------------------------------------------
312  /**
313  * Causes this eye to move to the specified location in the scene without
314  * modifying the view direction or any other eye specific information.
315  */
317  void MoveToLocation( const Vector& location, float moveTime = 2.0f );
318 
319  //------------------------------------------------------------------------
320  /**
321  * Moves the eyepoint in view-relative coordinates by the specified amount,
322  * over the specified time. The units are in relative screen coordinates:
323  * X and Y are pixels, Z is 0->1. See WindowToLogical() or
324  * LogicalToWindow().
325  */
327  const Vector& moveAmount,
328  const Vector& rotation );
329 
330  //------------------------------------------------------------------------
331  /**
332  * Returns the type of route to use when moving to another eyepoint.
333  */
334  Route_t Route() const { return _route; }
335 
336  //------------------------------------------------------------------------
337  /**
338  * Sets the type of route to use when moving to another eyepoint.
339  */
340  void Route( Route_t routeType );
341 
342  //------------------------------------------------------------------------
343  /* See base class */
344  GLSGEN_GLSMOVINGEYE_EXPORT virtual void SetValue( int spec, va_list& args );
345 
346 protected:
347 #ifdef GLES
348  /** Set a single attribute from the GLO file.
349  * \param data The attribute to set and its associated data.
350  */
351  GLSGEN_GLSMOVINGEYE_EXPORT virtual void SetFromGloData( GlsGloFileAttribute& data );
352 #endif
353 
354  /// Type to store eyepoint state information.
355  struct EyeState_t
356  {
357  Vector location;
358  bool orthographic;
359  double FOV;
360  double otherFOV;
361  bool fovIsHorizontal;
362  double orthoSize;
363  double otherOrthoSize;
364  double farClip;
365  double nearClip;
366  FovConstraintType horizontalConstraint;
367  FovConstraintType verticalConstraint;
368  Vector viewVectors[ 3 ];
369 
370  /** Default constructor */
371  EyeState_t();
372 
373  /** Initialize EyeState_t using targetEye parameters.
374  * \param movingEye The GlsMovingEye that the state information is for (needed for coordinate conversions)
375  * \param targetEye The GlsEyePoint to move to
376  */
377  EyeState_t( GlsMovingEye* movingEye, GlsEyePoint* targetEye );
378 
379  inline Vector Direction()
380  {
381  /* Copied from GlsEyePoint::Direction() */
382  return viewVectors[ 2 ];
383  }
384  };
385 
386  /// Type to store eyepoint movement parameters.
387  struct MoveParms_t : public EyeState_t
388  {
389  bool addToHistory;
390  double time;
391  std::string qualifiedEyeName;
392 
393  MoveParms_t(
394  bool storeHistory,
395  double moveTime,
396  GlsMovingEye* movingEye,
397  GlsEyePoint* targetEye );
398  };
399 
400  /// Whether or not to emit an event when the move has completed.
402 
403  /// This is true when a move is occurring and the route segment being
404  /// moved along is the very first one in the queue. This is used during
405  /// sinusoidal movement to smoothly speed up when starting.
407 
408  /// Current position into the history list
409  unsigned _historyPos;
410 
411  /// Flag to keep track of when the object gets initialized.
413 
414  /// Automatically adjust the view direction to point at the specified
415  /// targetObject. This is inactivated when the string is blank.
416  /// While this is active, the move methods will not control the view
417  /// direction. They can still control the position and other eye
418  /// information.
419  std::string _lookAtObject;
420 
421  /// The last up vector provided by the user or the move code.
422  /// Used by the 'look at' algorithm to orient the eyepoint
424 
425  /// The last up vector calculated by the lookAt algorithm.
427 
428  /// Stores a history of visited eyepoints for moving back and forth.
429  std::vector<MoveParms_t> _moveHistory;
430 
431  bool _disableMoveHistory;
432 
433  /// This specifies the maximum speed in logical units / second which will
434  /// be used to achive the transition. If the requested transition cannot
435  /// occur within the requested move time without exceeding the max speed,
436  /// the move time will be longer than requested. In other words, this
437  /// limit has priority over any requested moveTime. A MaxSpeed value of
438  /// < 0.0 means the speed limit is disabled.
439  float _maxSpeed;
440 
441  /// Type of movement algorithm to use when moving to another eyepoint.
443 
444  /// Contains movement parameters for each move that should be performed.
445  /// The last one contains the final eyepoint to stop at.
446  std::queue<MoveParms_t> _moveQ;
447 
448  /// Type of route to take when moving to another eyepoint.
450 
451  /// Stores this eyepoint's current state at the start of a move and is
452  /// used in calculating movement during each execution frame.
454 
455  /// Latest known simulation time.
456  double _simTime;
457 
458  /// Simulation time that a move starts.
459  double _startTime;
460 
461  /// This specifies the up direction and is used when interpolating
462  /// movement to keep the view oriented 'correctly'.
464 
465  /// This specifies a buffer area around _upVector and -_upVector which
466  /// the moving eye will try to avoid. Setting this to non-zero avoids
467  /// flipping problems when orientation passes through _upVector or -_upVector
468  /// during moves.
470 
471  //------------------------------------------------------------------------
472  /**
473  * Calculates the direction to the named object.
474  */
475  //------------------------------------------------------------------------
476  Vector DirectionToObj( const std::string& qualifiedObjName ) const;
477 
478  //------------------------------------------------------------------------
479  /**
480  * Extracts all eyepoint objects from the group hierarchy. The group
481  * can contain other groups and object types.
482  */
483  //------------------------------------------------------------------------
484  void ExtractEyepoints( Group* group, std::vector<GlsEyePoint*>& eyes );
485 
486  //------------------------------------------------------------------------
487  /**
488  * Called when the destination eyepoint is reached to perform actions
489  * necessary to complete the movement.
490  */
491  //------------------------------------------------------------------------
492  void FinishMoving();
493 
494  //------------------------------------------------------------------------
495  /**
496  * Initializes the movement history with the initial state of the eyepoint.
497  */
498  //------------------------------------------------------------------------
499  void Initialize();
500 
501  //------------------------------------------------------------------------
502  /**
503  * Returns an adjusted move time based on the maximum speed setting. If the
504  * speed of moving over distance in desiredTime is greater than the
505  * maximum speed setting, the move time will be lengthened.
506  *
507  * \param distance: distance in logical units that will be moved.
508  * \param desiredTime: time in which we wish to cover the specified
509  * distance.
510  */
511  //------------------------------------------------------------------------
512  float MoveTime( float distance, float desiredTime ) const;
513 
514  //------------------------------------------------------------------------
515  /**
516  * Calculates the distance over the entire route if moving between all
517  * eyepoints in the list.
518  */
519  //------------------------------------------------------------------------
520  float RouteDistance( std::vector<GlsEyePoint*>& eyes ) const;
521 
522  //------------------------------------------------------------------------
523  /**
524  * Queues the move using the passed in movement parameters and sets up
525  * the start time and starting state of the move.
526  */
527  //------------------------------------------------------------------------
528  void StartMoving( const MoveParms_t& moveParms );
529 
530  /// The editor class needs to access this class' privates. :)
531  friend class GlsMovingEyeEditor;
532 };
533 
534 //----------------------------------------------------------------------------
535 inline std::ostream& operator<<( std::ostream& outstr, GlsMovingEye::Movement_t m )
536 {
537  switch( m )
538  {
539  case GlsMovingEye::CONSTANT:
540  outstr << "CONSTANT";
541  break;
542  case GlsMovingEye::SINUSOIDAL:
543  outstr << "SINUSOIDAL";
544  break;
545  default:
546  outstr << "BAD_MOVEMENT";
547  };
548 
549  return outstr;
550 }
551 
552 //----------------------------------------------------------------------------
553 inline std::istream& operator>>( std::istream& instr, GlsMovingEye::Movement_t& m )
554 {
555  std::string str;
556  instr >> str;
557  if( str == "CONSTANT" )
558  {
559  m = GlsMovingEye::CONSTANT;
560  }
561  else if( str == "SINUSOIDAL" )
562  {
563  m = GlsMovingEye::SINUSOIDAL;
564  }
565  return instr;
566 }
567 
568 //----------------------------------------------------------------------------
569 inline std::ostream& operator<<( std::ostream& outstr, GlsMovingEye::Route_t r )
570 {
571  switch( r )
572  {
573  case GlsMovingEye::DIRECT:
574  outstr << "DIRECT";
575  break;
576  case GlsMovingEye::ARC:
577  outstr << "ARC";
578  break;
579  default:
580  outstr << "BAD_ROUTE";
581  };
582 
583  return outstr;
584 }
585 
586 //----------------------------------------------------------------------------
587 inline std::istream& operator>>( std::istream& instr, GlsMovingEye::Route_t& r )
588 {
589  std::string str;
590  instr >> str;
591  if( str == "DIRECT" )
592  {
593  r = GlsMovingEye::DIRECT;
594  }
595  else if( str == "ARC" )
596  {
597  r = GlsMovingEye::ARC;
598  }
599  return instr;
600 }
601 
602 } // namespace disti
603 #endif
unsigned _historyPos
Current position into the history list.
Definition: gls_moving_eye.h:409
Vector DirectionToObj(const std::string &qualifiedObjName) const
void MoveToEye(GlsEyePoint *eye, float moveTime=2.0f)
bool AtEndOfHistory() const
Definition: gls_moving_eye.h:135
Route_t Route() const
Definition: gls_moving_eye.h:334
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
float _bufferAngle
Definition: gls_moving_eye.h:469
virtual ~GlsMovingEye()
Definition: dynamic_array.h:62
Movement_t Movement() const
Definition: gls_moving_eye.h:250
void StartMoving(const MoveParms_t &moveParms)
Definition: display.h:97
bool AtStartOfHistory() const
Definition: gls_moving_eye.h:126
Vector _lookAtCalculatedUpVector
The last up vector calculated by the lookAt algorithm.
Definition: gls_moving_eye.h:426
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=0)
virtual void CopyProperties(DisplayObject *src)
Movement_t
This specifies the type of route taken from one eyepoint to another.
Definition: gls_moving_eye.h:92
void ExtractEyepoints(Group *group, std::vector< GlsEyePoint * > &eyes)
bool _firstSegment
Definition: gls_moving_eye.h:406
#define GLSGEN_GLSMOVINGEYE_EXPORT
Provides support for creating DLLs.
Definition: gls_moving_eye.h:57
virtual void SetAvailableAttributes(unsigned int value)
void MoveToEyeAdd(GlsEyePoint *eye, float moveTime=2.0f)
Definition: gls_glo_file.h:835
bool DisableMoveHistory() const
Definition: gls_moving_eye.h:191
bool EmitEvent() const
Definition: gls_moving_eye.h:178
Vector _upVector
Definition: gls_moving_eye.h:463
Type to store eyepoint state information.
Definition: gls_moving_eye.h:355
float RouteDistance(std::vector< GlsEyePoint * > &eyes) const
virtual void SetValue(int spec, va_list &args)
The disti::GlsEyePoint class. Implements eyepoints.
Route_t _route
Type of route to take when moving to another eyepoint.
Definition: gls_moving_eye.h:449
double _simTime
Latest known simulation time.
Definition: gls_moving_eye.h:456
Definition: gls_eyepoint.h:115
float _maxSpeed
Definition: gls_moving_eye.h:439
void MoveToLocation(const Vector &location, float moveTime=2.0f)
void MoveRelative(const Vector &moveAmount, const Vector &rotation)
Route_t
This specifies the type of route taken from one eyepoint to another.
Definition: gls_moving_eye.h:99
std::queue< MoveParms_t > _moveQ
Definition: gls_moving_eye.h:446
virtual DisplayObject * CloneObject(bool generateNames=false)
double _startTime
Simulation time that a move starts.
Definition: gls_moving_eye.h:459
The gls_auto_lib.
std::vector< MoveParms_t > _moveHistory
Stores a history of visited eyepoints for moving back and forth.
Definition: gls_moving_eye.h:429
Definition: group.h:52
float MaxSpeed() const
Definition: gls_moving_eye.h:236
bool _emitEvent
Whether or not to emit an event when the move has completed.
Definition: gls_moving_eye.h:401
Vector _lookAtReferenceUpVector
Definition: gls_moving_eye.h:423
Definition: vertex.h:83
std::string _lookAtObject
Definition: gls_moving_eye.h:419
const std::string & LookAtObject() const
Definition: gls_moving_eye.h:222
Movement_t _movement
Type of movement algorithm to use when moving to another eyepoint.
Definition: gls_moving_eye.h:442
float MoveTime(float distance, float desiredTime) const
virtual void Draw()
virtual void Calculate(double time)
static DisplayObject * CreateInstance()
Definition: gls_moving_eye.h:82
Macros and helper code to determine what subset of C++11/14/17 is available.
friend class GlsMovingEyeEditor
The editor class needs to access this class' privates. :)
Definition: gls_moving_eye.h:531
bool _initialized
Flag to keep track of when the object gets initialized.
Definition: gls_moving_eye.h:412
Definition: bmpimage.h:46
Type to store eyepoint movement parameters.
Definition: gls_moving_eye.h:387
EyeState_t _start
Definition: gls_moving_eye.h:453