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