GL Studio 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) 2015 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 "group.h"
44 #include "gls_eyepoint.h"
45 #include "display_types.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) || \
53  defined(GLSGEN_IMPORT_GlsMultiView) || \
54  defined(GLS_EXPORT_GENERATED) || \
55  defined(GLS_IMPORT_GENERATED)) \
56  && defined(_MSC_VER)
57 # if defined(GLSGEN_EXPORT_GlsMultiView) || defined(GLS_EXPORT_GENERATED)
58 # define GLSGEN_GlsMultiView_EXPORT __declspec(dllexport)
59 # else
60 # define GLSGEN_GlsMultiView_EXPORT __declspec(dllimport)
61 # endif
62 #else
63 # define GLSGEN_GlsMultiView_EXPORT
64 #endif
65 ///////////////////////////////////////////////////////////////////////////////
66 
67 namespace disti
68 {
69 
70  // SetValue enumerations
71 enum {
72  GLS_GLSMULTIVIEW_FIRST_VALUE = GLS_LAST_INITIALIZER+1,
73  GLS_GLSMULTIVIEW_VIEW_DATA,
74  GLS_GLSMULTIVIEW_VIEW_DRAWING_STATE
75  };
76 class ComponentLightMgr;
77 
78 /** Runtime implementation of GlsMultiView */
79 class GlsMultiView : public Group
80 {
81  friend class GlsMultiViewEditor;
82 public:
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);
98  virtual GLSGEN_GlsMultiView_EXPORT DisplayObject *CloneObject(bool generateNames = FALSE);
99  virtual GLSGEN_GlsMultiView_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices,Culler &culler );
100  virtual GLSGEN_GlsMultiView_EXPORT void Draw(void);
101  virtual GLSGEN_GlsMultiView_EXPORT void CopyProperties(DisplayObject *src);
102 #ifndef GLES
103  virtual GLSGEN_GlsMultiView_EXPORT InterfaceListType* GetCppInterfaceDescription(InterfaceListType* addToThisList= NULL );
104  virtual GLSGEN_GlsMultiView_EXPORT void GetCppInterfaceDescriptionFree(InterfaceListType* array);
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);
112  virtual GLSGEN_GlsMultiView_EXPORT DisplayObject* handle(DisplayEvent *ev);
113  virtual GLSGEN_GlsMultiView_EXPORT DistiAttributeBase& Resource(const char *name);
114  virtual GLSGEN_GlsMultiView_EXPORT void GetResources(std::ostream& outstr, GlsResourceFilter* filter= NULL);
115  virtual GLSGEN_GlsMultiView_EXPORT void SetValue(int spec,va_list &args);
116 
117  //////////////////////////////////////////////////
118  // Object specific operations
119  //////////////////////////////////////////////////
120 
121  enum {
122  CLEAR_BG_OFF = 0,
123  CLEAR_BG_DEPTH_AND_COLOR = 1,
124  CLEAR_BG_DEPTH = 2,
125  CLEAR_BG_COLOR = 3
126  } ClearBackgroundEnum;
127 
128  class ViewData : virtual public AttributeChangedNotifier
129  {
130  friend class GlsMultiView;
131  friend class GlsMultiViewEditor;
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  private:
201  // For public access, use GetEyePoint(). It requires an object pointer.
202  GLSGEN_GlsMultiView_EXPORT GlsEyePoint* EyePoint();
203  public:
204 
205  /** Sets the clear background mode
206  * 0 == Don't Clear; 1 == Clear both; 2 == Depth only; 3 == Color only
207  * \sa ClearBackgroundEnum
208  */
209  GLSGEN_GlsMultiView_EXPORT void ClearBackground(const int &);
210  /** Gets the clear background mode */
211  GLSGEN_GlsMultiView_EXPORT int ClearBackground();
212 
213  /** Sets the pick geometry bool
214  * When true, the geometry will be traversed with Pick3D in this
215  * view.
216  */
217  GLSGEN_GlsMultiView_EXPORT void PickGeometry(const bool &);
218  /** Gets the pick geometry bool
219  */
220  GLSGEN_GlsMultiView_EXPORT bool PickGeometry();
221 
222  /** Sets the visibility of this view
223  */
224  GLSGEN_GlsMultiView_EXPORT void Visible(const bool &);
225  /** Gets the visibility of this view
226  */
227  GLSGEN_GlsMultiView_EXPORT bool Visible();
228 
229  /** Sets if this view is pickable
230  * If true, and PickGeometry() is false, the view
231  * area will be picked
232  */
233  GLSGEN_GlsMultiView_EXPORT void Pickable(const bool &);
234  /** Gets the pickability of this view
235  */
236  GLSGEN_GlsMultiView_EXPORT bool Pickable();
237 
238  // Methods for property "EyePointName"
239  GLSGEN_GlsMultiView_EXPORT void DesiredEyePoint(const GlsPropString&);
240  GLSGEN_GlsMultiView_EXPORT GlsPropString DesiredEyePoint();
241 
242  /** Finds the eyepoint or returns a previously found one.
243  * It will be based on the _desiredEyePoint.
244  */
245  GLSGEN_GlsMultiView_EXPORT GlsEyePoint* GetEyePoint(const DisplayObject* heirarchiedObject);
246 
247  /** Forces eyepoint reload */
248  GLSGEN_GlsMultiView_EXPORT void ForceEyePointReload();
249 
250  GLSGEN_GlsMultiView_EXPORT OpenGLMatrices SavedMatrices();
251 
252  };
253 
255 
256  typedef enum {
257  GEOMETRY_ONLY = 0,
258  GEOMETRY_AND_VIEWS,
259  VIEWS_ONLY
260  } ViewDrawStateEnum;
261 
262  /** Set the ViewDrawingState
263  */
264  GLSGEN_GlsMultiView_EXPORT void ViewDrawingState(ViewDrawStateEnum);
265  /** Get the ViewDrawingState
266  */
267  GLSGEN_GlsMultiView_EXPORT ViewDrawStateEnum ViewDrawingState();
268 
269  /** Returns the number of views
270  * \return The view count
271  */
272  GLSGEN_GlsMultiView_EXPORT unsigned int ViewCount();
273 
274  /** Returns a reference to the specified View object
275  * Creates it (and all views with a lower id) if it doesn't exist
276  */
277  GLSGEN_GlsMultiView_EXPORT ViewData& View(unsigned int viewNumber);
278 
279  /** Return a reference to the array containing the Views
280  */
281  GLSGEN_GlsMultiView_EXPORT ViewDataArray& ViewArray();
282 
283  /** Return the integer id of the last view that was picked or
284  * -1 if no view has been picked yet or if the GlsMultiview
285  * was picked because it is set to PICK_ALWAYS.
286  */
287  GLSGEN_GlsMultiView_EXPORT int LastViewPicked();
288 
289  /** Set the value for _emitViewDrawEvents
290  * When true, an object event is emitted at the start and
291  * end the draw of each view.
292  * VIEW_DRAW_BEGIN and VIEW_DRAW_END
293  * The data of the event is the view index.
294  *
295  * These events are currently EXPERIMENTAL and may be removed or
296  * changed in a future release. They are not accessable from the
297  * plugin GUI for this reason.
298  */
299  GLSGEN_GlsMultiView_EXPORT void EmitViewDrawEvents(const bool&);
300  /** Get the value for _emitViewDrawEvents
301  */
302  GLSGEN_GlsMultiView_EXPORT bool EmitViewDrawEvents();
303 
304  // GlsMultiView utility functions
305  void DrawView(unsigned int viewNumber, ViewData* view);
306 
307 protected:
308  void CalculateViewMatrices( const OpenGLMatrices& parentMatrices, Culler &culler, GlsMultiView::ViewData* view) const;
309  bool PreDrawGeometryForView(int viewNumber, ViewData* view);
310  void ReapplyGlobalLightsForView(ViewData* view);
311 
312 #ifdef GLES
313  /** Set a single attribute from the GLO file.
314  * \param data The attribute to set and its associated data.
315  */
316  virtual void SetFromGloData(GlsGloFileAttribute &data);
317 #endif
318 
319  ViewDrawStateEnum _viewDrawingState;
320  ViewDataArray _viewArray;
321  ViewData _mainViewData;
322  int _lastViewPicked;
323  int _lastViewPredraw; // The number of the last view predraw or -1 if predraw used parent's view
324 
325  bool _showHighlights; // Used by the editor to turn on and off highlights
326  int _highlightView; // Used by the editor to highlight a specific view. -1 is none.
327 
328  bool _emitViewDrawEvents;
329 
330  ComponentLightMgr* _multiViewLightMgr; // Our very own light manager.
331  bool _childLightsAffectGlobal; // Calculated internally based on if geometry is drawn.
332 
333  GlsMatrixType _savedProjectionMatrix; // Stores the projection matrix from PreDraw for restoring after DrawView
334 
335 private:
336  void DummySetInt(const int&) {} // Used for making a read only property
337  GlsMultiView& operator=( const GlsMultiView& ) DISTI_SPECIAL_MEM_FUN_DELETE;
338  GlsMultiView( const GlsMultiView& ) DISTI_SPECIAL_MEM_FUN_DELETE;
339 
340 };
341 
342 ///////////////////////////////////////////////////////////////////////////////
343 //
344 // DistiAttributeViewDataArray Class
345 //
346 ///////////////////////////////////////////////////////////////////////////////
347 
349 {
351 public:
353  DistiAttributeBase(caller,name,false),
354  _array(array)
355  {
356  }
357 
358  DistiAttributeBase& operator=(const DistiAttributeBase& oldClass)
359  {
360  const DistiAttributeViewDataArray* ptr;
361  if( (ptr = dynamic_cast<const DistiAttributeViewDataArray*>(&oldClass)) )
362  {
363  // Copy array contents directly
364  _array = _array;
365  CallCallback();
366  }
367  else
368  {
369  // Copy by string value
370  return DistiAttributeBase::operator=(oldClass);
371  }
372  return *this;
373  }
374 
375  std::istream& ReadValue(std::istream& instr)
376  {
377  // Scan through the token including the ':'
378  std::string buf;
379 
380  // read through opening brace
381  instr.ignore(1024,'{');
382 
383  // Clear the array before reading
384  _array.ClearList();
385 
386  while (DistiAttribDict::ScanToken(instr, buf))
387  {
388  if (buf.length())
389  {
390  int index;
391  index = atoi(buf.c_str());
392 
393  // Eat the space between the : and the data
394  instr.get();
395  instr.ignore(1024,'{');
396 
397  // This eats the closing brace
398  _array[index].Attributes().Read(instr);
399  }
400  }
401  CallCallback();
402 
403  return instr;
404  }
405 
406  std::ostream& WriteValue(std::ostream& outstr)
407  {
408  outstr << "\n" << DistiAttribDict::SpacingString()<<"{" << "\n";
410 
411  for (unsigned int i=0; i < _array.Count(); i++)
412  {
413  outstr <<DistiAttribDict::SpacingString()<< i <<":\n";
414  outstr <<DistiAttribDict::SpacingString()<<"{\n";
416 
417  _array[i].Attributes().Write(outstr);
418 
420  outstr <<DistiAttribDict::SpacingString()<<"}\n";
421  }
423  outstr <<DistiAttribDict::SpacingString()<<"}";
424  return outstr;
425  }
426 };
427 
428 } // namespace disti
429 
430 #endif
431 
Definition: cull.h:50
void ClearList(void)
Definition: dynamic_array.h:350
virtual void Draw(void)
Definition: dynamic_array.h:63
The disti::Group class. Implements groups of objects.
void EyePoint(GlsEyePoint *)
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:289
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:358
Definition: gls_multi_view.h:128
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:79
Definition: component_light_mgr.h:55
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:1173
The disti::GlsEyePoint class. Implements eyepoints.
void Count(const unsigned int count)
Definition: dynamic_array.h:120
GL Studio Enumerations and constants.
GlsMultiView(int generateInstance=FALSE)
static void SpacingInc()
Definition: gls_eyepoint.h:115
Definition: disti_metadata.h:179
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:375
Definition: disti_metadata.h:661
virtual DisplayObject * CloneObject(bool generateNames=FALSE)
Definition: callback_caller_base.h:56
The gls_auto_lib.
ViewDataArray & ViewArray()
GlsEyePoint * GetEyePoint(const DisplayObject *heirarchiedObject)
Definition: group.h:53
virtual void NotifyAttributeChanged(const AttributeName &name)
Definition: disti_metadata.h:432
const ViewData & operator=(const ViewData &)
Definition: vertex.h:84
std::ostream & WriteValue(std::ostream &outstr)
Definition: gls_multi_view.h:406
Definition: gls_resources.h:50
virtual DistiAttributeBase & Resource(const char *name)
Definition: disti_metadata.h:83
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)