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  public:
152  GLSGEN_GlsMultiView_EXPORT ViewData();
153  GLSGEN_GlsMultiView_EXPORT ViewData( const ViewData& );
154  GLSGEN_GlsMultiView_EXPORT ~ViewData();
155 
156  /** Assignment operator */
157  GLSGEN_GlsMultiView_EXPORT const ViewData& operator=( const ViewData& );
158  GLSGEN_GlsMultiView_EXPORT void CopyBaseData( const ViewData& other );
159 
160  inline DistiAttribDict& Attributes() { return *_attribDict; };
161 
162  virtual GLSGEN_GlsMultiView_EXPORT void NotifyAttributeChanged( const AttributeName& name );
163 
164  /** Sets the Screen Rectangle
165  * The screen rect is specified in 0.0-1.0 as a ratio of the available viewport
166  * e.g. 0.0, 0.0, 1.0, 1.0 uses the full screen */
167  GLSGEN_GlsMultiView_EXPORT void SetScreenRect( float bottom, float left, float top, float right );
168  /** Gets the current screen rectangle
169  */
170  GLSGEN_GlsMultiView_EXPORT void GetScreenRect( float* bottom, float* left, float* top, float* right );
171 
172  /** Set the bottom value */
173  GLSGEN_GlsMultiView_EXPORT void Bottom( const float& );
174  /** Gets the bottom value */
175  GLSGEN_GlsMultiView_EXPORT float Bottom();
176  /** Sets the left value */
177  GLSGEN_GlsMultiView_EXPORT void Left( const float& );
178  /** Gets the left value */
179  GLSGEN_GlsMultiView_EXPORT float Left();
180  /** Sets the top value */
181  GLSGEN_GlsMultiView_EXPORT void Top( const float& );
182  /** Gets the top value */
183  GLSGEN_GlsMultiView_EXPORT float Top();
184  /** Sets the right value */
185  GLSGEN_GlsMultiView_EXPORT void Right( const float& );
186  /** Gets the right value */
187  GLSGEN_GlsMultiView_EXPORT float Right();
188  /** Set the absolute pixels flag
189  * When true, the Left-Right-Top-Bottom values are interpreted
190  * as pixel coordinates, otherwise they are percentage of screen space*/
191  GLSGEN_GlsMultiView_EXPORT void AbsolutePixels( const bool& );
192  /** Get the absolute pixels flag
193  * When true, the Left-Right-Top-Bottom values are interpreted
194  * as pixel coordinates, otherwise they are percentage of screen space*/
195  GLSGEN_GlsMultiView_EXPORT bool AbsolutePixels();
196 
197  /** Sets the eyepoint to view from
198  * When NULL, the parent view is used */
199  GLSGEN_GlsMultiView_EXPORT void EyePoint( GlsEyePoint* );
200 
201  private:
202  // For public access, use GetEyePoint(). It requires an object pointer.
203  GLSGEN_GlsMultiView_EXPORT GlsEyePoint* EyePoint();
204 
205  public:
206  /** Sets the clear background mode
207  * 0 == Don't Clear; 1 == Clear both; 2 == Depth only; 3 == Color only
208  * \sa ClearBackgroundEnum
209  */
210  GLSGEN_GlsMultiView_EXPORT void ClearBackground( const int& );
211  /** Gets the clear background mode */
212  GLSGEN_GlsMultiView_EXPORT int ClearBackground();
213 
214  /** Sets the pick geometry bool
215  * When true, the geometry will be traversed with Pick3D in this
216  * view.
217  */
218  GLSGEN_GlsMultiView_EXPORT void PickGeometry( const bool& );
219  /** Gets the pick geometry bool
220  */
221  GLSGEN_GlsMultiView_EXPORT bool PickGeometry();
222 
223  /** Sets the visibility of this view
224  */
225  GLSGEN_GlsMultiView_EXPORT void Visible( const bool& );
226  /** Gets the visibility of this view
227  */
228  GLSGEN_GlsMultiView_EXPORT bool Visible();
229 
230  /** Sets if this view is pickable
231  * If true, and PickGeometry() is false, the view
232  * area will be picked
233  */
234  GLSGEN_GlsMultiView_EXPORT void Pickable( const bool& );
235  /** Gets the pickability of this view
236  */
237  GLSGEN_GlsMultiView_EXPORT bool Pickable();
238 
239  // Methods for property "EyePointName"
240  GLSGEN_GlsMultiView_EXPORT void DesiredEyePoint( const GlsPropString& );
241  GLSGEN_GlsMultiView_EXPORT GlsPropString DesiredEyePoint();
242 
243  /** Finds the eyepoint or returns a previously found one.
244  * It will be based on the _desiredEyePoint.
245  */
246  GLSGEN_GlsMultiView_EXPORT GlsEyePoint* GetEyePoint( const DisplayObject* heirarchiedObject );
247 
248  /** Forces eyepoint reload */
249  GLSGEN_GlsMultiView_EXPORT void ForceEyePointReload();
250 
251  GLSGEN_GlsMultiView_EXPORT OpenGLMatrices SavedMatrices();
252  };
253 
255 
256  typedef enum
257  {
258  GEOMETRY_ONLY = 0,
259  GEOMETRY_AND_VIEWS,
260  VIEWS_ONLY
261  } ViewDrawStateEnum;
262 
263  /** Set the ViewDrawingState
264  */
265  GLSGEN_GlsMultiView_EXPORT void ViewDrawingState( ViewDrawStateEnum );
266  /** Get the ViewDrawingState
267  */
268  GLSGEN_GlsMultiView_EXPORT ViewDrawStateEnum ViewDrawingState();
269 
270  /** Returns the number of views
271  * \return The view count
272  */
273  GLSGEN_GlsMultiView_EXPORT unsigned int ViewCount();
274 
275  /** Returns a reference to the specified View object
276  * Creates it (and all views with a lower id) if it doesn't exist
277  */
278  GLSGEN_GlsMultiView_EXPORT ViewData& View( unsigned int viewNumber );
279 
280  /** Return a reference to the array containing the Views
281  */
282  GLSGEN_GlsMultiView_EXPORT ViewDataArray& ViewArray();
283 
284  /** Return the integer id of the last view that was picked or
285  * -1 if no view has been picked yet or if the GlsMultiview
286  * was picked because it is set to PICK_ALWAYS.
287  */
288  GLSGEN_GlsMultiView_EXPORT int LastViewPicked();
289 
290  /** Set the value for _emitViewDrawEvents
291  * When true, an object event is emitted at the start and
292  * end the draw of each view.
293  * VIEW_DRAW_BEGIN and VIEW_DRAW_END
294  * The data of the event is the view index.
295  *
296  * These events are currently EXPERIMENTAL and may be removed or
297  * changed in a future release. They are not accessable from the
298  * plugin GUI for this reason.
299  */
300  GLSGEN_GlsMultiView_EXPORT void EmitViewDrawEvents( const bool& );
301  /** Get the value for _emitViewDrawEvents
302  */
303  GLSGEN_GlsMultiView_EXPORT bool EmitViewDrawEvents();
304 
305  // GlsMultiView utility functions
306  GLSGEN_GlsMultiView_EXPORT void DrawView( unsigned int viewNumber, ViewData* view );
307 
308 protected:
309  GLSGEN_GlsMultiView_EXPORT void CalculateViewMatrices( const OpenGLMatrices& parentMatrices, Culler& culler, GlsMultiView::ViewData* view ) const;
310  GLSGEN_GlsMultiView_EXPORT bool PreDrawGeometryForView( int viewNumber, ViewData* view );
311  GLSGEN_GlsMultiView_EXPORT void ReapplyGlobalLightsForView( ViewData* view );
312 
313 #ifdef GLES
314  /** Set a single attribute from the GLO file.
315  * \param data The attribute to set and its associated data.
316  */
317  GLSGEN_GlsMultiView_EXPORT virtual void SetFromGloData( GlsGloFileAttribute& data );
318 #endif
319 
320  ViewDrawStateEnum _viewDrawingState;
321  ViewDataArray _viewArray;
322  ViewData _mainViewData;
323  int _lastViewPicked;
324  int _lastViewPredraw; // The number of the last view predraw or -1 if predraw used parent's view
325 
326  bool _showHighlights; // Used by the editor to turn on and off highlights
327  int _highlightView; // Used by the editor to highlight a specific view. -1 is none.
328 
329  bool _emitViewDrawEvents;
330 
331  ComponentLightMgr* _multiViewLightMgr; // Our very own light manager.
332  bool _childLightsAffectGlobal; // Calculated internally based on if geometry is drawn.
333 
334  GlsMatrixType _savedProjectionMatrix; // Stores the projection matrix from PreDraw for restoring after DrawView
335 
336 private:
337  void DummySetInt( const int& ) {} // Used for making a read only property
338  GlsMultiView& operator=( const GlsMultiView& ) DISTI_SPECIAL_MEM_FUN_DELETE;
339  GlsMultiView( const GlsMultiView& ) DISTI_SPECIAL_MEM_FUN_DELETE;
340 };
341 
342 ///////////////////////////////////////////////////////////////////////////////
343 //
344 // DistiAttributeViewDataArray Class
345 //
346 ///////////////////////////////////////////////////////////////////////////////
347 
349 {
351 
352 public:
354  : DistiAttributeBase( caller, name, false )
355  , _array( array )
356  {
357  }
358 
359  DistiAttributeBase& operator=( const DistiAttributeBase& oldClass )
360  {
361  const DistiAttributeViewDataArray* ptr;
362  if( ( ptr = dynamic_cast<const DistiAttributeViewDataArray*>( &oldClass ) ) )
363  {
364  // Copy array contents directly
365  _array = _array;
366  CallCallback();
367  }
368  else
369  {
370  // Copy by string value
371  return DistiAttributeBase::operator=( oldClass );
372  }
373  return *this;
374  }
375 
376  std::istream& ReadValue( std::istream& instr )
377  {
378  // Scan through the token including the ':'
379  std::string buf;
380 
381  // read through opening brace
382  instr.ignore( 1024, '{' );
383 
384  // Clear the array before reading
385  _array.ClearList();
386 
387  while( DistiAttribDict::ScanToken( instr, buf ) )
388  {
389  if( buf.length() )
390  {
391  int index;
392  index = atoi( buf.c_str() );
393 
394  // Eat the space between the : and the data
395  instr.get();
396  instr.ignore( 1024, '{' );
397 
398  // This eats the closing brace
399  _array[ index ].Attributes().Read( instr );
400  }
401  }
402  CallCallback();
403 
404  return instr;
405  }
406 
407  std::ostream& WriteValue( std::ostream& outstr )
408  {
409  outstr << "\n"
411  << "\n";
413 
414  for( unsigned int i = 0; i < _array.Count(); i++ )
415  {
416  outstr << DistiAttribDict::SpacingString() << i << ":\n";
417  outstr << DistiAttribDict::SpacingString() << "{\n";
419 
420  _array[ i ].Attributes().Write( outstr );
421 
423  outstr << DistiAttribDict::SpacingString() << "}\n";
424  }
426  outstr << DistiAttribDict::SpacingString() << "}";
427  return outstr;
428  }
429 };
430 
431 } // namespace disti
432 
433 #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:278
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:359
Definition: gls_multi_view.h:127
Definition: display.h:97
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:835
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:1202
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:174
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
static bool ScanToken(std::istream &instr, std::string &result)
Definition: events.h:110
std::istream & ReadValue(std::istream &instr)
Definition: gls_multi_view.h:376
Definition: disti_metadata.h:667
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:443
const ViewData & operator=(const ViewData &)
Definition: vertex.h:83
std::ostream & WriteValue(std::ostream &outstr)
Definition: gls_multi_view.h:407
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:348
void SetScreenRect(float bottom, float left, float top, float right)