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 
314  { mySceneBounds=b; }
315  const UT_BoundingBoxD &getSceneBounds() const { return mySceneBounds; }
317  { mySelectedObjBounds=b; }
318 
319  // In case far/near > 10M, and extended zbuffer range is supported
320  // Far clip will be at this value rather than 1.0.
321  fpreal32 getExtendedZBufferFar() const { return myExtendedZBufferFar; }
322 
323  static void setExtendedZBufferRangeSupport(bool has_ext);
324 
325  void allowNearFarClipAdapt(bool allow)
326  { myAllowNearFarClipAdapt = allow; }
327 
328  // True if the viewer isn't tied to a camera.
329  void setIsFreeCam(bool free_cam) { myIsFreeCam = free_cam; }
330  bool isFreeCam() const { return myIsFreeCam; }
331 
333  {
334  myView.myWinX = x;
335  myView.myWinY = y;
336  myView.myWinW = SYSmax(w, fpreal(0.001));
337  myView.myWinH = SYSmax(h, fpreal(0.001));
338  updateWindowOverridesNominal();
339  }
341  fpreal &w, fpreal &h) const
342  {
343  x = myView.myWinX;
344  y = myView.myWinY;
345  w = myView.myWinW;
346  h = myView.myWinH;
347  }
348 
350  {
351  myNominalWinX = x;
352  myNominalWinY = y;
353  myNominalWinW = SYSmax(w, fpreal(0.001));
354  myNominalWinH = SYSmax(h, fpreal(0.001));
355  updateWindowOverridesNominal();
356  }
358  fpreal &w, fpreal &h) const
359  {
360  x = myNominalWinX;
361  y = myNominalWinY;
362  w = myNominalWinW;
363  h = myNominalWinH;
364  }
366  { return myWindowOverridesNominal; }
367 
368  // A handy method to compute the view region bounds relative to the nominal
369  // window rather than relative to the current window. With bounds relative
370  // to the nominal window, the nominal window is the unit square from (0,0)
371  // to (1,1), in contrast with bounds relative to the current window, which
372  // are themselves always this unit square.
373  void getViewBoundsRelativeToNominalWindow(
374  fpreal &l, fpreal &r, fpreal &b, fpreal &t) const;
375 
376  // The window is stored as an offset from 0, 0 with the scale applied prior
377  // to translation. However, mantra and other renderers expect the window
378  // to be relative to the (0,1) rectangle. getScreenWindow() will translate
379  // the window parameters into a screen window. setScreenWindow() will take
380  // a screen window and set the appropriate parameters.
382  fpreal &b, fpreal &t) const
383  {
384  convertViewToScreenWindow(myView.myWinX, myView.myWinY,
385  myView.myWinW, myView.myWinH,
386  l, r, b, t);
387  }
389  {
390  convertScreenToViewWindow(l, r, b, t,
391  myView.myWinX, myView.myWinY,
392  myView.myWinW, myView.myWinH);
393  }
394 
396  {
397  myHasSubRegion = true;
398  mySubRegionX = x;
399  mySubRegionY = y;
400  mySubRegionW = w;
401  mySubRegionH = h;
402  }
404  {
405  myHasSubRegion = false;
406  mySubRegionX = 0.0;
407  mySubRegionY = 0.0;
408  mySubRegionW = 1.0;
409  mySubRegionH = 1.0;
410  }
412  {
413  x = mySubRegionX;
414  y = mySubRegionY;
415  w = mySubRegionW;
416  h = mySubRegionH;
417  return myHasSubRegion;
418  }
419  bool hasSubRegion() const { return myHasSubRegion; }
420 
421  static void convertScreenToViewWindow(
422  fpreal l, fpreal r, fpreal b, fpreal t,
423  fpreal &xoff, fpreal &yoff, fpreal &xsize, fpreal &ysz);
424  static void convertViewToScreenWindow(
425  fpreal xoff, fpreal yoff, fpreal xsize, fpreal ysize,
426  fpreal &l, fpreal &r, fpreal &b, fpreal &t);
427 
428  fpreal getWinSizeX() const { return myView.myWinW; }
429  fpreal getWinSizeY() const { return myView.myWinH; }
430  fpreal getWinX() const { return myView.myWinX; }
431  fpreal getWinY() const { return myView.myWinY; }
432 
434  {
435  GUI_VIEW_ADJUST_NONE = 0,
436  GUI_VIEW_ADJUST_FAR = 1,
437  GUI_VIEW_ADJUST_NEAR = 2,
438  GUI_VIEW_ADJUST_BOTH = 3
439  };
441  { myAdjustLimits = which; }
442  GUI_ViewAdjustLimits getAdjustLimits() const { return myAdjustLimits; }
443 
444  void setWindowAffectRotoscope(int v) { myFlag.rotoTrackWindow = v; }
446  { return myFlag.rotoTrackWindow; }
447 
448  // aspectRatio
449  void setApplyAspectFlag(int a) { myFlag.applyAspect = a; }
450  int getApplyAspectFlag() const { return myFlag.applyAspect; }
451  void setAspectRatio(fpreal a) { myViewAspectRatio = a; }
452  fpreal getAspectRatio() const { return myViewAspectRatio; }
453 
455  {
456  myFrustumWidthScale = xsc;
457  myFrustumHeightScale = ysc;
458  }
459 
460  // Return 8 corner points of the frustum, near points first (BL,BR,TL,TR)
461  void getFrustumPoints(UT_Vector3FArray &pnts);
462 
463  // position
465  void setT(const UT_Vector3D &t)
466  { myView.myT = t; myFlag.matrixDirty=1; myFlag.iMatrixDirty=1;}
468  const UT_Vector3D & getT() const { return myView.myT; }
469 
470  // pivot
472  const UT_Vector3D & getP() const { return myView.myP; }
474  void setP(const UT_Vector3D &p)
475  { myView.myP = p; myFlag.matrixDirty=1; myFlag.iMatrixDirty=1;}
476 
477  static void setOrientationMode(orientation o);
478  static orientation getOrientationMode();
479  static bool isOrientationYUp()
480  { return getOrientationMode() == Y_UP; }
481  static bool isOrientationZUp()
482  { return getOrientationMode() == Z_UP; }
483 
484  // Rotation style:
485  static void setTumbleStyleFlag(int style)
486  { myTumbleStyle = style; }
487  static int getTumbleStyleFlag() { return myTumbleStyle; }
488  static void setAltKeyViewControlsFlag(int style)
489  { myAltKeyViewControls = style; }
490  static int getAltKeyViewControlsFlag() { return myAltKeyViewControls; }
491  static void setScrollStyleFlag(int style)
492  { myScrollStyle = style; }
493  static int getScrollStyleFlag() { return myScrollStyle; }
494  static void setDefaultHomingStyleFlag(int style)
495  { myDefaultHomingStyle = GUI_ViewParameter::axis(style); }
496  static axis getDefaultHomingStyleFlag() { return myDefaultHomingStyle; }
497 
498  // the resulting matrices
499  void setRotateMatrix(const UT_Matrix3D &mat)
500  { myView.myRotateMatrix = mat;
501  myFlag.matrixDirty = 1;
502  myFlag.iMatrixDirty = 1;
503  myFlag.rxyzDirty = 1; }
504  const UT_Matrix4D &getRotateMatrix() const { return myView.myRotateMatrix; }
505 
507  { return myProjectionOverride ? *myProjectionOverride
508  : myView.myProjectionMatrix; }
509  const UT_Matrix4D &getTransformMatrix() { updateTransformMatrix();
510  return myTransformMatrix; }
511  const UT_Matrix4D &getItransformMatrix() { updateItransformMatrix();
512  return myItransformMatrix; }
513 
514  // This sets the transform matrix to the given value, bypassing the
515  // PX, TX, etc. The purpose of this is to get accurate camera transforms
516  // you can first set all the PX, Rotate, etc, according to the cracked
517  // values, and then do a forceTransformMatrix to ensure the user sees
518  // the most accurate possible matrix.
519  void forceTransformMatrix(const UT_DMatrix4 &mat);
520  void getTransformMatrix(UT_DMatrix4 &mat, fpreal time);
522  void *data)
523  {
524  myTransformCallback = callback;
525  myTransformCallbackData = data;
526  }
527 
528  // Class I/O methods. They return 0 if successful, -1 if not.
529  // `for_view_copy` is only for temporarily transferring one view parms to
530  // another.
531  int save(std::ostream &os,
532  char separator = '\n',
533  bool for_view_copy = false) const;
534  bool load(UT_IStream &is);
535  bool oldLoad(UT_IStream &is, int version);
536 
537  // inline for non-virtual class
538  const char *className() const { return "GUI_ViewParameter"; }
539 
540  fpreal getLastHomeRadius() const { return myLastHomeRadius; }
541 
542  void setHomeAxis(axis homeaxis)
543  { myHomeAxis = homeaxis; myFlag.rxyzDirty = 1; }
544  axis getHomeAxis() const { return myHomeAxis; }
545  void setCustomHomeRot(UT_Matrix3R &rot) { myCustomHomeRot = rot; }
546  const UT_Matrix3R &getCustomHomeRot() const { return myCustomHomeRot; }
547 
548  // Set a callback to get the home rotation for the construction plane
549  // (axis::CPLANE), to which this class does not have direct access.
551  void *data)
552  {
553  myCPlaneHomeRotCallback = callback;
554  myCPlaneHomeRotCallbackData = data;
555  }
556 
557 
558  void setOrthoWidth(fpreal w) { myView.myOrthoWidth = w; }
559  fpreal getOrthoWidth() const { return myView.myOrthoWidth; }
560 
561  void setFocalLength(fpreal f) { myView.myFocalLength = f; }
562  fpreal getFocalLength() const { return myView.myFocalLength; }
563 
564  void setFocalUnitScale(fpreal f) { myView.myFocalScale = f; }
565  fpreal getFocalUnitScale() const { return myView.myFocalScale; }
566 
567  void setFocusDistance(fpreal f) { myView.myFocusDistance = f; }
568  fpreal getFocusDistance() const { return myView.myFocusDistance; }
569 
570  void setAperture(fpreal a) { myView.myAperture = a; }
571  fpreal getAperture() const { return myView.myAperture; }
572 
573  void setFStop(fpreal fs) { myView.myFStop = fs; }
574  fpreal getFStop() const { return myView.myFStop; }
575 
577  {
578  myView.myHApertureOffset = h;
579  myView.myVApertureOffset = v;
580  }
582  {
583  h = myView.myHApertureOffset;
584  v = myView.myVApertureOffset;
585  }
586 
587  fpreal getNearLimit() const { return myView.myNearLimit; }
588  fpreal getFarLimit() const { return myView.myFarLimit; }
589 
590  fpreal getZBufferNear() const { return myZBufferNear; }
591  fpreal getZBufferFar() const { return myZBufferFar; }
592 
593  // viewport clearing
595 
596  // fog
597  int myFog;
599  float myFogNear;
600  float myFogFar;
601  float myFogColor[3];
602  float myFogAlpha;
603 
604  // used for rotoscoping only
606 
607  // container for all view home information
608  class gui_View
609  {
610  public:
612  : myT(0.0, 0.0, 0.1),
613  myP(0.0, 0.0, 0.0),
614  myRotateMatrix(1.0),
615  myProjectionMatrix(1.0),
616  myWinX(0.0),
617  myWinY(0.0),
618  myWinW(1.0),
619  myWinH(1.0),
620  myOrthoWidth(1.0),
621  myFocalLength(50.0),
622  myFocusDistance(5.0),
623  myAperture(41.4214),
624  myFStop(5.6),
625  myFocalScale(0.001),
626  myNearLimit(0.1),
627  myFarLimit(10000.0),
628  myHApertureOffset(0.0),
629  myVApertureOffset(0.0),
630  myDefaultFOV(45.0)
631  {}
632 
635 
638 
639  // window (zooming)
644 
645  // projection information
646  // ortho specific
648 
649  // perspective specific sSee diagram below)
653  fpreal myFStop; // for dof.
658 
661  };
662 
663  // methods to quickly stash and recall the view state.
664  void getViewState(gui_View &view_state) const
665  { view_state = myView; }
666  void setViewState(const gui_View &view_state)
667  {
668  myView = view_state;
669  myFlag.matrixDirty=1;
670  myFlag.iMatrixDirty=1;
671  myFlag.rxyzDirty=1;
672  updateWindowOverridesNominal();
673  }
674 
675  void adjustNearFarClip();
676 
677  // clipping
678 private:
679  fpreal myZBufferNear;
680  fpreal myZBufferFar;
681  GUI_ViewAdjustLimits myAdjustLimits;
682  bool myInfiniteFarPlane = false;
683  bool myIsFreeCam = true;
684 
685  // aspect ratio
686  fpreal myViewAspectRatio;
687 public:
688  fpreal myPixelAspect; // depends on output device
689 
690 // projection information (see docs below)
701 
703 
704 private:
705  void updateTransformMatrix();
706  void updateItransformMatrix();
707  void updateRXYZValues();
708  fpreal getDistanceToBoxCenter(int clamp = 0) const;
709 
710  void internalScroll(fpreal dx, fpreal dy,
711  const UT_InclusiveRect &viewport,
712  bool decouple_axes,
713  const UT_Vector3R *locked_pos);
714  void internalZoom(fpreal dx, GUI_ZoomItem item, int width);
715  void internalOffsetZoom(fpreal sx, fpreal sy, fpreal dx,
716  GUI_ZoomItem item,
717  const UT_InclusiveRect &viewport);
718  void internalScreenScroll(fpreal dx, fpreal dy,
719  const UT_InclusiveRect &viewport);
720 
721  void getFrustumClip(fpreal &l, fpreal &r, fpreal &t, fpreal &b,
722  fpreal &n, fpreal &f, bool adjust_zrange);
723  bool computeWorldLockedScrollAccel(fpreal dx, fpreal dy,
724  const UT_Vector3R &locked_pos,
725  fpreal &accelerationx,
726  fpreal &accelerationy);
727  fpreal computeZoomDelta(fpreal dx,
728  bool precise_zoom,
729  bool smooth_deltas);
730 
731  void updateWindowOverridesNominal()
732  {
733  myWindowOverridesNominal =
734  (myView.myWinX != myNominalWinX ||
735  myView.myWinY != myNominalWinY ||
736  myView.myWinW != myNominalWinW ||
737  myView.myWinH != myNominalWinH);
738  }
739 
740  GUI_ViewFlag myFlag;
741 
742 // transform information
743 
744  gui_View myView;
745  fpreal myDx, myDy;
746  static orientation myOrientationMode;
747  static int myTumbleStyle;
748  static int myAltKeyViewControls;
749  static int myScrollStyle;
750  static axis myDefaultHomingStyle;
751 
752  fpreal myRx, myRy, myRz; // Used by euler method. In degrees
753 
754  // always call updateTransformMatrix before using myTransformMatrix.
755  UT_Matrix4D myTransformMatrix; // this one is generated from the above
756  UT_Matrix4D myItransformMatrix; // inverse of myTransformMatrix;
757 
758  GUI_TransformCallback myTransformCallback;
759  void *myTransformCallbackData;
760 
761 // home information to be used in scaling of view transformation
762  fpreal myLastHomeDistance;
763  fpreal myLastHomePixelWidthOBSOLETE;
764  fpreal myLastHomeAdjustedBoxWidth;
765  fpreal myLastHomeOrthoWidth;
766  fpreal myLastHomeRadius;
767 
768  // myLastHomeAdjustedBoxWidth supercedes myLastHomePixelWidth, but to load
769  // view transforms from old hip files without screwed up scrolling, we may
770  // need to use the obsolete quantity until the next manual home operation.
771  bool myObsoleteScrollIsActive;
772 
773  axis myHomeAxis;
774  UT_Matrix3R myCustomHomeRot;
775 
776  GUI_HomeRotCallback myCPlaneHomeRotCallback;
777  void *myCPlaneHomeRotCallbackData;
778 
779  // A collection of data needed for calculating the appropriate changes to
780  // the view transform to perform view operations under continuous export
781  // of view changes to a camera.
782  class ContinuousExportCache
783  {
784  public:
785  ContinuousExportCache() {}
786 
787  UT_Matrix4D myRotateMatrix;
788  UT_Matrix4D myTransformMatrix;
789  UT_Matrix4D myItransformMatrix;
790  fpreal myAdjustedNear;
791  fpreal myAdjustedX;
792  fpreal myAdjustedY;
793  fpreal myTotalScrollX;
794  fpreal myTotalScrollY;
795  };
796 
797  typedef ContinuousExportCache ViewOpCache;
798 
799  ViewOpCache myContinuousExportCache;
800  bool myContinuousExportInProgress;
801 
802  // The nominal window (zooming) for this view. The myView.myWin* members
803  // represent the window used for the current view, but when they are used
804  // to override the camera's screen window, we need to know that this is
805  // the case and what nominal window values to use for properly displaying
806  // overlays like the safe area or field guide.
807  bool myWindowOverridesNominal;
808  fpreal myNominalWinX;
809  fpreal myNominalWinY;
810  fpreal myNominalWinW;
811  fpreal myNominalWinH;
812 
813  bool myHasSubRegion;
814  fpreal mySubRegionX;
815  fpreal mySubRegionY;
816  fpreal mySubRegionW;
817  fpreal mySubRegionH;
818 
819  // These might be needed for other guys.
820  int myViewportLeft, myViewportRight;
821  int myViewportBottom, myViewportTop;
822 
823  // The view is a subregion of the viewport that represents the current
824  // "camera" view. Aspect ratio bars are used to dim the parts of the
825  // viewport not in this view. The window coordinates are relative to
826  // this view, not the viewport.
827  int myViewLeft, myViewRight;
828  int myViewBottom, myViewTop;
829 
830  int myVersion;
831  int myVersion2D;
832 
833  fpreal32 myExtendedZBufferFar;
834  bool myHasExtendedZBufferFar;
835  bool myAllowNearFarClipAdapt;
836  UT_BoundingBoxD mySceneBounds;
837  UT_BoundingBoxD mySelectedObjBounds;
838 
839  UT_Matrix4D *myProjectionOverride;
840 };
841 
842 
843 #ifdef __DOCUMENTATION__
844 
845 FOV can be computed from aperture and focal length.
846 
847  <--aperture--->
848  | |
849  | |
850  +------+------+-----------
851  \ | / ^
852  \ | / |
853  \_--+--_/ Focal
854 Unzoomed \ | / Length
855  FOV --> \ | / |
856  \|/ v
857  +------------------
858 
859 myFullW and myFullH are the dimensions of the plane onto which the
860 image is projected before any adjustments for zoom or window parms.
861 the plane is located at "myAdjustedNear" along the z axis.
862 After taking the zoom and win channels into account, myAdjustedX and
863 myAdjustedY refer to the center of the view on the same plane, and
864 myAdjustedW and myAdjustedH contain the dimensions of the adjusted view.
865 
866 #endif
867 
868 #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
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)
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