GL Studio C++ Runtime API
gls_multi_view.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsMultiView 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 INCLUDED_DISTI_GLS_MULTI_VIEW_H
41 #define INCLUDED_DISTI_GLS_MULTI_VIEW_H
42 
43 #include "display_types.h"
44 #include "gls_eyepoint.h"
45 #include "group.h"
46 
47 #define LIB_BASE_NAME "gls_multi_view"
48 #include "gls_auto_lib.h"
49 #undef LIB_BASE_NAME
50 
51 //////////////////// Provides support for creating DLLs ////////////////////////
52 #if( defined( GLSGEN_EXPORT_GlsMultiView ) || defined( GLSGEN_IMPORT_GlsMultiView ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
53  && defined( _MSC_VER )
54 # if defined( GLSGEN_EXPORT_GlsMultiView ) || defined( GLS_EXPORT_GENERATED )
55 # define GLSGEN_GlsMultiView_EXPORT __declspec( dllexport )
56 # else
57 # define GLSGEN_GlsMultiView_EXPORT __declspec( dllimport )
58 # endif
59 #else
60 # define GLSGEN_GlsMultiView_EXPORT
61 #endif
62 ///////////////////////////////////////////////////////////////////////////////
63 
64 namespace disti
65 {
66 // SetValue enumerations
67 enum
68 {
69  GLS_GLSMULTIVIEW_FIRST_VALUE = GLS_LAST_INITIALIZER + 1,
70  GLS_GLSMULTIVIEW_VIEW_DATA,
71  GLS_GLSMULTIVIEW_VIEW_DRAWING_STATE
72 };
73 class ComponentLightMgr;
74 
75 /** Runtime implementation of GlsMultiView */
76 class GlsMultiView : public Group
77 {
78  friend class GlsMultiViewEditor;
79 
80 public:
81  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
82  typedef Group _BaseClass;
83  typedef Group BaseClass;
84 
85  /** Create a new GlsMultiView.
86  * \param generateInstance Whether or not to generate an instance name
87  * for this inputdevice */
88  GLSGEN_GlsMultiView_EXPORT GlsMultiView( int generateInstance = FALSE );
89 
90  GLSGEN_GlsMultiView_EXPORT GlsMultiView( const GlsMultiView& that, const bool generateNames );
91 
92  /** GlsMultiView deconstructor */
93  virtual GLSGEN_GlsMultiView_EXPORT ~GlsMultiView();
94 
95  static GLSGEN_GlsMultiView_EXPORT DisplayObject* CreateInstance();
96 
97  virtual GLSGEN_GlsMultiView_EXPORT void SetAvailableAttributes( unsigned int value ) DISTI_METHOD_OVERRIDE;
98  virtual GLSGEN_GlsMultiView_EXPORT DisplayObject* CloneObject( bool generateNames = FALSE ) DISTI_METHOD_OVERRIDE;
99  virtual GLSGEN_GlsMultiView_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler ) DISTI_METHOD_OVERRIDE;
100  virtual GLSGEN_GlsMultiView_EXPORT void Draw( void ) DISTI_METHOD_OVERRIDE;
101  virtual GLSGEN_GlsMultiView_EXPORT void CopyProperties( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
102 #ifndef GLES
103  virtual GLSGEN_GlsMultiView_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
104  virtual GLSGEN_GlsMultiView_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
105 #endif
106  virtual GLSGEN_GlsMultiView_EXPORT DisplayObject* Pick3D( const Vector& winLoc,
107  const Vector& logicalCoords,
108  float scale,
109  const Vector& directionVector,
110  Vector& collisionWinLoc, /*Returned*/
111  const OpenGLMatrices& drawnMatrices ) DISTI_METHOD_OVERRIDE;
112  virtual GLSGEN_GlsMultiView_EXPORT DisplayObject* handle( DisplayEvent* ev ) DISTI_METHOD_OVERRIDE;
113  virtual GLSGEN_GlsMultiView_EXPORT DistiAttributeBase& Resource( const char* name ) DISTI_METHOD_OVERRIDE;
114  virtual GLSGEN_GlsMultiView_EXPORT void GetResources( std::ostream& outstr, GlsResourceFilter* filter = NULL ) DISTI_METHOD_OVERRIDE;
115  virtual GLSGEN_GlsMultiView_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
116 
117  //////////////////////////////////////////////////
118  // Object specific operations
119  //////////////////////////////////////////////////
120 
121  enum
122  {
123  CLEAR_BG_OFF = 0,
124  CLEAR_BG_DEPTH_AND_COLOR = 1,
125  CLEAR_BG_DEPTH = 2,
126  CLEAR_BG_COLOR = 3
127  } ClearBackgroundEnum;
128 
129  class ViewData : virtual public AttributeChangedNotifier
130  {
131  friend class GlsMultiView;
132  friend class GlsMultiViewEditor;
133 
134  float _bottom;
135  float _left;
136  float _top;
137  float _right;
138  bool _absolutePixels;
139  GlsEyePoint* _eyepoint;
140  std::string _desiredEyePoint;
141  int _clearBackground;
142  bool _pickGeometry;
143  bool _visible;
144  bool _pickable;
145 
146  DistiAttribDict _attribDict;
147  GlsMatrixType* _modelMatrix;
148  GlsMatrixType* _projMatrix;
149  int* _viewPort;
150  bool _cullerVal;
151 
152  GlsMultiView* _multiView;
153 
154  GlsEyePoint* EyePoint(); // Note: For public access, use GetEyePoint(). It requires an object pointer.
155  void SetMultiview( GlsMultiView* view );
156  void InitAttributes();
157 
158  public:
159  GLSGEN_GlsMultiView_EXPORT ViewData();
160  GLSGEN_GlsMultiView_EXPORT ViewData( const ViewData& );
161  GLSGEN_GlsMultiView_EXPORT ~ViewData();
162 
163  /** Assignment operator */
164  GLSGEN_GlsMultiView_EXPORT const ViewData& operator=( const ViewData& );
165  GLSGEN_GlsMultiView_EXPORT void CopyBaseData( const ViewData& other );
166 
167  DistiAttribDict& Attributes() { return _attribDict; };
168 
169  virtual GLSGEN_GlsMultiView_EXPORT void NotifyAttributeChanged( const AttributeName& name );
170 
171  /** Sets the Screen Rectangle
172  * The screen rect is specified in 0.0-1.0 as a ratio of the available viewport
173  * e.g. 0.0, 0.0, 1.0, 1.0 uses the full screen */
174  GLSGEN_GlsMultiView_EXPORT void SetScreenRect( float bottom, float left, float top, float right );
175  /** Gets the current screen rectangle
176  */
177  GLSGEN_GlsMultiView_EXPORT void GetScreenRect( float* bottom, float* left, float* top, float* right ) const;
178 
179  /** Set the bottom value */
180  GLSGEN_GlsMultiView_EXPORT void Bottom( const float& );
181  /** Gets the bottom value */
182  GLSGEN_GlsMultiView_EXPORT float Bottom() const;
183  /** Sets the left value */
184  GLSGEN_GlsMultiView_EXPORT void Left( const float& );
185  /** Gets the left value */
186  GLSGEN_GlsMultiView_EXPORT float Left() const;
187  /** Sets the top value */
188  GLSGEN_GlsMultiView_EXPORT void Top( const float& );
189  /** Gets the top value */
190  GLSGEN_GlsMultiView_EXPORT float Top() const;
191  /** Sets the right value */
192  GLSGEN_GlsMultiView_EXPORT void Right( const float& );
193  /** Gets the right value */
194  GLSGEN_GlsMultiView_EXPORT float Right() const;
195  /** Set the absolute pixels flag
196  * When true, the Left-Right-Top-Bottom values are interpreted
197  * as pixel coordinates, otherwise they are percentage of screen space*/
198  GLSGEN_GlsMultiView_EXPORT void AbsolutePixels( const bool& );
199  /** Get the absolute pixels flag
200  * When true, the Left-Right-Top-Bottom values are interpreted
201  * as pixel coordinates, otherwise they are percentage of screen space*/
202  GLSGEN_GlsMultiView_EXPORT bool AbsolutePixels() const;
203 
204  /** Sets the eyepoint to view from
205  * When NULL, the parent view is used */
206  GLSGEN_GlsMultiView_EXPORT void EyePoint( GlsEyePoint* );
207 
208  /** Sets the clear background mode
209  * 0 == Don't Clear; 1 == Clear both; 2 == Depth only; 3 == Color only
210  * \sa ClearBackgroundEnum
211  */
212  GLSGEN_GlsMultiView_EXPORT void ClearBackground( const int& );
213  /** Gets the clear background mode */
214  GLSGEN_GlsMultiView_EXPORT int ClearBackground() const;
215 
216  /** Sets the pick geometry bool
217  * When true, the geometry will be traversed with Pick3D in this
218  * view.
219  */
220  GLSGEN_GlsMultiView_EXPORT void PickGeometry( const bool& );
221  /** Gets the pick geometry bool
222  */
223  GLSGEN_GlsMultiView_EXPORT bool PickGeometry() const;
224 
225  /** Sets the visibility of this view
226  */
227  GLSGEN_GlsMultiView_EXPORT void Visible( bool );
228  /** Gets the visibility of this view
229  */
230  GLSGEN_GlsMultiView_EXPORT bool Visible() const;
231 
232  /** Sets if this view is pickable
233  * If true, and PickGeometry() is false, the view
234  * area will be picked
235  */
236  GLSGEN_GlsMultiView_EXPORT void Pickable( bool );
237  /** Gets the pickability of this view
238  */
239  GLSGEN_GlsMultiView_EXPORT bool Pickable() const;
240 
241  // Methods for property "EyePointName"
242  GLSGEN_GlsMultiView_EXPORT void DesiredEyePoint( const GlsPropString& );
243  GLSGEN_GlsMultiView_EXPORT GlsPropString DesiredEyePoint() const;
244 
245  /** Finds the eyepoint or returns a previously found one.
246  * It will be based on the _desiredEyePoint.
247  */
248  GLSGEN_GlsMultiView_EXPORT GlsEyePoint* GetEyePoint( const DisplayObject* heirarchiedObject );
249 
250  /** Forces eyepoint reload */
251  GLSGEN_GlsMultiView_EXPORT void ForceEyePointReload();
252 
253  GLSGEN_GlsMultiView_EXPORT OpenGLMatrices SavedMatrices() const;
254  };
255 
257 
258  typedef enum
259  {
260  GEOMETRY_ONLY = 0,
261  GEOMETRY_AND_VIEWS,
262  VIEWS_ONLY
263  } ViewDrawStateEnum;
264 
265  /** Set the ViewDrawingState
266  */
267  GLSGEN_GlsMultiView_EXPORT void ViewDrawingState( ViewDrawStateEnum );
268  /** Get the ViewDrawingState
269  */
270  GLSGEN_GlsMultiView_EXPORT ViewDrawStateEnum ViewDrawingState();
271 
272  /** Returns the number of views
273  * \return The view count
274  */
275  GLSGEN_GlsMultiView_EXPORT unsigned int ViewCount() const;
276 
277  /** Returns a reference to the specified View object
278  * Creates it (and all views with a lower id) if it doesn't exist
279  */
280  GLSGEN_GlsMultiView_EXPORT ViewData& View( unsigned int viewNumber );
281 
282  /** Return a reference to the array containing the Views
283  */
284  GLSGEN_GlsMultiView_EXPORT ViewDataArray& ViewArray();
285 
286  /** Return the integer id of the last view that was picked or
287  * -1 if no view has been picked yet or if the GlsMultiview
288  * was picked because it is set to PICK_ALWAYS.
289  */
290  GLSGEN_GlsMultiView_EXPORT int LastViewPicked() const;
291 
292  /** Set the value for _emitViewDrawEvents
293  * When true, an object event is emitted at the start and
294  * end the draw of each view.
295  * VIEW_DRAW_BEGIN and VIEW_DRAW_END
296  * The data of the event is the view index.
297  *
298  * These events are currently EXPERIMENTAL and may be removed or
299  * changed in a future release. They are not accessable from the
300  * plugin GUI for this reason.
301  */
302  GLSGEN_GlsMultiView_EXPORT void EmitViewDrawEvents( const bool& );
303  /** Get the value for _emitViewDrawEvents
304  */
305  GLSGEN_GlsMultiView_EXPORT bool EmitViewDrawEvents() const;
306 
307  // GlsMultiView utility functions
308  GLSGEN_GlsMultiView_EXPORT void DrawView( unsigned int viewNumber, ViewData* view );
309 
310 protected:
311  GLSGEN_GlsMultiView_EXPORT void CalculateViewMatrices( const OpenGLMatrices& parentMatrices, Culler& culler, GlsMultiView::ViewData* view ) const;
312  GLSGEN_GlsMultiView_EXPORT bool PreDrawGeometryForView( int viewNumber, ViewData* view );
313  GLSGEN_GlsMultiView_EXPORT void ReapplyGlobalLightsForView( ViewData* view );
314 
315 #ifdef GLES
316  /** Set a single attribute from the GLO file.
317  * \param data The attribute to set and its associated data.
318  */
319  GLSGEN_GlsMultiView_EXPORT virtual void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
320 #endif
321 
322  ViewDrawStateEnum _viewDrawingState;
323  ViewDataArray _viewArray;
324  ViewData _mainViewData;
325  int _lastViewPicked;
326  int _lastViewPredraw; // The number of the last view predraw or -1 if predraw used parent's view
327 
328  bool _showHighlights; // Used by the editor to turn on and off highlights
329  int _highlightView; // Used by the editor to highlight a specific view. -1 is none.
330 
331  bool _emitViewDrawEvents;
332 
333  ComponentLightMgr* _multiViewLightMgr; // Our very own light manager.
334  bool _childLightsAffectGlobal; // Calculated internally based on if geometry is drawn.
335 
336  GlsMatrixType _savedProjectionMatrix; // Stores the projection matrix from PreDraw for restoring after DrawView
337 
338 private:
339  void OnViewDataChanged();
340  void OnViewDrawingStateChanged();
341  void OnViewArrayChange();
342 
343  void DummySetInt( const int& ) {} // Used for making a read only property
344  GlsMultiView& operator=( const GlsMultiView& ) DISTI_SPECIAL_MEM_FUN_DELETE;
345  GlsMultiView( const GlsMultiView& ) DISTI_SPECIAL_MEM_FUN_DELETE;
346 };
347 
348 ///////////////////////////////////////////////////////////////////////////////
349 //
350 // DistiAttributeViewDataArray Class
351 //
352 ///////////////////////////////////////////////////////////////////////////////
353 
355 {
357 
358 public:
360  : DistiAttributeBase( caller, name, false )
361  , _array( array )
362  {
363  }
364 
365  DistiAttributeBase& operator=( const DistiAttributeBase& oldClass )
366  {
367  const DistiAttributeViewDataArray* ptr;
368  if( ( ptr = dynamic_cast<const DistiAttributeViewDataArray*>( &oldClass ) ) )
369  {
370  // Copy array contents directly
371  _array = ptr->_array;
372  CallCallback();
373  }
374  else
375  {
376  // Copy by string value
377  return DistiAttributeBase::operator=( oldClass );
378  }
379  return *this;
380  }
381 
382  std::istream& ReadValue( std::istream& instr )
383  {
384  // Scan through the token including the ':'
385  std::string buf;
386 
387  // read through opening brace
388  instr.ignore( 1024, '{' );
389 
390  // Clear the array before reading
391  _array.Clear();
392 
393  while( DistiAttribDict::ScanToken( instr, buf ) )
394  {
395  if( buf.length() )
396  {
397  int index;
398  index = atoi( buf.c_str() );
399 
400  // Eat the space between the : and the data
401  instr.get();
402  instr.ignore( 1024, '{' );
403 
404  // This eats the closing brace
405  _array[ index ].Attributes().Read( instr );
406  }
407  }
408  CallCallback();
409 
410  return instr;
411  }
412 
413  std::ostream& WriteValue( std::ostream& outstr )
414  {
415  outstr << "\n"
417  << "\n";
419 
420  for( unsigned int i = 0; i < _array.Count(); i++ )
421  {
422  outstr << DistiAttribDict::SpacingString() << i << ":\n";
423  outstr << DistiAttribDict::SpacingString() << "{\n";
425 
426  _array[ i ].Attributes().Write( outstr );
427 
429  outstr << DistiAttribDict::SpacingString() << "}\n";
430  }
432  outstr << DistiAttribDict::SpacingString() << "}";
433  return outstr;
434  }
435 };
436 
437 } // namespace disti
438 
439 #endif
Definition: cull.h:49
virtual void SetValue(int spec, va_list &args) DISTI_METHOD_OVERRIDE
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:436
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler) DISTI_METHOD_OVERRIDE
virtual void GetResources(std::ostream &outstr, GlsResourceFilter *filter=NULL) DISTI_METHOD_OVERRIDE
virtual DisplayObject * Pick3D(const Vector &winLoc, const Vector &logicalCoords, float scale, const Vector &directionVector, Vector &collisionWinLoc, const OpenGLMatrices &drawnMatrices) DISTI_METHOD_OVERRIDE
unsigned Count() const
Definition: dynamic_array.h:204
virtual DisplayObject * handle(DisplayEvent *ev) DISTI_METHOD_OVERRIDE
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:471
ViewDrawStateEnum ViewDrawingState()
virtual DistiAttributeBase & operator=(const DistiAttributeBase &oldClass)
DistiAttributeBase & operator=(const DistiAttributeBase &oldClass)
Definition: gls_multi_view.h:365
Definition: gls_multi_view.h:129
virtual void Draw(void) DISTI_METHOD_OVERRIDE
Definition: display.h:98
unsigned int ViewCount() const
int LastViewPicked() const
static void SpacingDec()
Definition: gls_multi_view.h:76
Definition: component_light_mgr.h:55
Definition: gls_glo_file.h:988
static std::string SpacingString()
ViewData & View(unsigned int viewNumber)
bool EmitViewDrawEvents() const
virtual DisplayObject * CloneObject(bool generateNames=FALSE) DISTI_METHOD_OVERRIDE
Definition: util.h:1412
The disti::GlsEyePoint class. Implements eyepoints.
GL Studio Enumerations and constants.
GlsMultiView(int generateInstance=FALSE)
void GetScreenRect(float *bottom, float *left, float *top, float *right) const
static void SpacingInc()
Definition: gls_eyepoint.h:115
Definition: disti_metadata.h:186
static bool ScanToken(std::istream &instr, std::string &result)
Definition: events.h:112
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) DISTI_METHOD_OVERRIDE
std::istream & ReadValue(std::istream &instr)
Definition: gls_multi_view.h:382
Definition: disti_metadata.h:668
Definition: callback_caller_base.h:55
The gls_auto_lib.
ViewDataArray & ViewArray()
GlsEyePoint * GetEyePoint(const DisplayObject *heirarchiedObject)
Definition: group.h:52
virtual void NotifyAttributeChanged(const AttributeName &name)
Definition: disti_metadata.h:458
const ViewData & operator=(const ViewData &)
Definition: vertex.h:84
virtual void CopyProperties(DisplayObject *src) DISTI_METHOD_OVERRIDE
std::ostream & WriteValue(std::ostream &outstr)
Definition: gls_multi_view.h:413
Definition: gls_resources.h:50
void Clear()
Definition: dynamic_array.h:238
Definition: disti_metadata.h:85
virtual DistiAttributeBase & Resource(const char *name) DISTI_METHOD_OVERRIDE
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array) DISTI_METHOD_OVERRIDE
Definition: bmpimage.h:46
virtual ~GlsMultiView()
Definition: gls_multi_view.h:354
virtual void SetAvailableAttributes(unsigned int value) DISTI_METHOD_OVERRIDE
void SetScreenRect(float bottom, float left, float top, float right)