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