HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUI_ViewState.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GUI_ViewState.h (Geometry Render Library, C++)
7  *
8  * COMMENTS:
9  * This class basically envelopes a DisplayOption and
10  * a ViewParameter. So it holds all the information
11  * that is relevant to viewing.
12  *
13  */
14 
15 #ifndef __GUI_ViewState__
16 #define __GUI_ViewState__
17 
18 #include "GUI_API.h"
19 #include "GUI_DisplayOption.h"
20 #include "GUI_RenderCommon.h"
21 #include "GUI_ViewParameter.h"
22 #include <RE/RE_RenderContext.h>
23 #include <UT/UT_Matrix3.h>
24 #include <UT/UT_Matrix4.h>
25 #include <UT/UT_Plane.h>
26 #include <UT/UT_Quaternion.h>
27 #include <UT/UT_Vector3.h>
28 
29 // Essentially a callback class to allow options from above GUI
30 // to be saved to the default file.
32 {
33 public:
35  virtual bool isDefaultToken(const char *token) = 0;
36  virtual bool parseDefaultOption(const char *token, UT_IStream &is) = 0;
37 
38  virtual bool save(std::ostream &os) = 0;
39 };
40 
41 
42 class UT_StringArray;
43 class TIL_Raster;
44 class GUI_SnapshotImage;
45 
47 {
48 public:
49  GUI_ViewState(bool for_lops);
50  ~GUI_ViewState();
51 
52  // member data accessors
54  { return myOption; }
56  { return myView; }
57  GUI_DisplayOption &getDisplayOptionRef() { return myOption; }
58  GUI_ViewParameter &getViewParameterRef() { return myView; }
59 
60  // sets the OpenGL state according to the view parameter
61  void setViewport(RE_RenderContext r, int x, int y, int w, int h)
62  { myView.setViewport(r, x, y, w, h); }
64  { myView.setProjection(r); }
65 
66  // methods for getting and setting the view point
67  void homeToBox(int w, int h, UT_BoundingBox &box,
68  const UT_Matrix3R *rot = NULL, bool centred = false,
69  bool zoom_in = false)
70  {
71  fpreal minh = getDisplayOptionRef().common()
72  .getMinHomeZoom();
73  myView.homeToBox(w, h, minh, box, rot,
74  centred, zoom_in);
75  myLeftView.homeToBox(w, h, minh, box, rot,
76  centred, zoom_in);
77  myRightView.homeToBox(w, h, minh, box, rot,
78  centred, zoom_in);
79  }
80  void getViewport(int &l, int &r, int &b, int &t) const
81  { myView.getViewport(l, r, b, t); }
82  UT_DimRect getViewport() const { return myView.getViewport(); }
83  void getView(int &l, int &r, int &b, int &t) const
84  { myView.getView(l, r, b, t); }
85  UT_DimRect getView() const { return myView.getView(); }
86  int getViewWidth() const { return myView.getViewWidth(); }
87  int getViewHeight() const { return myView.getViewHeight(); }
88 
90  { return myView.getItransformMatrix();}
92  { return myView.getTransformMatrix(); }
94  { return myView.getProjectionMatrix();}
96  { return myView.getRotateMatrix(); }
97  void setRotateMatrix(const UT_Matrix3R &mat)
98  { myView.setRotateMatrix(mat); }
99 
100  int initialized() const { return myView.initialized(); }
101 
102  void setOrthoFlag(int onoff)
103  {
104  myView.setOrthoFlag(onoff);
105  myLeftView.setOrthoFlag(onoff);
106  myRightView.setOrthoFlag(onoff);
107  }
108  int getOrthoFlag() const { return myView.getOrthoFlag(); }
109 
110  void setApplyAspectFlag(int onoff)
111  { myView.setApplyAspectFlag(onoff); }
112  int getApplyAspectFlag() const
113  {return myView.getApplyAspectFlag(); }
115  { myView.setAspectRatio(value); }
117  {return myView.getAspectRatio(); }
119  { myView.setDefaultFOV(value); }
121  { return myView.getDefaultFOV(); }
123  { myView.setLimits(n, f); }
124 
125  void rotate(UT_Axis3::axis axis, fpreal dx)
126  {
127  myView.rotate(axis, dx);
128  myLeftView.rotate(axis, dx);
129  myRightView.rotate(axis, dx);
130  }
131  void rotate(const UT_Vector3R &axis, fpreal dx)
132  {
133  myView.rotate(axis, dx);
134  myLeftView.rotate(axis, dx);
135  myRightView.rotate(axis, dx);
136  }
137  void rotate(const UT_Quaternion &quat)
138  {
139  myView.rotate(quat);
140  myLeftView.rotate(quat);
141  myRightView.rotate(quat);
142  }
143  void trackball(fpreal dx, fpreal dy)
144  {
145  myView.trackball(dx, dy);
146  myLeftView.trackball(dx, dy);
147  myRightView.trackball(dx, dy);
148  }
149  void dotumble(fpreal dx, fpreal dy, int changed)
150  {
151  myView.dotumble(dx, dy, changed);
152  myLeftView.dotumble(dx, dy, changed);
153  myRightView.dotumble(dx, dy, changed);
154  }
155  void scroll(fpreal dx, fpreal dy)
156  {
157  myView.scroll(dx, dy);
158  myLeftView.scroll(dx, dy);
159  myRightView.scroll(dx, dy);
160  }
161  void scroll(fpreal dx, fpreal dy,
162  const UT_InclusiveRect &viewport)
163  {
164  myView.scroll(dx, dy, viewport);
165  myLeftView.scroll(dx, dy, viewport);
166  myRightView.scroll(dx, dy, viewport);
167  }
168  void worldLockedScroll(const UT_Vector3R &locked_pos,
169  fpreal dx, fpreal dy)
170  {
171  // This method requires the projection
172  // matrix to be set correctly, which is
173  // not always the case for myLeftView
174  // and myRightView. Even if we could
175  // count on that, doing it individually
176  // for each view would tend to change
177  // the distance between the left and
178  // right views, which isn't what one
179  // wants. Instead, we just apply the
180  // same delta to the left and right
181  // views.
182  UT_Vector3D old_t = myView.getT();
183  UT_Vector3D old_p = myView.getP();
184 
185  myView.worldLockedScroll(
186  locked_pos, dx, dy);
187 
188  UT_Vector3D delta_t =
189  myView.getT() - old_t;
190  UT_Vector3D delta_p =
191  myView.getP() - old_p;
192  myLeftView.setT(
193  myLeftView.getT() + delta_t);
194  myLeftView.setP(
195  myLeftView.getP() + delta_p);
196  myRightView.setT(
197  myLeftView.getT() + delta_t);
198  myRightView.setP(
199  myLeftView.getP() + delta_p);
200  }
201  void dolly(fpreal dx,
202  bool precise_zoom = false,
203  bool smooth_dolly = false)
204  {
205  myView.dolly(dx, precise_zoom,
206  smooth_dolly);
207  myLeftView.dolly(dx, precise_zoom,
208  smooth_dolly);
209  myRightView.dolly(dx, precise_zoom,
210  smooth_dolly);
211  }
212  void directedDolly(const UT_Vector3R &unit_worldspace_dir,
213  fpreal dx,
214  bool precise_zoom = false,
215  bool smooth_dolly = false)
216  {
217  myView.directedDolly(
218  unit_worldspace_dir, dx,
219  precise_zoom,
220  smooth_dolly);
221  myLeftView.directedDolly(
222  unit_worldspace_dir, dx,
223  precise_zoom,
224  smooth_dolly);
225  myRightView.directedDolly(
226  unit_worldspace_dir, dx,
227  precise_zoom,
228  smooth_dolly);
229  }
231  bool precise_zoom = false)
232  {
233  myView.zoom(dx, item, precise_zoom);
234  myLeftView.zoom(dx, item, precise_zoom);
235  myRightView.zoom(dx, item,precise_zoom);
236  }
238  const UT_InclusiveRect &viewport,
239  bool precise_zoom = false)
240  {
241  myView.zoom(dx, item, viewport,
242  precise_zoom);
243  myLeftView.zoom(dx, item, viewport,
244  precise_zoom);
245  myRightView.zoom(dx, item, viewport,
246  precise_zoom);
247  }
248  void offsetZoom(fpreal sx, fpreal sy, fpreal dx,
250  bool precise_zoom = false)
251  {
252  myView.offsetZoom(sx, sy, dx, item,
253  precise_zoom);
254  myLeftView.offsetZoom(sx, sy, dx, item,
255  precise_zoom);
256  myRightView.offsetZoom(sx, sy, dx, item,
257  precise_zoom);
258  }
259  void offsetZoom(fpreal sx, fpreal sy, fpreal dx,
261  const UT_InclusiveRect &viewport,
262  bool precise_zoom = false)
263  {
264  myView.offsetZoom(sx, sy, dx, item,
265  viewport,
266  precise_zoom);
267  myLeftView.offsetZoom(sx, sy, dx, item,
268  viewport,
269  precise_zoom);
270  myRightView.offsetZoom(sx, sy, dx, item,
271  viewport,
272  precise_zoom);
273  }
274  void boxZoom(fpreal frstx, fpreal frsty, fpreal lastx,
275  fpreal lasty, fpreal distance)
276  { myView.boxZoom(frstx,frsty,lastx,lasty, distance); }
277 
279  {
280  myView.screenScroll(dx, dy);
281  myLeftView.screenScroll(dx, dy);
282  myRightView.screenScroll(dx, dy);
283  }
284 
286  { myOption.common().primMask(m); }
288  { return myOption.common().primMask(); }
289 
290  // Enumeration of the types of view points:
292  {
296  GUI_IMAGE
297  };
298 
299  // type dependent view parameter accessor
301  {
302  if( view_type == GUI_MAIN )
303  return myView;
304  if( view_type == GUI_LEFT )
305  return myLeftView;
306  if( view_type == GUI_RIGHT )
307  return myRightView;
308  if( view_type == GUI_IMAGE )
309  return myImageView;
310  return myView;
311  }
312 
313  // for general synchronization of L/R view points with the main one
315  {
316  myLeftView = myView;
317  myRightView = myView;
318  }
319 
320  // type dependent versions
322  RE_RenderContext r, int x, int y, int w, int h)
323  { getViewParameter(vt).setViewport(r, x, y, w, h); }
326  { getViewParameter(vt).setProjection(r); }
327 
328  // The UT_Plane will be transformed with the inverted ViewState transform
329  // matrix
330  void alignPlaneWithView(UT_Plane *plane);
331 
332  const char *className() const;
333 
335 
336  // Method to override the default preference file name. In order to for
337  // the defaults to be loaded from this file, this must be called before
338  // the first instance of this class is created.
339  static void overridePrefFile(const char *filename);
340 
341  void saveAsDefault();
342  void resetToDefaults();
343 
344  // setting the image that overrides the regular rendering
345  void setSnapshotImage(TIL_Raster *texture);
346  TIL_Raster *getSnapshotImage() const;
347 
348  // setting the frame information of the snapshot image
349  void setSnapshotImageFrame( int frame );
350  int getSnapshotImageFrame() const;
351 
352  // the snapshot blending coefficient (alpha)
353  void setSnapshotFactor( float alpha);
354  float getSnapshotFactor() const;
355 
356  void setSnapshotBlendMode(GUI_SnapshotBlendMode mode);
357  GUI_SnapshotBlendMode getSnapshotBlendMode() const;
358 
359  // snapshot image flags
360  void setHideSnapshotAtSourceFrame( bool flag );
361  bool getHideSnapshotAtSourceFrame() const;
362 
363  void setTumbling(bool tumble) { myTumbleFlag = tumble; }
364  bool isTumbling() const { return myTumbleFlag; }
365 
366  bool isLopsView() const { return myIsLops; }
367 
368  // Returns the near and far clipping planes that have saved in the pref file
369  static void getDefaultNearFarLimits(fpreal &near_limit, fpreal &far_limit);
370 
371  // Automatic near/far clip adapt is disabled when looking through a camera.
372  void allowNearFarClipAdapt(bool allow)
373  {
374  myView.allowNearFarClipAdapt(allow);
375  myLeftView.allowNearFarClipAdapt(false); //allow);
376  myRightView.allowNearFarClipAdapt(false); //allow);
377  // No Image view
378  }
379  void setSceneBounds(const UT_BoundingBoxD &bbox)
380  {
381  myView.setSceneBounds(bbox);
382  myLeftView.setSceneBounds(bbox);
383  myRightView.setSceneBounds(bbox);
384  }
385 
387  {
388  myView.setSelectedObjectBounds(bbox);
389  myLeftView.setSelectedObjectBounds(bbox);
390  myRightView.setSelectedObjectBounds(bbox);
391  }
393  {
394  return myView.getSceneBounds();
395  }
396 
397  // Methods to manipulate the external callback class for saving/loading
398  // defaults.
400  { return externalDefaultValues[for_lops?1:0]; }
402  bool for_lops)
403  { externalDefaultValues[for_lops?1:0] = cb; }
404 
405  static void ensureDefaultsLoaded(bool is_lops);
406 
407 private:
408  // 0 = reg, 1 = lops
409  static GUI_ViewState *defaultValues[2];
410  static GUI_ExternalDefaultCB *externalDefaultValues[2];
411  static UT_StringArray *defaultEnabledUserOptions[2];
412 
413  // Display options for the viewport
414  GUI_DisplayOption myOption;
415 
416  // Defines the point of view for simple cameras (non-stereoscopic).
417  GUI_ViewParameter myView;
418 
419  // For stereoscopic cameras we have two view points
420  GUI_ViewParameter myLeftView;
421  GUI_ViewParameter myRightView;
422 
423  // For the image view in LOPs, this is the camera view (myView is the 2D
424  // view)
425  GUI_ViewParameter myImageView;
426 
427  // data about the snapshot image that is displayed instead of showing
428  // the rendered scene (or is blended with the scene framebuffer)
429  GUI_SnapshotImage *mySnapshotImage;
430  bool myTumbleFlag;
431  bool myIsLops;
432 };
433 
434 #endif
const GUI_DisplayOption & getDisplayOptionRef() const
Definition: GUI_ViewState.h:53
GUI_ViewParameter & getViewParameterRef()
Definition: GUI_ViewState.h:58
virtual ~GUI_ExternalDefaultCB()
Definition: GUI_ViewState.h:34
GT_API const UT_StringHolder filename
void dotumble(fpreal dx, fpreal dy, int changed)
const UT_Matrix4D & getRotateMatrix() const
Definition: GUI_ViewState.h:95
void setDefaultFOV(fpreal value)
void screenScroll(fpreal dx, fpreal dy)
const UT_Matrix4D & getProjectionMatrix() const
Definition: GUI_ViewState.h:93
GA_API const UT_StringHolder rot
void scroll(fpreal dx, fpreal dy, const UT_InclusiveRect &viewport)
void allowNearFarClipAdapt(bool allow)
void syncViewsWithMain()
void setSceneBounds(const UT_BoundingBoxD &bbox)
GLint y
Definition: glcorearb.h:103
void setPrimitiveMask(GA_PrimCompat::TypeMask m)
Temporary container for either a RV_Render and an RE_Render.
void dolly(fpreal dx, bool precise_zoom=false, bool smooth_dolly=false)
void directedDolly(const UT_Vector3R &unit_worldspace_dir, fpreal dx, bool precise_zoom=false, bool smooth_dolly=false)
GUI_DisplayOption & getDisplayOptionRef()
Definition: GUI_ViewState.h:57
const UT_Matrix4D & getTransformMatrix()
Definition: GUI_ViewState.h:91
int getApplyAspectFlag() const
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
void setSelectedObjectBounds(const UT_BoundingBoxD &bbox)
void setProjection(GUI_ViewState::GUI_ViewType vt, RE_RenderContext r)
#define GUI_API
Definition: GUI_API.h:10
void setRotateMatrix(const UT_Matrix3R &mat)
Definition: GUI_ViewState.h:97
bool isLopsView() const
void scroll(fpreal dx, fpreal dy)
int getViewWidth() const
Definition: GUI_ViewState.h:86
bool isTumbling() const
void setViewport(GUI_ViewState::GUI_ViewType vt, RE_RenderContext r, int x, int y, int w, int h)
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
void rotate(const UT_Vector3R &axis, fpreal dx)
void worldLockedScroll(const UT_Vector3R &locked_pos, fpreal dx, fpreal dy)
UT_DimRect getViewport() const
Definition: GUI_ViewState.h:82
int initialized() const
const GUI_ViewParameter & getViewParameterRef() const
Definition: GUI_ViewState.h:55
void offsetZoom(fpreal sx, fpreal sy, fpreal dx, GUI_ViewParameter::GUI_ZoomItem item, const UT_InclusiveRect &viewport, bool precise_zoom=false)
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
UT_DimRect getView() const
Definition: GUI_ViewState.h:85
int getOrthoFlag() const
void getView(int &l, int &r, int &b, int &t) const
Definition: GUI_ViewState.h:83
void zoom(fpreal dx, GUI_ViewParameter::GUI_ZoomItem item, const UT_InclusiveRect &viewport, bool precise_zoom=false)
GLdouble t
Definition: glad.h:2397
GLenum mode
Definition: glcorearb.h:99
fpreal getAspectRatio() const
void setOrthoFlag(int onoff)
GUI_ViewParameter & getViewParameter(GUI_ViewState::GUI_ViewType view_type)
void zoom(fpreal dx, GUI_ViewParameter::GUI_ZoomItem item, bool precise_zoom=false)
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
void setTumbling(bool tumble)
void rotate(const UT_Quaternion &quat)
fpreal getDefaultFOV() const
int getViewHeight() const
Definition: GUI_ViewState.h:87
fpreal64 fpreal
Definition: SYS_Types.h:277
LeafData & operator=(const LeafData &)=delete
void setLimits(fpreal n, fpreal f)
const UT_Matrix4D & getItransformMatrix()
Definition: GUI_ViewState.h:89
void rotate(UT_Axis3::axis axis, fpreal dx)
static GUI_ExternalDefaultCB * getExternalDefaultCB(bool for_lops)
void trackball(fpreal dx, fpreal dy)
GLuint texture
Definition: glcorearb.h:415
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
void setAspectRatio(fpreal value)
Definition: core.h:1131
GLboolean r
Definition: glcorearb.h:1222
void homeToBox(int w, int h, UT_BoundingBox &box, const UT_Matrix3R *rot=NULL, bool centred=false, bool zoom_in=false)
Definition: GUI_ViewState.h:67
SIM_API const UT_StringHolder distance
static void setExternalDefaultCB(GUI_ExternalDefaultCB *cb, bool for_lops)
GUI_SnapshotBlendMode
void offsetZoom(fpreal sx, fpreal sy, fpreal dx, GUI_ViewParameter::GUI_ZoomItem item, bool precise_zoom=false)
void boxZoom(fpreal frstx, fpreal frsty, fpreal lastx, fpreal lasty, fpreal distance)
void getViewport(int &l, int &r, int &b, int &t) const
Definition: GUI_ViewState.h:80
GA_PrimCompat::TypeMask getPrimitiveMask() const
void setApplyAspectFlag(int onoff)
void setProjection(RE_RenderContext r)
Definition: GUI_ViewState.h:63
GLenum src
Definition: glcorearb.h:1793
void setViewport(RE_RenderContext r, int x, int y, int w, int h)
Definition: GUI_ViewState.h:61
UT_BoundingBox getSceneBounds() const