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