HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUI_ViewParameter.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_ViewParameter (Geometry Render Library, C++)
7  *
8  * COMMENTS:
9  * ViewParameter contains information relating to the
10  * viewport's physical characteristics, eg aspect ratio,
11  * position, lookat.
12  *
13  */
14 
15 #ifndef __GUI_ViewParameter__
16 #define __GUI_ViewParameter__
17 
18 #include "GUI_API.h"
19 #include <UT/UT_BoundingBox.h>
20 #include <UT/UT_Matrix3.h>
21 #include <UT/UT_Matrix4.h>
22 #include <UT/UT_Quaternion.h>
23 #include <UT/UT_Rect.h>
24 #include <UT/UT_Vector3.h>
25 #include <UT/UT_VectorTypes.h>
26 #include <UT/UT_Plane.h>
27 
28 #include <RE/RE_RenderContext.h>
29 
31 typedef void (*GUI_HomeRotCallback)(UT_Matrix3R &, void *);
32 
34 {
35 public:
37  {
38  ortho = 0;
39  applyAspect = 0;
40  matrixDirty = 1;
41  iMatrixDirty = 1;
42  boxZoom = 0;
43  viewportDirty = 0;
44  rotoTrackWindow = 1;
45  initXform = 0;
46  rxyzDirty = 1;
47  }
48 
49  // ASCII methods to save and load flags
50  void save(std::ostream &os) const;
51  bool load(UT_IStream &is);
52 
53  unsigned ortho:1,
54  applyAspect:1,
55  matrixDirty:1,
56  iMatrixDirty:1,
57  boxZoom:1,
58  viewportDirty:1,
59  rotoTrackWindow:1,
60  initXform:1,
61  rxyzDirty:1;
62 };
63 
65 {
66 public:
69 
70  GUI_ViewParameter(const GUI_ViewParameter &) = delete;
71  enum axis { OBLIQUE, CUSTOM, XAXIS, YAXIS, ZAXIS,
72  FRONT, RIGHT, TOP, BACK, LEFT, BOTTOM, CPLANE };
73 
74  enum orientation { Y_UP, Z_UP };
75 
77  {
78  int w,h;
79  getViewportSize(w,h);
80  area.set(myViewportLeft, myViewportBottom, w,h);
81  }
82  void getViewport(int &l, int &r, int &b, int &t) const;
83  void getViewportSize(int &w, int &h) const
84  {
85  // Note that we have inclusive coordinates.
86  w = myViewportRight - myViewportLeft + 1;
87  h = myViewportTop - myViewportBottom + 1;
88  }
89  int getViewportWidth() const
90  { return myViewportRight - myViewportLeft + 1; }
91  int getViewportHeight() const
92  { return myViewportTop - myViewportBottom + 1; }
93  void setViewport(RE_RenderContext r, int x, int y, int w, int h);
94  void setViewport(RE_RenderContext r, const UT_DimRect &viewarea)
95  { setViewport(r, viewarea.x(), viewarea.y(),
96  viewarea.w(), viewarea.h()); }
97 
98  // Utility for converting our viewport into a UT_Rect.
100  { return UT_InclusiveRect(myViewportLeft, myViewportBottom,
101  myViewportRight, myViewportTop); }
102 
103 
104  // Both setViewport and setView must be called before setProjection.
105  // r may be NULL to set the projection matrix without loading it into
106  // RE_Render.
107  void setProjection(RE_RenderContext r);
108 
109  // Returns the projection matrix. If depth_adjust is false, Z is not
110  // mapped to [0,1], and instead remains as-is.
111  void getProjection(UT_Matrix4D &proj, bool depth_adjust=true);
112 
113  // Returns a projection matrix with near at 1.0 and far at 0.0 mapped to
114  // [0,1]. If `infinite_far_plane` is true, assume an infinitely far clip and
115  // ignore the far plane defined in this object.
116  void getReverseDepthProjection(UT_Matrix4D &proj,
117  bool infinite_far_plane);
118 
119  void getUnclippedProjection(UT_Matrix4D &project,
120  fpreal left_crop = 0.0,
121  fpreal right_crop = 1.0,
122  fpreal bottom_crop = 0.0,
123  fpreal top_crop = 1.0);
124 
125  // temporarily use this projection matrix. This class does not take
126  // ownership.
127  void setProjectionOverride(UT_Matrix4D *override);
128 
129  // Get the direction a particular point (px, py) in the camera's
130  // near plane is pointing to in world coordinates. The range of
131  // (px, py) is (0, 0) to (1, 1) with (0, 0) representing the
132  // lower-left corner and the default arguments represent the center of
133  // the screen.
134  UT_Vector3 getCameraDir(fpreal px = 0.5, fpreal py = 0.5);
135 
136  // A utility method to return the world space plane representing our
137  // view plane. The point will be set to the center of the view and
138  // the normal will point towards the camera.
139  UT_PlaneD getViewPlane();
140 
141  // The view is a subregion of the viewport that represents the current
142  // "camera" view. Aspect ratio bars are used to dim the parts of the
143  // viewport not in this view. The window coordinates are relative to
144  // this view, not the viewport.
145  void setView(const UT_DimRect &area)
146  { setView(area.x(), area.y(), area.w(), area.h()); }
147  void setView(int x, int y, int w, int h);
148  void getView(int &l, int &r, int &b, int &t) const;
149  int getViewWidth() const
150  { return myViewRight - myViewLeft + 1; }
151  int getViewHeight() const
152  { return myViewTop - myViewBottom + 1; }
153  // Utility for converting our viewport into a UT_Rect.
155  { return UT_InclusiveRect(myViewLeft, myViewBottom,
156  myViewRight, myViewTop); }
157 
158  // A handy method to compute projection bounds for the viewport such
159  // that the specified bounds map to the view subregion.
160  void viewToViewportProjectionBounds(
161  fpreal &left, fpreal &right,
162  fpreal &bottom, fpreal &top) const;
163 
164  // Convenience methods to query the margins on each side of the view
165  // subregion.
166  int getLeftMargin() const
167  { return myViewLeft - myViewportLeft; }
168  int getRightMargin() const
169  { return myViewportRight - myViewRight; }
170  int getBottomMargin() const
171  { return myViewBottom - myViewportBottom; }
172  int getTopMargin() const
173  { return myViewportTop - myViewTop; }
174 
175  void homeToBox(int width, int height, fpreal minzoom,
176  UT_BoundingBox &box, const UT_Matrix3R *rot = NULL,
177  bool centre_to_origin = false, bool zoom_in = false);
178  void homeRotation(axis a, UT_Matrix3R &rot) const;
179  void homeRotation(axis a);
180 
181  void resetFOV();
182 
183  // Set the default camera FOV, 0-180 degrees.
184  void setDefaultFOV(fpreal fov_in_degrees);
185  fpreal getDefaultFOV() const { return myView.myDefaultFOV; }
186 
187  // Query the rotation that converts the view rotation from the old mode
188  // to the new mode.
189  static void getOrientationChangeRotation(
192  UT_Matrix3R &rot);
193 
194  // Convert a view transform relative to the old_mode to the corresponding
195  // view transform relative to the new mode.
196  void convertTransform(GUI_ViewParameter::axis home_axis,
199 
200  // To perform view operations that are being exported continuously, we
201  // need to cache some data to account for view changes that occur as a
202  // result of the exporting. Generally, you'll want to call the begin
203  // method on a UI_VALUE_START and the end method on a UI_VALUE_CHANGED.
204  void beginContinuouslyExportedOperation();
205  void endContinuouslyExportedOperation();
206  bool continuouslyExportedOperationInProgress() const;
207 
208  void rotate(UT_Axis3::axis axis, fpreal dx);
209  void rotate(const UT_Vector3R &axis, fpreal dx);
210  void rotate(const UT_Quaternion &quat);
211  void trackball(fpreal dx, fpreal dy);
212  void incrementtrackball(fpreal dx, fpreal dy, int finish);
213  void eulertumble(fpreal dx, fpreal dy, int finish, bool lock);
214  void dotumble(fpreal dx, fpreal dy, int finish);
215 
216  void scroll(fpreal dx, fpreal dy);
217  // Scroll using the specified viewport size instead of our settings. Used
218  // for scrolling linked ortho viewports.
219  void scroll(fpreal dx, fpreal dy, const UT_InclusiveRect &viewport);
220  // Scroll to maintain the specified world position under the cursor. This
221  // method is unnecessary when using an orthographic projection.
222  void worldLockedScroll(const UT_Vector3R &locked_pos,
223  fpreal dx, fpreal dy);
224 
225  void dolly(fpreal dx,
226  bool precise_zoom = false,
227  bool smooth_deltas = false);
228 
229  // Dolly using a specified world-space direction (instead of towards the
230  // center of the view as in a regular dolly). The use of world space is
231  // a convenience for the GUI_ViewState wrapper that would otherwise have
232  // to transform this to a view space direction for each instance of this
233  // class.
234  void directedDolly(const UT_Vector3R &unit_worldspace_dir,
235  fpreal dx, bool precise_zoom = false,
236  bool smooth_deltas = false);
237 
239  {
241  GUI_ORTHO_WIDTH
242  };
243  void zoom(fpreal dx, GUI_ZoomItem item, bool precise_zoom = false);
244  // Zoom using the specified viewport size instead of our settings. Used
245  // for zooming linked ortho viewports.
246  void zoom(fpreal dx, GUI_ZoomItem item,
247  const UT_InclusiveRect &viewport,
248  bool precise_zoom = false);
249 
250  // Versions of the zoom() methods that center the zoom around the given
251  // (normalized) screen position (sx, sy). This affects either the window
252  // offset, when GUI_WIN_SIZE is specified, or the view position, when
253  // GUI_ORTHO_WIDTH is specified.
254  void offsetZoom(fpreal sx, fpreal sy, fpreal dx, GUI_ZoomItem item,
255  bool precise_zoom = false);
256  void offsetZoom(fpreal sx, fpreal sy, fpreal dx, GUI_ZoomItem item,
257  const UT_InclusiveRect &viewport,
258  bool precise_zoom = false);
259 
260  // Dolly onto a target located at a specified distance.
261  // Note that the location and size of the "box" must be
262  // normalized to [0, 1]
263  // ** Note : Aspect ratio of the box is assumed to match aspect ratio
264  // of the viewport!
265  void boxZoom(fpreal firstx, fpreal firsty, fpreal lastx,
266  fpreal lasty, fpreal distance);
267 
268  void screenScroll(fpreal dx, fpreal dy);
269 
270  // Returns the width of the frustum cross-section at the distance t.
271  static fpreal getFrustumWidth(fpreal t, fpreal aperture, fpreal focal_length,
272  fpreal orthowidth, bool is_ortho);
273 
274  // Returns the centre of the frustum (cx, cy) and the half-width and
275  // half-height (hw, hh), from these, you can compute the corners of the
276  // frustum.
277  static void getFrustumCenter(fpreal frustum_width, fpreal aspect,
278  fpreal x_offset, fpreal y_offset,
279  fpreal x_window_size, fpreal y_window_size,
280  fpreal &cx, fpreal &cy,
281  fpreal &hw, fpreal &hh);
282 
283 // member data access methods
284 
285  bool isDirty() const { return (myFlag.viewportDirty ||
286  myFlag.matrixDirty ||
287  myFlag.iMatrixDirty); }
288  // bumped whenever the view has changed.
289  int getViewVersion() const { return myVersion + myVersion2D; }
290  void bumpViewVersion() { myVersion++; }
291  void bumpView2DVersion() { myVersion2D++; }
292  int getView3DVersion() const { return myVersion; }
293  int getView2DVersion() const { return myVersion2D; }
294 
295  // projection
296  int initialized() const { return myFlag.initXform; }
297  int getOrthoFlag() const { return myFlag.ortho; }
298  void setOrthoFlag(int o) { myFlag.ortho = o; }
299 
300  void setInfiniteFarPlane(bool enable) { myInfiniteFarPlane = enable;}
301  bool getInfiniteFarPlane() const { return myInfiniteFarPlane; }
302  void setLimits(fpreal n, fpreal f) { setNearClip(n); setFarClip(f); }
304  {
305  *n = myView.myNearLimit;
306  *f = myView.myFarLimit;
307  }
308  void setNearClip(fpreal near);
309  void setFarClip(fpreal far);
310  fpreal getNearClip() const { return myView.myNearLimit; }
311  fpreal getFarClip() const { return myView.myFarLimit; }
312 
313  void setMaxNearClip(bool limit, fpreal near_max);
314  bool hasMaxNearClip() const { return myLimitNearClip; }
315  fpreal getMaxNearClip() const { return myMaxNearClip; }
316 
318  { mySceneBounds=b; }
319  const UT_BoundingBoxD &getSceneBounds() const { return mySceneBounds; }
321  { mySelectedObjBounds=b; }
322 
323  // In case far/near > 10M, and extended zbuffer range is supported
324  // Far clip will be at this value rather than 1.0.
325  fpreal32 getExtendedZBufferFar() const { return myExtendedZBufferFar; }
326 
327  static void setExtendedZBufferRangeSupport(bool has_ext);
328 
329  void allowNearFarClipAdapt(bool allow)
330  { myAllowNearFarClipAdapt = allow; }
331 
332  // True if the viewer isn't tied to a camera.
333  void setIsFreeCam(bool free_cam) { myIsFreeCam = free_cam; }
334  bool isFreeCam() const { return myIsFreeCam; }
335 
337  {
338  myView.myWinX = x;
339  myView.myWinY = y;
340  myView.myWinW = SYSmax(w, fpreal(0.001));
341  myView.myWinH = SYSmax(h, fpreal(0.001));
342  updateWindowOverridesNominal();
343  }
345  fpreal &w, fpreal &h) const
346  {
347  x = myView.myWinX;
348  y = myView.myWinY;
349  w = myView.myWinW;
350  h = myView.myWinH;
351  }
352 
354  {
355  myNominalWinX = x;
356  myNominalWinY = y;
357  myNominalWinW = SYSmax(w, fpreal(0.001));
358  myNominalWinH = SYSmax(h, fpreal(0.001));
359  updateWindowOverridesNominal();
360  }
362  fpreal &w, fpreal &h) const
363  {
364  x = myNominalWinX;
365  y = myNominalWinY;
366  w = myNominalWinW;
367  h = myNominalWinH;
368  }
370  { return myWindowOverridesNominal; }
371 
372  // A handy method to compute the view region bounds relative to the nominal
373  // window rather than relative to the current window. With bounds relative
374  // to the nominal window, the nominal window is the unit square from (0,0)
375  // to (1,1), in contrast with bounds relative to the current window, which
376  // are themselves always this unit square.
377  void getViewBoundsRelativeToNominalWindow(
378  fpreal &l, fpreal &r, fpreal &b, fpreal &t) const;
379 
380  // The window is stored as an offset from 0, 0 with the scale applied prior
381  // to translation. However, mantra and other renderers expect the window
382  // to be relative to the (0,1) rectangle. getScreenWindow() will translate
383  // the window parameters into a screen window. setScreenWindow() will take
384  // a screen window and set the appropriate parameters.
386  fpreal &b, fpreal &t) const
387  {
388  convertViewToScreenWindow(myView.myWinX, myView.myWinY,
389  myView.myWinW, myView.myWinH,
390  l, r, b, t);
391  }
393  {
394  convertScreenToViewWindow(l, r, b, t,
395  myView.myWinX, myView.myWinY,
396  myView.myWinW, myView.myWinH);
397  }
398 
400  {
401  myHasSubRegion = true;
402  mySubRegionX = x;
403  mySubRegionY = y;
404  mySubRegionW = w;
405  mySubRegionH = h;
406  }
408  {
409  myHasSubRegion = false;
410  mySubRegionX = 0.0;
411  mySubRegionY = 0.0;
412  mySubRegionW = 1.0;
413  mySubRegionH = 1.0;
414  }
416  {
417  x = mySubRegionX;
418  y = mySubRegionY;
419  w = mySubRegionW;
420  h = mySubRegionH;
421  return myHasSubRegion;
422  }
423  bool hasSubRegion() const { return myHasSubRegion; }
424 
425  static void convertScreenToViewWindow(
426  fpreal l, fpreal r, fpreal b, fpreal t,
427  fpreal &xoff, fpreal &yoff, fpreal &xsize, fpreal &ysz);
428  static void convertViewToScreenWindow(
429  fpreal xoff, fpreal yoff, fpreal xsize, fpreal ysize,
430  fpreal &l, fpreal &r, fpreal &b, fpreal &t);
431 
432  fpreal getWinSizeX() const { return myView.myWinW; }
433  fpreal getWinSizeY() const { return myView.myWinH; }
434  fpreal getWinX() const { return myView.myWinX; }
435  fpreal getWinY() const { return myView.myWinY; }
436 
438  {
439  GUI_VIEW_ADJUST_NONE = 0,
440  GUI_VIEW_ADJUST_FAR = 1,
441  GUI_VIEW_ADJUST_NEAR = 2,
442  GUI_VIEW_ADJUST_BOTH = 3
443  };
445  { myAdjustLimits = which; }
446  GUI_ViewAdjustLimits getAdjustLimits() const { return myAdjustLimits; }
447 
448  void setWindowAffectRotoscope(int v) { myFlag.rotoTrackWindow = v; }
450  { return myFlag.rotoTrackWindow; }
451 
452  // aspectRatio
453  void setApplyAspectFlag(int a) { myFlag.applyAspect = a; }
454  int getApplyAspectFlag() const { return myFlag.applyAspect; }
455  void setAspectRatio(fpreal a) { myViewAspectRatio = a; }
456  fpreal getAspectRatio() const { return myViewAspectRatio; }
457 
459  {
460  myFrustumWidthScale = xsc;
461  myFrustumHeightScale = ysc;
462  }
463 
464  // Return 8 corner points of the frustum, near points first (BL,BR,TL,TR)
465  void getFrustumPoints(UT_Vector3FArray &pnts);
466 
467  // position
469  void setT(const UT_Vector3D &t)
470  { myView.myT = t; myFlag.matrixDirty=1; myFlag.iMatrixDirty=1;}
472  const UT_Vector3D & getT() const { return myView.myT; }
473 
474  // pivot
476  const UT_Vector3D & getP() const { return myView.myP; }
478  void setP(const UT_Vector3D &p)
479  { myView.myP = p; myFlag.matrixDirty=1; myFlag.iMatrixDirty=1;}
480 
481  static void setOrientationMode(orientation o);
482  static orientation getOrientationMode();
483  static bool isOrientationYUp()
484  { return getOrientationMode() == Y_UP; }
485  static bool isOrientationZUp()
486  { return getOrientationMode() == Z_UP; }
487 
488  // Rotation style:
489  static void setTumbleStyleFlag(int style)
490  { myTumbleStyle = style; }
491  static int getTumbleStyleFlag() { return myTumbleStyle; }
492  static void setAltKeyViewControlsFlag(int style)
493  { myAltKeyViewControls = style; }
494  static int getAltKeyViewControlsFlag() { return myAltKeyViewControls; }
495  static void setScrollStyleFlag(int style)
496  { myScrollStyle = style; }
497  static int getScrollStyleFlag() { return myScrollStyle; }
498  static void setDefaultHomingStyleFlag(int style)
499  { myDefaultHomingStyle = GUI_ViewParameter::axis(style); }
500  static axis getDefaultHomingStyleFlag() { return myDefaultHomingStyle; }
501 
502  // the resulting matrices
503  void setRotateMatrix(const UT_Matrix3D &mat)
504  { myView.myRotateMatrix = mat;
505  myFlag.matrixDirty = 1;
506  myFlag.iMatrixDirty = 1;
507  myFlag.rxyzDirty = 1; }
508  const UT_Matrix4D &getRotateMatrix() const { return myView.myRotateMatrix; }
509 
511  { return myProjectionOverride ? *myProjectionOverride
512  : myView.myProjectionMatrix; }
513  const UT_Matrix4D &getTransformMatrix() { updateTransformMatrix();
514  return myTransformMatrix; }
515  const UT_Matrix4D &getItransformMatrix() { updateItransformMatrix();
516  return myItransformMatrix; }
517 
518  // This sets the transform matrix to the given value, bypassing the
519  // PX, TX, etc. The purpose of this is to get accurate camera transforms
520  // you can first set all the PX, Rotate, etc, according to the cracked
521  // values, and then do a forceTransformMatrix to ensure the user sees
522  // the most accurate possible matrix.
523  void forceTransformMatrix(const UT_DMatrix4 &mat);
524  void getTransformMatrix(UT_DMatrix4 &mat, fpreal time);
526  void *data)
527  {
528  myTransformCallback = callback;
529  myTransformCallbackData = data;
530  }
531 
532  // Class I/O methods. They return 0 if successful, -1 if not.
533  // `for_view_copy` is only for temporarily transferring one view parms to
534  // another.
535  int save(std::ostream &os,
536  char separator = '\n',
537  bool for_view_copy = false) const;
538  bool load(UT_IStream &is);
539  bool oldLoad(UT_IStream &is, int version);
540 
541  // inline for non-virtual class
542  const char *className() const { return "GUI_ViewParameter"; }
543 
544  fpreal getLastHomeRadius() const { return myLastHomeRadius; }
545 
546  void setHomeAxis(axis homeaxis)
547  { myHomeAxis = homeaxis; myFlag.rxyzDirty = 1; }
548  axis getHomeAxis() const { return myHomeAxis; }
549  void setCustomHomeRot(UT_Matrix3R &rot) { myCustomHomeRot = rot; }
550  const UT_Matrix3R &getCustomHomeRot() const { return myCustomHomeRot; }
551 
552  // Set a callback to get the home rotation for the construction plane
553  // (axis::CPLANE), to which this class does not have direct access.
555  void *data)
556  {
557  myCPlaneHomeRotCallback = callback;
558  myCPlaneHomeRotCallbackData = data;
559  }
560 
561 
562  void setOrthoWidth(fpreal w) { myView.myOrthoWidth = w; }
563  fpreal getOrthoWidth() const { return myView.myOrthoWidth; }
564 
565  void setFocalLength(fpreal f) { myView.myFocalLength = f; }
566  fpreal getFocalLength() const { return myView.myFocalLength; }
567 
568  void setFocalUnitScale(fpreal f) { myView.myFocalScale = f; }
569  fpreal getFocalUnitScale() const { return myView.myFocalScale; }
570 
571  void setFocusDistance(fpreal f) { myView.myFocusDistance = f; }
572  fpreal getFocusDistance() const { return myView.myFocusDistance; }
573 
574  void setAperture(fpreal a) { myView.myAperture = a; }
575  fpreal getAperture() const { return myView.myAperture; }
576 
577  void setFStop(fpreal fs) { myView.myFStop = fs; }
578  fpreal getFStop() const { return myView.myFStop; }
579 
581  {
582  myView.myHApertureOffset = h;
583  myView.myVApertureOffset = v;
584  }
586  {
587  h = myView.myHApertureOffset;
588  v = myView.myVApertureOffset;
589  }
590 
591  fpreal getNearLimit() const { return myView.myNearLimit; }
592  fpreal getFarLimit() const { return myView.myFarLimit; }
593 
594  fpreal getZBufferNear() const { return myZBufferNear; }
595  fpreal getZBufferFar() const { return myZBufferFar; }
596 
597  // viewport clearing
599 
600  // fog
601  int myFog;
603  float myFogNear;
604  float myFogFar;
605  float myFogColor[3];
606  float myFogAlpha;
607 
608  // used for rotoscoping only
610 
611  // container for all view home information
612  class gui_View
613  {
614  public:
616  : myT(0.0, 0.0, 0.1),
617  myP(0.0, 0.0, 0.0),
618  myRotateMatrix(1.0),
619  myProjectionMatrix(1.0),
620  myWinX(0.0),
621  myWinY(0.0),
622  myWinW(1.0),
623  myWinH(1.0),
624  myOrthoWidth(1.0),
625  myFocalLength(50.0),
626  myFocusDistance(5.0),
627  myAperture(41.4214),
628  myFStop(5.6),
629  myFocalScale(0.001),
630  myNearLimit(0.1),
631  myFarLimit(10000.0),
632  myHApertureOffset(0.0),
633  myVApertureOffset(0.0),
634  myDefaultFOV(45.0)
635  {}
636 
639 
642 
643  // window (zooming)
648 
649  // projection information
650  // ortho specific
652 
653  // perspective specific sSee diagram below)
657  fpreal myFStop; // for dof.
662 
665  };
666 
667  // methods to quickly stash and recall the view state.
668  void getViewState(gui_View &view_state) const
669  { view_state = myView; }
670  void setViewState(const gui_View &view_state)
671  {
672  myView = view_state;
673  myFlag.matrixDirty=1;
674  myFlag.iMatrixDirty=1;
675  myFlag.rxyzDirty=1;
676  updateWindowOverridesNominal();
677  }
678 
679  void adjustNearFarClip();
680 
681  // clipping
682 private:
683  fpreal myZBufferNear;
684  fpreal myZBufferFar;
685  GUI_ViewAdjustLimits myAdjustLimits;
686  bool myInfiniteFarPlane = false;
687  bool myIsFreeCam = true;
688 
689  // aspect ratio
690  fpreal myViewAspectRatio;
691 public:
692  fpreal myPixelAspect; // depends on output device
693 
694 // projection information (see docs below)
705 
707 
708 private:
709  void updateTransformMatrix();
710  void updateItransformMatrix();
711  void updateRXYZValues();
712  fpreal getDistanceToBoxCenter(int clamp = 0) const;
713 
714  void internalScroll(fpreal dx, fpreal dy,
715  const UT_InclusiveRect &viewport,
716  bool decouple_axes,
717  const UT_Vector3R *locked_pos);
718  void internalZoom(fpreal dx, GUI_ZoomItem item, int width);
719  void internalOffsetZoom(fpreal sx, fpreal sy, fpreal dx,
720  GUI_ZoomItem item,
721  const UT_InclusiveRect &viewport);
722  void internalScreenScroll(fpreal dx, fpreal dy,
723  const UT_InclusiveRect &viewport);
724 
725  void getFrustumClip(fpreal &l, fpreal &r, fpreal &t, fpreal &b,
726  fpreal &n, fpreal &f, bool adjust_zrange);
727  bool computeWorldLockedScrollAccel(fpreal dx, fpreal dy,
728  const UT_Vector3R &locked_pos,
729  fpreal &accelerationx,
730  fpreal &accelerationy);
731  fpreal computeZoomDelta(fpreal dx,
732  bool precise_zoom,
733  bool smooth_deltas);
734 
735  void updateWindowOverridesNominal()
736  {
737  myWindowOverridesNominal =
738  (myView.myWinX != myNominalWinX ||
739  myView.myWinY != myNominalWinY ||
740  myView.myWinW != myNominalWinW ||
741  myView.myWinH != myNominalWinH);
742  }
743 
744  GUI_ViewFlag myFlag;
745 
746 // transform information
747 
748  gui_View myView;
749  fpreal myDx, myDy;
750  static orientation myOrientationMode;
751  static int myTumbleStyle;
752  static int myAltKeyViewControls;
753  static int myScrollStyle;
754  static axis myDefaultHomingStyle;
755 
756  fpreal myRx, myRy, myRz; // Used by euler method. In degrees
757 
758  // always call updateTransformMatrix before using myTransformMatrix.
759  UT_Matrix4D myTransformMatrix; // this one is generated from the above
760  UT_Matrix4D myItransformMatrix; // inverse of myTransformMatrix;
761 
762  GUI_TransformCallback myTransformCallback;
763  void *myTransformCallbackData;
764 
765 // home information to be used in scaling of view transformation
766  fpreal myLastHomeDistance;
767  fpreal myLastHomePixelWidthOBSOLETE;
768  fpreal myLastHomeAdjustedBoxWidth;
769  fpreal myLastHomeOrthoWidth;
770  fpreal myLastHomeRadius;
771 
772  // myLastHomeAdjustedBoxWidth supercedes myLastHomePixelWidth, but to load
773  // view transforms from old hip files without screwed up scrolling, we may
774  // need to use the obsolete quantity until the next manual home operation.
775  bool myObsoleteScrollIsActive;
776 
777  axis myHomeAxis;
778  UT_Matrix3R myCustomHomeRot;
779 
780  GUI_HomeRotCallback myCPlaneHomeRotCallback;
781  void *myCPlaneHomeRotCallbackData;
782 
783  // A collection of data needed for calculating the appropriate changes to
784  // the view transform to perform view operations under continuous export
785  // of view changes to a camera.
786  class ContinuousExportCache
787  {
788  public:
789  ContinuousExportCache() {}
790 
791  UT_Matrix4D myRotateMatrix;
792  UT_Matrix4D myTransformMatrix;
793  UT_Matrix4D myItransformMatrix;
794  fpreal myAdjustedNear;
795  fpreal myAdjustedX;
796  fpreal myAdjustedY;
797  fpreal myTotalScrollX;
798  fpreal myTotalScrollY;
799  };
800 
801  typedef ContinuousExportCache ViewOpCache;
802 
803  ViewOpCache myContinuousExportCache;
804  bool myContinuousExportInProgress;
805 
806  // The nominal window (zooming) for this view. The myView.myWin* members
807  // represent the window used for the current view, but when they are used
808  // to override the camera's screen window, we need to know that this is
809  // the case and what nominal window values to use for properly displaying
810  // overlays like the safe area or field guide.
811  bool myWindowOverridesNominal;
812  fpreal myNominalWinX;
813  fpreal myNominalWinY;
814  fpreal myNominalWinW;
815  fpreal myNominalWinH;
816 
817  bool myHasSubRegion;
818  fpreal mySubRegionX;
819  fpreal mySubRegionY;
820  fpreal mySubRegionW;
821  fpreal mySubRegionH;
822 
823  // These might be needed for other guys.
824  int myViewportLeft, myViewportRight;
825  int myViewportBottom, myViewportTop;
826 
827  // The view is a subregion of the viewport that represents the current
828  // "camera" view. Aspect ratio bars are used to dim the parts of the
829  // viewport not in this view. The window coordinates are relative to
830  // this view, not the viewport.
831  int myViewLeft, myViewRight;
832  int myViewBottom, myViewTop;
833 
834  int myVersion;
835  int myVersion2D;
836 
837  fpreal32 myExtendedZBufferFar;
838  bool myHasExtendedZBufferFar;
839  bool myAllowNearFarClipAdapt;
840  UT_BoundingBoxD mySceneBounds;
841  UT_BoundingBoxD mySelectedObjBounds;
842 
843  UT_Matrix4D *myProjectionOverride;
844  bool myLimitNearClip = false;
845  fpreal myMaxNearClip = 1.0;
846 };
847 
848 
849 #ifdef __DOCUMENTATION__
850 
851 FOV can be computed from aperture and focal length.
852 
853  <--aperture--->
854  | |
855  | |
856  +------+------+-----------
857  \ | / ^
858  \ | / |
859  \_--+--_/ Focal
860 Unzoomed \ | / Length
861  FOV --> \ | / |
862  \|/ v
863  +------------------
864 
865 myFullW and myFullH are the dimensions of the plane onto which the
866 image is projected before any adjustments for zoom or window parms.
867 the plane is located at "myAdjustedNear" along the z axis.
868 After taking the zoom and win channels into account, myAdjustedX and
869 myAdjustedY refer to the center of the view on the same plane, and
870 myAdjustedW and myAdjustedH contain the dimensions of the adjusted view.
871 
872 #endif
873 
874 #endif
#define SYSmax(a, b)
Definition: SYS_Math.h:1570
void setLimits(fpreal n, fpreal f)
fpreal getNearClip() const
int getViewWidth() const
fpreal getNearLimit() const
int rotoscopeTracksWindowVals() const
bool doesWindowOverrideNominal() const
GLenum clamp
Definition: glcorearb.h:1234
void getViewportSize(int &w, int &h) const
void setSelectedObjectBounds(const UT_BoundingBoxD &b)
static void setDefaultHomingStyleFlag(int style)
void
Definition: png.h:1083
GLint left
Definition: glcorearb.h:2005
GLboolean * data
Definition: glcorearb.h:131
GT_API const UT_StringHolder time
void setApertureOffsets(fpreal h, fpreal v)
const GLdouble * v
Definition: glcorearb.h:837
void setWindow(fpreal x, fpreal y, fpreal w, fpreal h)
SYS_FORCE_INLINE void setT(const UT_Vector3D &t)
bool getInfiniteFarPlane() const
int getView2DVersion() const
axis getHomeAxis() const
GA_API const UT_StringHolder rot
fpreal getWinX() const
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
GLdouble right
Definition: glad.h:2817
int getBottomMargin() const
int h() const
Get width/height dimensions.
Definition: UT_Rect.h:247
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
void setInfiniteFarPlane(bool enable)
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
void setAperture(fpreal a)
GLenum GLenum GLsizei void * image
Definition: glad.h:5132
GLint y
Definition: glcorearb.h:103
void setCPlaneHomeRotCallback(GUI_HomeRotCallback callback, void *data)
GLdouble far
Definition: glcorearb.h:143
int getApplyAspectFlag() const
static void setTumbleStyleFlag(int style)
void getLimits(fpreal *n, fpreal *f)
float fpreal32
Definition: SYS_Types.h:200
void setView(const UT_DimRect &area)
Temporary container for either a RV_Render and an RE_Render.
void getApertureOffsets(fpreal &h, fpreal &v) const
int initialized() const
int getView3DVersion() const
void setFocalUnitScale(fpreal f)
void(* GUI_HomeRotCallback)(UT_Matrix3R &, void *)
fpreal getFarLimit() const
int getOrthoFlag() const
void setScreenWindow(fpreal l, fpreal r, fpreal b, fpreal t)
fpreal getAperture() const
void setFocalLength(fpreal f)
const char * className() const
void setAdjustLimits(GUI_ViewAdjustLimits which)
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
fpreal getFocalLength() const
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
void getWindow(fpreal &x, fpreal &y, fpreal &w, fpreal &h) const
fpreal getMaxNearClip() const
int getViewportHeight() const
void setApplyAspectFlag(int a)
SYS_FORCE_INLINE void setP(const UT_Vector3D &p)
bool any(const vbool4 &v)
Definition: simd.h:3468
void setWindowAffectRotoscope(int v)
fpreal getFocalUnitScale() const
#define GUI_API
Definition: GUI_API.h:10
void setHomeAxis(axis homeaxis)
void setOrthoFlag(int o)
void getViewport(UT_DimRect &area) const
UT_Vector2T< T > project(const UT_Vector2T< T > &u, const UT_Vector2T< T > &v)
The orthogonal projection of a vector u onto a vector v.
Definition: UT_Vector2.h:700
GUI_ViewAdjustLimits getAdjustLimits() const
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
void set(int v1, int v2, int v3, int v4)
Set the native rect type values.
Definition: UT_Rect.h:136
void setOrthoWidth(fpreal w)
static bool isOrientationZUp()
void setRotateMatrix(const UT_Matrix3D &mat)
int getViewHeight() const
void setNominalWindow(fpreal x, fpreal y, fpreal w, fpreal h)
int getViewportWidth() const
int x() const
Get lower-left corner.
Definition: UT_Rect.h:226
void allowNearFarClipAdapt(bool allow)
int w() const
Get width/height dimensions.
Definition: UT_Rect.h:246
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
fpreal getZBufferFar() const
GLint GLenum GLint x
Definition: glcorearb.h:409
fpreal getLastHomeRadius() const
ImageBuf OIIO_API rotate(const ImageBuf &src, float angle, string_view filtername=string_view(), float filterwidth=0.0f, bool recompute_roi=false, ROI roi={}, int nthreads=0)
fpreal getWinSizeX() const
static int getScrollStyleFlag()
void setIsFreeCam(bool free_cam)
int getRightMargin() const
GLdouble t
Definition: glad.h:2397
UT_Rect< UT_InclusiveRectImpl > UT_InclusiveRect
Integer rectangle class which stores its data as inclusive lower-left to upper-right (x1...
Definition: UT_Rect.h:54
fpreal getDefaultFOV() const
GT_API const UT_StringHolder version
GLint GLint bottom
Definition: glcorearb.h:2005
fpreal getWinY() const
const UT_BoundingBoxD & getSceneBounds() const
IFDmantra py
Definition: HDK_Image.dox:266
fpreal getFStop() const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
static axis getDefaultHomingStyleFlag()
static int getTumbleStyleFlag()
bool getSubRegion(fpreal &x, fpreal &y, fpreal &w, fpreal &h) const
static void setScrollStyleFlag(int style)
bool hasMaxNearClip() const
static int getAltKeyViewControlsFlag()
void setFocusDistance(fpreal f)
const UT_Matrix4D & getTransformMatrix()
fpreal64 fpreal
Definition: SYS_Types.h:277
fpreal getFocusDistance() const
static void setAltKeyViewControlsFlag(int style)
void getViewState(gui_View &view_state) const
void setSubRegion(fpreal x, fpreal y, fpreal w, fpreal h)
fpreal getAspectRatio() const
bool isDirty() const
static bool isOrientationYUp()
int y() const
Get lower-left corner.
Definition: UT_Rect.h:227
void setSceneBounds(const UT_BoundingBoxD &b)
GLint GLsizei width
Definition: glcorearb.h:103
void setCustomHomeRot(UT_Matrix3R &rot)
GLdouble GLdouble GLdouble top
Definition: glad.h:2817
Definition: core.h:982
bool isFreeCam() const
int getTopMargin() const
void setViewport(RE_RenderContext r, const UT_DimRect &viewarea)
SYS_FORCE_INLINE const UT_Vector3D & getT() const
void setViewState(const gui_View &view_state)
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
void getNominalWindow(fpreal &x, fpreal &y, fpreal &w, fpreal &h) const
void setFrustumScale(fpreal xsc, fpreal ysc)
void setAspectRatio(fpreal a)
UT_InclusiveRect getView() const
const UT_Matrix4D & getProjectionMatrix() const
GLboolean r
Definition: glcorearb.h:1222
const UT_Matrix4D & getRotateMatrix() const
SYS_FORCE_INLINE const UT_Vector3D & getP() const
int getViewVersion() const
SIM_API const UT_StringHolder distance
void setTransformCallback(GUI_TransformCallback callback, void *data)
bool hasSubRegion() const
fpreal getFarClip() const
fpreal getOrthoWidth() const
const UT_Matrix3R & getCustomHomeRot() const
fpreal getWinSizeY() const
fpreal getZBufferNear() const
void setFStop(fpreal fs)
void getScreenWindow(fpreal &l, fpreal &r, fpreal &b, fpreal &t) const
void(* GUI_TransformCallback)(UT_DMatrix4 &, fpreal time, void *)
Definition: format.h:895
UT_InclusiveRect getViewport() const
GA_API const UT_StringHolder area
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)
fpreal32 getExtendedZBufferFar() const
const UT_Matrix4D & getItransformMatrix()
int getLeftMargin() const