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