GL Studio C++ Runtime API
gls_eyepoint.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsEyePoint class. Implements eyepoints.
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 _GLS_EYEPOINT_H
41 #define _GLS_EYEPOINT_H
42 
43 #include "display.h"
44 #include "disti_metadata.h"
45 #include "gls_color.h"
46 #include "gls_cpp_lang_support.h"
47 #include "gls_include.h"
49 
50 namespace disti
51 {
52 /**
53  Eye Point Initializers
54 */
55 typedef enum
56 {
57  GLS_EYEPOINT_FOV = GLS_LAST_INITIALIZER + 1,
58  GLS_EYEPOINT_ORTHOGRAPHIC,
59  GLS_EYEPOINT_ORTHO_SIZE,
60  GLS_EYEPOINT_FOV_IS_HORIZONTAL,
61  GLS_EYEPOINT_ASPECT,
62  GLS_EYEPOINT_NEAR_CLIP,
63  GLS_EYEPOINT_FAR_CLIP,
64  GLS_EYEPOINT_MAINTAIN_ASPECT,
65  GLS_EYEPOINT_VIEW_VECTORS
67 
68 class GlsEyePoint;
69 
70 /** Eye Point Calc View Callback Base */
72 {
73 public:
74  virtual ~EyePointCalcViewCallbackBase() {}
75  virtual void Call( int viewWidth,
76  int viewHeight,
77  GlsEyePoint* thisEye,
78  double& rval1,
79  double& rval2 )
80  = 0;
81 };
82 template<class T>
83 /** Eye Point Calc View Callback */
85 {
86 public:
87  typedef void ( T::*MethodType )(
88  int viewWidth,
89  int viewHeight,
90  GlsEyePoint* thisEye,
91  double& rval1,
92  double& rval2 );
93  // The object which contains the method to call
94  T* _container;
95  MethodType _method;
96 
97  EyePointCalcViewCallback( T* container, MethodType method )
98  : _container( container )
99  , _method( method )
100  {
101  }
102  void Call( int viewWidth,
103  int viewHeight,
104  GlsEyePoint* thisEye,
105  double& rval1,
106  double& rval2 )
107  {
108  if( _container )
109  ( _container->*( _method ) )( viewWidth, viewHeight, thisEye, rval1, rval2 );
110  }
111 };
112 /**
113  The GlsEyePoint class. Implements Eyepoints
114 */
116 {
117 public:
118  typedef DisplayObject _BaseClass;
119  friend class GlsEyePointEditor;
120 
121  typedef enum
122  {
123  FOV_CONSTRAINT_NONE,
124  FOV_CONSTRAINT_GREATER,
125  FOV_CONSTRAINT_LESS,
126  FOV_CONSTRAINT_EXACTLY
127  } FovConstraintType;
128 
129 private:
130  static bool _drawDebugGeometry; /** Causes eyepoints to draw debugging geometry. Defaults to false. */
131 
132 protected:
133  double _fov; /** Field of view of eyepoint in Degrees, if _fovIsHorizontal is true, this is horizontal */
134  double _otherFov; /** Field of view for the other direction, based on _fovIsHorizontal */
135  bool _orthographic; /** True if orthographic projection, else perspective projection */
136  double _orthoSize; /** Size of ortho projection in logical units, if _fovIsHorizontal is true, this is horizontal */
137  double _otherOrthoSize; /** Size of ortho projection for the other direction, based on _fovIsHorizontal */
138  bool _fovIsHorizontal; /** True if field of view measurement is along horizonal axis, else along vertical axis */
139  FovConstraintType _horizontalConstraint; /** The type of constraint in the horizontal direction */
140  FovConstraintType _verticalConstraint; /** The type of constraint in the vertical direction */
141  double _nearClip; /** Distance from eyepoint to near clipping plane */
142  double _farClip; /** Distance from eyepoint to far clipping plane */
143  Vector _viewVectors[ 3 ]; /** 3 vectors used to set the orientation of the eyepoint */
144 
145  EyePointCalcViewCallbackBase* _alternateCalcOrthographicView; /** Alternate callback for calculating the orthographic view */
146  EyePointCalcViewCallbackBase* _alternateCalcPerspectiveView; /** Alternate callback for calculating the perspective view */
147 
148 #ifdef GLES
149  /** Set a single attribute from the GLO file.
150  * \param data The attribute to set and its associated data.
151  */
152  virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data );
153 #endif
154 
155 public:
156  /** Set DrawDebugGeometry to true to cause eyepoints to draw at runtime.
157  * This affects all eyepoint instances.
158  */
159  static GLS_EXPORT void DrawDebugGeometry( bool draw ) { _drawDebugGeometry = draw; }
160 
161  /* See base class */
162  virtual GLS_EXPORT DisplayObject* CloneObject( bool generateNames = false );
163 
164  /** Allocate a (blank) EyePoint object */
165  GLS_EXPORT GlsEyePoint();
166 
167  /** The copy constructor for GlsEyePoint
168  *
169  * \param that The GlsEyePoint object that is being copied
170  * \param generateNames Whether or not to generate a new instance name
171  */
172  GLS_EXPORT GlsEyePoint( const GlsEyePoint& that, const bool generateNames );
173 
174  /** Destroy an Eyepoint object */
175  virtual GLS_EXPORT ~GlsEyePoint( void );
176 
177  virtual GLS_EXPORT void SetAvailableAttributes( unsigned int value );
178 
179  /** Draws does nothing because this object is not a visible object,
180  * unless DrawDebugGeometry() is true, then it draws the view frustum. */
181  virtual GLS_EXPORT void Draw( void );
182 
183 #ifndef GLES
184  /** Draws a representation of the frustum. This is done primarily for the editor.
185  * but is available at runtime. The specific values can be specified to avoid
186  * making the editor set them and set them back.*/
187  virtual GLS_EXPORT void DrawFrustum(
188  bool selected,
189  bool orthographic,
190  bool fovIsHorizontal,
191  double orthoSize,
192  double otherOrthoSize,
193  double fov,
194  double otherFov,
195  FovConstraintType horizontalConstraint,
196  FovConstraintType verticalConstraint,
197  double farClip,
198  double nearClip );
199 #endif
200 
201  /* See base class */
202  virtual GLS_EXPORT void CopyGeometry( DisplayObject* src );
203 
204  /* See base class */
205  virtual GLS_EXPORT void CopyProperties( DisplayObject* src );
206 
207 #ifndef GLES
208  /* See base class */
209  virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList );
210 
211  /* See base class */
212  virtual GLS_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* list );
213 #endif
214 
215  /* Unhides base class implementation. */
216  using _BaseClass::Rotate;
217 
218  /* See base class */
219  virtual GLS_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis );
220 
221  /* See base class */
222  virtual GLS_EXPORT void SetValue( int spec, va_list& args );
223 
224  /** Sets the Field Of View for this eyepoint.
225  * If FovIsHorizontal, this is the horizontal fov.
226  * \param fovDeg The new field of view, in degrees
227  */
228  GLS_EXPORT void FOV( double fovDeg );
229 
230  /** Sets the Field Of View for this eyepoint.
231  * If FovIsHorizontal, this is the vertical fov.
232  * \param fovDeg The new field of view, in degrees
233  */
234  GLS_EXPORT void OtherFOV( double fovDeg );
235 
236  /** Sets whether or not the field of view measurement is along horizontal or vertical axis
237  * \param val True if FOV measurement is along horizonal axis of eyepoint
238  */
239  GLS_EXPORT void FovIsHorizontal( bool val );
240 
241  /** Sets whether the eyepoint uses an orthographic projection or a perspective projection
242  * \param val True if the eypoint uses an orthographic projection. False if it uses a perspective projection.
243  */
244  GLS_EXPORT void Orthographic( bool val );
245 
246  /** Sets the size of the orthographic projection, in logical units.
247  * The direction this controls is set by FovIsHorizontal. If true, it is horizontal.
248  * \param val The size of the orthographic projection, in logical units
249  */
250  GLS_EXPORT void OrthoSize( double val );
251 
252  /** Sets the size of the orthographic projection, in logical units.
253  * The direction this controls is set by FovIsHorizontal. If true, it is vertical.
254  * \param val The size of the orthographic projection, in logical units
255  */
256  GLS_EXPORT void OtherOrthoSize( double val );
257 
258  /** Sets the distance to the near clipping plane from the eyepoint
259  * \param val Distance to the near clipping plane from the eyepoint in logical units
260  */
261  GLS_EXPORT void NearClip( double val );
262 
263  /** Sets the distance to the far clipping plane from the eyepoint
264  * \param val Distance to the far clipping plane from the eyepoint in logical units
265  */
266  GLS_EXPORT void FarClip( double val );
267 
268  /** Sets the constraint for the horizontal direction
269  */
270  GLS_EXPORT void HorizontalConstraint( FovConstraintType val );
271 
272  /** Sets the constraint for the vertical direction
273  */
274  GLS_EXPORT void VerticalConstraint( FovConstraintType val );
275 
276  /** Allows the view vectors to be set directly.
277  * These are normally controlled by the Orientation call
278  */
279  GLS_EXPORT void SetViewVectors( const Vector& x, const Vector& y, const Vector& z );
280 
281  /** Gets the Field Of View for this eyepoint.
282  * If FovIsHorizontal is true, this is the horizontal fov.
283  * \return The field of view, in degrees
284  */
285  GLS_EXPORT double FOV( void );
286 
287  /** Gets the Field Of View for this eyepoint.
288  * If FovIsHorizontal is true, this is the vertical fov.
289  * \return The field of view, in degrees
290  */
291  GLS_EXPORT double OtherFOV( void );
292 
293  /** Gets whether or not the field of view measurement is along horizontal or vertical axis
294  * \return True if FOV measurement is along horizonal axis of eyepoint
295  */
296  GLS_EXPORT bool FovIsHorizontal( void );
297 
298  /** Gets whether the eyepoint uses an orthographic projection or a perspective projection
299  * \return True if the eypoint uses an orthographic projection. False if it uses a perspective projection.
300  */
301  GLS_EXPORT bool Orthographic( void );
302 
303  /** Sets the size of the orthographic projection, in logical units.
304  * The direction this returns is set by FovIsHorizontal. If true, it is horizontal.
305  */
306  GLS_EXPORT double OrthoSize( void );
307 
308  /** Sets the size of the orthographic projection, in logical units.
309  * The direction this returns is set by FovIsHorizontal. If true, it is vertical.
310  */
311  GLS_EXPORT double OtherOrthoSize( void );
312 
313  /** Gets the distance to the near clipping plane from the eyepoint
314  * \return Distance to the near clipping plane from the eyepoint in logical units
315  */
316  GLS_EXPORT double NearClip( void );
317 
318  /** Gets the distance to the far clipping plane from the eyepoint
319  * \return Distance to the far clipping plane from the eyepoint in logical units
320  */
321  GLS_EXPORT double FarClip( void );
322 
323  /** Gets the constraint for the horizontal direction
324  */
325  GLS_EXPORT FovConstraintType HorizontalConstraint( void );
326 
327  /** Gets the constraint for the vertical direction
328  */
329  GLS_EXPORT FovConstraintType VerticalConstraint( void );
330 
331  /** Returns the current view vectors.
332  */
333  GLS_EXPORT void GetViewVectors( Vector& x, Vector& y, Vector& z );
334 
335  /** Sets the orientation of the eyepoint
336  * \param direction A direction vector
337  * \param roll A roll value about the direction vector, in degrees
338  * \param upVector defines the "up" direction for the purposes of calculating roll.
339  */
340  GLS_EXPORT void Orientation( const Vector& direction, float roll, const Vector& upVector = Vector( 0, 1, 0 ) /* Y Axis */ );
341 
342  /** Gets the current direction vector of the eyepoint
343  * \return The direction vector
344  */
345  GLS_EXPORT Vector Direction( void );
346 
347  /** Gets the current roll angle of the eyepoint
348  * \return The current roll
349  * \param upVector The "up" direction used for determining roll.
350  */
351  GLS_EXPORT float Roll( const Vector upVector = Vector( 0, 1, 0 ) /* Y Axis */ );
352 
353  /** Called by ApplyViewMatrices() to do the sizing logic
354  */
355  virtual GLS_EXPORT void CalcOrthographicView(
356  int viewWidth,
357  int viewHeight,
358  GlsEyePoint* thisEye,
359  double& fovY,
360  double& aspect );
361 
362  /** Called by ApplyViewMatrices() to do the sizing logic
363  */
364  virtual GLS_EXPORT void CalcPerspectiveView(
365  int viewWidth,
366  int viewHeight,
367  GlsEyePoint* thisEye,
368  double& fovY,
369  double& aspect );
370 
371 #ifdef GLES
372  /** Calculates and applies the projection and modelview matrices for this eyepoint
373  * \param proj The projection matrix (returned)
374  * \param modelView The modelview matrix (returned)
375  * \param width The current view width
376  * \param height The current view height
377  */
378  virtual GLS_EXPORT void ApplyViewMatrices( GlsMatrixType& proj, GlsMatrixType& modelView, int width, int height );
379 #else
380  /** Calculates and applies the projection and modelview matrices for this eyepoint */
381  virtual GLS_EXPORT void ApplyViewMatrices( void );
382 #endif
383 
384  /** Returns the modelview matrix for this eyepoint.
385  * \param modelview Output
386  * \param includeEyeToWorld If true, will include all transforms up to the top of the hierarcy.
387  */
388  virtual GLS_EXPORT void GetModelViewMatrix( GlsMatrixType& modelview, bool includeEyeToWorld = true );
389  /** Returns the projection matrix for this eyepoint
390  * \param proj The requested projection matrix
391  * \param viewW The width of the view in pixels
392  * \param viewH The height of the view in pixels
393  */
394  virtual GLS_EXPORT void GetProjectionMatrix( GlsMatrixType& proj, int viewW, int viewH );
395 
396  template<class T>
397  static void SetAlternateCalcOrthographicView( GlsEyePoint* eye, T* container, typename EyePointCalcViewCallback<T>::MethodType method )
398  {
399  if( !eye )
400  return;
402  delete eye->_alternateCalcOrthographicView;
403  eye->_alternateCalcOrthographicView = new EyePointCalcViewCallback<T>( container, method );
404  }
405  template<class T>
406  static void SetAlternateCalcPerspectiveView( GlsEyePoint* eye, T* container, typename EyePointCalcViewCallback<T>::MethodType method )
407  {
408  if( !eye )
409  return;
410  if( eye->_alternateCalcPerspectiveView )
411  delete eye->_alternateCalcPerspectiveView;
412  eye->_alternateCalcPerspectiveView = new EyePointCalcViewCallback<T>( container, method );
413  }
414 
415 private:
416  // Returns the 16 doubles representing the ModelView matrix
417  // Must set with bool_includeEyeToWorld before reading
418  GLS_EXPORT GlsPropString GetModelViewMatrix();
419  GLS_EXPORT void GetModelViewMatrix( const GlsPropString& bool_includeEyeToWorld );
420  bool _getModelViewMatrixIncludeEyeToWorld;
421 
422  // Returns the 16 doubles representing the Projection matrix
423  // Must set with int_width_height before reading
424  GLS_EXPORT GlsPropString GetProjectionMatrix();
425  GLS_EXPORT void GetProjectionMatrix( const GlsPropString& int_width_height );
426  int _getProjectionMatrixWidth;
427  int _getProjectionMatrixHeight;
428 
429  /** Assignment operator not implemented. Use CloneObject() or the copy constructor instead. */
430  GlsEyePoint& operator=( const GlsEyePoint& that ) DISTI_SPECIAL_MEM_FUN_DELETE;
431  GlsEyePoint( const GlsEyePoint& ) DISTI_SPECIAL_MEM_FUN_DELETE;
432 };
433 
434 ///////////////////////////////////////////////////////////
435 // DistiAttributeFovConstraintTypeEnum
436 ///////////////////////////////////////////////////////////
437 /** Disti Attribute Fov Constrain tType Enum */
438 class DistiAttributeFovConstraintTypeEnum : public DistiAttributeEnum<GlsEyePoint, GlsEyePoint::FovConstraintType, GlsEyePoint::FovConstraintType>
439 {
440 public:
441  GLS_EXPORT DistiAttributeFovConstraintTypeEnum( GlsEyePoint* frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName& name );
442  virtual GLS_EXPORT ~DistiAttributeFovConstraintTypeEnum();
443 };
444 
445 } // namespace disti
446 
447 #endif
double _otherFov
Definition: gls_eyepoint.h:134
bool _orthographic
Definition: gls_eyepoint.h:135
The disti metadata.
double _farClip
Definition: gls_eyepoint.h:142
Definition: gls_eyepoint.h:71
EyePointCalcViewCallbackBase * _alternateCalcOrthographicView
Definition: gls_eyepoint.h:145
double FOV(void)
Definition: dynamic_array.h:62
double _orthoSize
Definition: gls_eyepoint.h:136
bool _fovIsHorizontal
Definition: gls_eyepoint.h:138
Vector Direction(void)
virtual void CalcOrthographicView(int viewWidth, int viewHeight, GlsEyePoint *thisEye, double &fovY, double &aspect)
double _otherOrthoSize
Definition: gls_eyepoint.h:137
Definition: display.h:98
virtual void SetValue(int spec, va_list &args)
void GetViewVectors(Vector &x, Vector &y, Vector &z)
virtual void Draw(void)
void Orientation(const Vector &direction, float roll, const Vector &upVector=Vector(0, 1, 0))
The Color class: Implements a 4 component RGBA color.
Definition: gls_eyepoint.h:438
double OrthoSize(void)
A file for all GL Studio files to include.
Definition: gls_glo_file.h:982
The disti::DisplayObject class and global enumerations.
FovConstraintType HorizontalConstraint(void)
Vector _viewVectors[3]
Definition: gls_eyepoint.h:143
VertexNoColor Vector
Definition: gls_font_base.h:66
Definition: disti_metadata.h:852
virtual void CopyProperties(DisplayObject *src)
FovConstraintType VerticalConstraint(void)
virtual void CalcPerspectiveView(int viewWidth, int viewHeight, GlsEyePoint *thisEye, double &fovY, double &aspect)
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList)
void SetViewVectors(const Vector &x, const Vector &y, const Vector &z)
GLS_EyePoint_Initializers
Definition: gls_eyepoint.h:55
FovConstraintType _horizontalConstraint
Definition: gls_eyepoint.h:139
double FarClip(void)
bool Orthographic(void)
Definition: gls_eyepoint.h:115
double OtherOrthoSize(void)
double NearClip(void)
virtual void Rotate(float angle, int axis=Z_AXIS)
float Roll(const Vector upVector=Vector(0, 1, 0))
bool FovIsHorizontal(void)
double _nearClip
Definition: gls_eyepoint.h:141
double _fov
Definition: gls_eyepoint.h:133
virtual void DrawFrustum(bool selected, bool orthographic, bool fovIsHorizontal, double orthoSize, double otherOrthoSize, double fov, double otherFov, FovConstraintType horizontalConstraint, FovConstraintType verticalConstraint, double farClip, double nearClip)
EyePointCalcViewCallbackBase * _alternateCalcPerspectiveView
Definition: gls_eyepoint.h:146
Defines templated metadata classes for DisplayObjects and other uses.
virtual void GetModelViewMatrix(GlsMatrixType &modelview, bool includeEyeToWorld=true)
Definition: vertex.h:84
Definition: gls_eyepoint.h:84
virtual void Rotate(const Vector &orig, float angle, const Vector &axis)
virtual void CopyGeometry(DisplayObject *src)
virtual DisplayObject * CloneObject(bool generateNames=false)
virtual ~GlsEyePoint(void)
Macros and helper code to determine what subset of C++11/14/17 is available.
virtual void ApplyViewMatrices(void)
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *list)
Definition: disti_metadata.h:84
virtual void SetAvailableAttributes(unsigned int value)
Definition: bmpimage.h:46
static void DrawDebugGeometry(bool draw)
Definition: gls_eyepoint.h:159
double OtherFOV(void)
FovConstraintType _verticalConstraint
Definition: gls_eyepoint.h:140
virtual void GetProjectionMatrix(GlsMatrixType &proj, int viewW, int viewH)