HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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_ViewParameter.h"
21 #include <UT/UT_Matrix3.h>
22 #include <UT/UT_Matrix4.h>
23 #include <UT/UT_Plane.h>
24 #include <UT/UT_Quaternion.h>
25 #include <UT/UT_Vector3.h>
26 
27 // Essentially a callback class to allow options from above GUI
28 // to be saved to the default file.
30 {
31 public:
33  virtual bool isDefaultToken(const char *token) = 0;
34  virtual bool parseDefaultOption(const char *token, UT_IStream &is) = 0;
35 
36  virtual bool save(std::ostream &os) = 0;
37 };
38 
39 
40 class UT_StringArray;
41 class TIL_Raster;
42 class GUI_SnapshotImage;
43 
45 {
46 public:
47  GUI_ViewState();
48  ~GUI_ViewState();
49 
50  // member data accessors
52  { return myOption; }
54  { return myView; }
55  GUI_DisplayOption &getDisplayOptionRef() { return myOption; }
56  GUI_ViewParameter &getViewParameterRef() { return myView; }
57 
58  // sets the OpenGL state according to the view parameter
59  void setViewport(RE_Render *r, int x, int y, int w, int h)
60  { myView.setViewport(r, x, y, w, h); }
62  { myView.setProjection(r); }
63 
64  // methods for getting and setting the view point
65  void homeToBox(int w, int h, UT_BoundingBox &box,
66  const UT_Matrix3R *rot = NULL, bool centred = false,
67  bool zoom_in = false)
68  {
69  fpreal minh = getDisplayOptionRef().common()
70  .getMinHomeZoom();
71  myView.homeToBox(w, h, minh, box, rot,
72  centred, zoom_in);
73  myLeftView.homeToBox(w, h, minh, box, rot,
74  centred, zoom_in);
75  myRightView.homeToBox(w, h, minh, box, rot,
76  centred, zoom_in);
77  }
78  void getViewport(int &l, int &r, int &b, int &t) const
79  { myView.getViewport(l, r, b, t); }
80  UT_DimRect getViewport() const { return myView.getViewport(); }
81  void getView(int &l, int &r, int &b, int &t) const
82  { myView.getView(l, r, b, t); }
83  int getViewWidth() const { return myView.getViewWidth(); }
84  int getViewHeight() const { return myView.getViewHeight(); }
85 
87  { return myView.getItransformMatrix();}
89  { return myView.getTransformMatrix(); }
91  { return myView.getProjectionMatrix();}
93  { return myView.getRotateMatrix(); }
94  void setRotateMatrix(const UT_Matrix3R &mat)
95  { myView.setRotateMatrix(mat); }
96 
97  int initialized() const { return myView.initialized(); }
98 
99  void setOrthoFlag(int onoff)
100  {
101  myView.setOrthoFlag(onoff);
102  myLeftView.setOrthoFlag(onoff);
103  myRightView.setOrthoFlag(onoff);
104  }
105  int getOrthoFlag() const { return myView.getOrthoFlag(); }
106 
107  void setApplyAspectFlag(int onoff)
108  { myView.setApplyAspectFlag(onoff); }
109  int getApplyAspectFlag() const
110  {return myView.getApplyAspectFlag(); }
112  { myView.setAspectRatio(value); }
114  {return myView.getAspectRatio(); }
116  { myView.setLimits(n, f); }
117 
118  void rotate(UT_Axis3::axis axis, fpreal dx)
119  {
120  myView.rotate(axis, dx);
121  myLeftView.rotate(axis, dx);
122  myRightView.rotate(axis, dx);
123  }
124  void rotate(const UT_Vector3R &axis, fpreal dx)
125  {
126  myView.rotate(axis, dx);
127  myLeftView.rotate(axis, dx);
128  myRightView.rotate(axis, dx);
129  }
130  void rotate(const UT_Quaternion &quat)
131  {
132  myView.rotate(quat);
133  myLeftView.rotate(quat);
134  myRightView.rotate(quat);
135  }
136  void trackball(fpreal dx, fpreal dy)
137  {
138  myView.trackball(dx, dy);
139  myLeftView.trackball(dx, dy);
140  myRightView.trackball(dx, dy);
141  }
142  void dotumble(fpreal dx, fpreal dy, int changed)
143  {
144  myView.dotumble(dx, dy, changed);
145  myLeftView.dotumble(dx, dy, changed);
146  myRightView.dotumble(dx, dy, changed);
147  }
148  void scroll(fpreal dx, fpreal dy)
149  {
150  myView.scroll(dx, dy);
151  myLeftView.scroll(dx, dy);
152  myRightView.scroll(dx, dy);
153  }
154  void scroll(fpreal dx, fpreal dy,
155  const UT_InclusiveRect &viewport)
156  {
157  myView.scroll(dx, dy, viewport);
158  myLeftView.scroll(dx, dy, viewport);
159  myRightView.scroll(dx, dy, viewport);
160  }
161  void dolly(fpreal dx,
162  bool precise_zoom = false,
163  bool smooth_dolly = false)
164  {
165  myView.dolly(dx, precise_zoom,
166  smooth_dolly);
167  myLeftView.dolly(dx, precise_zoom,
168  smooth_dolly);
169  myRightView.dolly(dx, precise_zoom,
170  smooth_dolly);
171  }
172  void directedDolly(const UT_Vector3R &unit_worldspace_dir,
173  fpreal dx,
174  bool precise_zoom = false,
175  bool smooth_dolly = false)
176  {
177  myView.directedDolly(
178  unit_worldspace_dir, dx,
179  precise_zoom,
180  smooth_dolly);
181  myLeftView.directedDolly(
182  unit_worldspace_dir, dx,
183  precise_zoom,
184  smooth_dolly);
185  myRightView.directedDolly(
186  unit_worldspace_dir, dx,
187  precise_zoom,
188  smooth_dolly);
189  }
191  bool precise_zoom = false)
192  {
193  myView.zoom(dx, item, precise_zoom);
194  myLeftView.zoom(dx, item, precise_zoom);
195  myRightView.zoom(dx, item,precise_zoom);
196  }
198  const UT_InclusiveRect &viewport,
199  bool precise_zoom = false)
200  {
201  myView.zoom(dx, item, viewport,
202  precise_zoom);
203  myLeftView.zoom(dx, item, viewport,
204  precise_zoom);
205  myRightView.zoom(dx, item, viewport,
206  precise_zoom);
207  }
208  void offsetZoom(fpreal sx, fpreal sy, fpreal dx,
210  bool precise_zoom = false)
211  {
212  myView.offsetZoom(sx, sy, dx, item,
213  precise_zoom);
214  myLeftView.offsetZoom(sx, sy, dx, item,
215  precise_zoom);
216  myRightView.offsetZoom(sx, sy, dx, item,
217  precise_zoom);
218  }
219  void offsetZoom(fpreal sx, fpreal sy, fpreal dx,
221  const UT_InclusiveRect &viewport,
222  bool precise_zoom = false)
223  {
224  myView.offsetZoom(sx, sy, dx, item,
225  viewport,
226  precise_zoom);
227  myLeftView.offsetZoom(sx, sy, dx, item,
228  viewport,
229  precise_zoom);
230  myRightView.offsetZoom(sx, sy, dx, item,
231  viewport,
232  precise_zoom);
233  }
234  void boxZoom(fpreal frstx, fpreal frsty, fpreal lastx,
235  fpreal lasty, fpreal distance)
236  { myView.boxZoom(frstx,frsty,lastx,lasty, distance); }
237 
239  { myOption.common().primMask(m); }
241  { return myOption.common().primMask(); }
242 
243  // Enumeration of the types of view points:
245  {
248  GUI_RIGHT
249  };
250 
251  // type dependent view parameter accessor
253  {
254  if( view_type == GUI_MAIN )
255  return myView;
256  if( view_type == GUI_LEFT )
257  return myLeftView;
258  if( view_type == GUI_RIGHT )
259  return myRightView;
260  return myView;
261  }
262 
263  // for general synchronization of L/R view points with the main one
265  {
266  myLeftView = myView;
267  myRightView = myView;
268  }
269 
270  // type dependent versions
272  RE_Render *r, int x, int y, int w, int h)
273  { getViewParameter(vt).setViewport(r, x, y, w, h); }
275  { getViewParameter(vt).setProjection(r); }
276 
277  // The UT_Plane will be transformed with the inverted ViewState transform
278  // matrix
279  void alignPlaneWithView(UT_Plane *plane);
280 
281  const char *className() const;
282 
283  GUI_ViewState &operator=(const GUI_ViewState &src);
284 
285  // Method to override the default preference file name. In order to for
286  // the defaults to be loaded from this file, this must be called before
287  // the first instance of this class is created.
288  static void overridePrefFile(const char *filename);
289 
290  void saveAsDefault();
291  void resetToDefaults();
292 
293  // setting the image that overrides the regular rendering
294  void setSnapshotImage(TIL_Raster *texture);
295  TIL_Raster *getSnapshotImage() const;
296 
297  // setting the frame information of the snapshot image
298  void setSnapshotImageFrame( int frame );
299  int getSnapshotImageFrame() const;
300 
301  // the snapshot blending coefficient (alpha)
302  void setSnapshotAlpha( float alpha);
303  float getSnapshotAlpha() const;
304 
305  // snapshot image flags
306  void setHideSnapshotAtSourceFrame( bool flag );
307  bool getHideSnapshotAtSourceFrame() const;
308 
309  void setTumbling(bool tumble) { myTumbleFlag = tumble; }
310  bool isTumbling() const { return myTumbleFlag; }
311 
312 
313  // Returns the near and far clipping planes that have saved in the pref file
314  static void getDefaultNearFarLimits(fpreal &near_limit, fpreal &far_limit);
315 
316  // Methods to manipulate the external callback class for saving/loading
317  // defaults.
319  { return externalDefaultValues; }
321  { externalDefaultValues = cb; }
322 
323  static void ensureDefaultsLoaded();
324 
325 private:
326  static GUI_ViewState *defaultValues;
327  static GUI_ExternalDefaultCB *externalDefaultValues;
328  static UT_StringArray *defaultEnabledUserOptions;
329 
330  // Display options for the viewport
331  GUI_DisplayOption myOption;
332 
333  // Defines the point of view for simple cameras (non-stereoscopic).
334  GUI_ViewParameter myView;
335 
336  // For stereoscopic cameras we have two view points
337  GUI_ViewParameter myLeftView;
338  GUI_ViewParameter myRightView;
339 
340  // data about the snapshot image that is displayed instead of showing
341  // the rendered scene (or is blended with the scene framebuffer)
342  GUI_SnapshotImage *mySnapshotImage;
343  bool myTumbleFlag;
344 };
345 
346 #endif
const GUI_DisplayOption & getDisplayOptionRef() const
Definition: GUI_ViewState.h:51
GUI_ViewParameter & getViewParameterRef()
Definition: GUI_ViewState.h:56
virtual ~GUI_ExternalDefaultCB()
Definition: GUI_ViewState.h:32
void dotumble(fpreal dx, fpreal dy, int changed)
const UT_Matrix4D & getRotateMatrix() const
Definition: GUI_ViewState.h:92
void setProjection(GUI_ViewState::GUI_ViewType vt, RE_Render *r)
const UT_Matrix4D & getProjectionMatrix() const
Definition: GUI_ViewState.h:90
GA_API const UT_StringHolder rot
void scroll(fpreal dx, fpreal dy, const UT_InclusiveRect &viewport)
void syncViewsWithMain()
GLint y
Definition: glcorearb.h:102
void setPrimitiveMask(GA_PrimCompat::TypeMask m)
void dolly(fpreal dx, bool precise_zoom=false, bool smooth_dolly=false)
GA_PrimCompat::TypeMask getPrimitiveMask(void) const
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:55
static GUI_ExternalDefaultCB * getExternalDefaultCB()
const UT_Matrix4D & getTransformMatrix()
Definition: GUI_ViewState.h:88
int getApplyAspectFlag() const
GLdouble n
Definition: glcorearb.h:2007
GLfloat f
Definition: glcorearb.h:1925
void setProjection(RE_Render *r)
Definition: GUI_ViewState.h:61
void setViewport(GUI_ViewState::GUI_ViewType vt, RE_Render *r, int x, int y, int w, int h)
T distance(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Definition: UT_Vector4.h:634
#define GUI_API
Definition: GUI_API.h:10
void setRotateMatrix(const UT_Matrix3R &mat)
Definition: GUI_ViewState.h:94
void setViewport(RE_Render *r, int x, int y, int w, int h)
Definition: GUI_ViewState.h:59
void scroll(fpreal dx, fpreal dy)
int getViewWidth() const
Definition: GUI_ViewState.h:83
bool isTumbling() const
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:111
void rotate(const UT_Vector3R &axis, fpreal dx)
UT_DimRect getViewport() const
Definition: GUI_ViewState.h:80
int initialized() const
Definition: GUI_ViewState.h:97
const GUI_ViewParameter & getViewParameterRef() const
Definition: GUI_ViewState.h:53
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:1221
int getOrthoFlag() const
void getView(int &l, int &r, int &b, int &t) const
Definition: GUI_ViewState.h:81
void zoom(fpreal dx, GUI_ViewParameter::GUI_ZoomItem item, const UT_InclusiveRect &viewport, bool precise_zoom=false)
fpreal getAspectRatio() const
void setOrthoFlag(int onoff)
Definition: GUI_ViewState.h:99
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:2001
GLsizei const GLfloat * value
Definition: glcorearb.h:823
double fpreal
Definition: SYS_Types.h:269
void setTumbling(bool tumble)
void rotate(const UT_Quaternion &quat)
int getViewHeight() const
Definition: GUI_ViewState.h:84
void setLimits(fpreal n, fpreal f)
const UT_Matrix4D & getItransformMatrix()
Definition: GUI_ViewState.h:86
static void setExternalDefaultCB(GUI_ExternalDefaultCB *cb)
GLint GLenum GLint x
Definition: glcorearb.h:408
void rotate(UT_Axis3::axis axis, fpreal dx)
void trackball(fpreal dx, fpreal dy)
GLuint texture
Definition: glcorearb.h:414
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
void setAspectRatio(fpreal value)
GLboolean r
Definition: glcorearb.h:1221
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:65
png_infop png_uint_32 flag
Definition: png.h:2242
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:78
void setApplyAspectFlag(int onoff)
GLenum src
Definition: glcorearb.h:1792