HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
frustum.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_GF_FRUSTUM_H
8 #define PXR_BASE_GF_FRUSTUM_H
9 
10 /// \file gf/frustum.h
11 /// \ingroup group_gf_BasicGeometry
12 
13 #include "pxr/pxr.h"
14 #include "pxr/base/gf/bbox3d.h"
15 #include "pxr/base/gf/matrix4d.h"
16 #include "pxr/base/gf/plane.h"
17 #include "pxr/base/gf/ray.h"
18 #include "pxr/base/gf/range1d.h"
19 #include "pxr/base/gf/range2d.h"
20 #include "pxr/base/gf/rotation.h"
21 #include "pxr/base/gf/vec2d.h"
22 #include "pxr/base/gf/vec3d.h"
23 #include "pxr/base/gf/api.h"
24 #include "pxr/base/tf/hash.h"
25 
26 #include <array>
27 #include <atomic>
28 #include <iosfwd>
29 #include <vector>
30 
32 
33 /// \class GfFrustum
34 /// \ingroup group_gf_BasicGeometry
35 ///
36 /// Basic type: View frustum.
37 ///
38 /// This class represents a viewing frustum in three dimensional eye space. It
39 /// may represent either a parallel (orthographic) or perspective projection.
40 /// One can think of the frustum as being defined by 6 boundary planes.
41 ///
42 /// The frustum is specified using these parameters:
43 /// \li The \em position of the viewpoint.
44 /// \li The \em rotation applied to the default view frame, which is
45 /// looking along the -z axis with the +y axis as the "up"
46 /// direction.
47 /// \li The 2D \em window on the reference plane that defines the left,
48 /// right, top, and bottom planes of the viewing frustum, as
49 /// described below.
50 /// \li The distances to the \em near and \em far planes.
51 /// \li The \em projection \em type
52 /// \li The view distance.
53 ///
54 /// The window and near/far parameters combine to define the view frustum as
55 /// follows. Transform the -z axis and the +y axis by the frustum rotation to
56 /// get the world-space \em view \em direction and \em up \em direction. Now
57 /// consider the \em reference \em plane that is perpendicular to the view
58 /// direction, a distance of referencePlaneDepth from the viewpoint, and whose
59 /// y axis corresponds to the up direction. The window rectangle is specified
60 /// in a 2D coordinate system embedded in this plane. The origin of the
61 /// coordinate system is the point at which the view direction vector
62 /// intersects the plane. Therefore, the point (0,1) in this plane is found by
63 /// moving 1 unit along the up direction vector in this plane. The vector from
64 /// the viewpoint to the resulting point will form a 45-degree angle with the
65 /// view direction.
66 ///
67 /// The view distance is only useful for interactive applications. It can be
68 /// used to compute a look at point which is useful when rotating around an
69 /// object of interest.
70 ///
71 class GfFrustum {
72  public:
73  /// This enum is used to determine the type of projection represented by a
74  /// frustum.
76  Orthographic, ///< Orthographic projection
77  Perspective, ///< Perspective projection
78  };
79 
80  /// This constructor creates an instance with default viewing parameters:
81  /// \li The position is the origin.
82  /// \li The rotation is the identity rotation. (The view is along
83  /// the -z axis, with the +y axis as "up").
84  /// \li The window is -1 to +1 in both dimensions.
85  /// \li The near/far interval is (1, 10).
86  /// \li The view distance is 5.0.
87  /// \li The projection type is \c GfFrustum::Perspective.
88  GF_API GfFrustum();
89 
90  /// Copy constructor.
91  GfFrustum(GfFrustum const &o)
92  : _position(o._position)
93  , _rotation(o._rotation)
94  , _window(o._window)
95  , _nearFar(o._nearFar)
96  , _viewDistance(o._viewDistance)
97  , _projectionType(o._projectionType)
98  , _planes(nullptr) {
99  if (auto *planes = o._planes.load()) {
100  _planes = new std::array<GfPlane, 6>(*planes);
101  }
102  }
103 
104  /// Move constructor.
105  GfFrustum(GfFrustum &&o) noexcept
106  : _position(o._position)
107  , _rotation(o._rotation)
108  , _window(o._window)
109  , _nearFar(o._nearFar)
110  , _viewDistance(o._viewDistance)
111  , _projectionType(o._projectionType)
112  , _planes(nullptr) {
113  if (auto *planes =
114  o._planes.exchange(nullptr, std::memory_order_relaxed)) {
115  _planes = planes;
116  }
117  }
118 
119  /// This constructor creates an instance with the given viewing
120  /// parameters.
122  const GfRange2d &window, const GfRange1d &nearFar,
123  GfFrustum::ProjectionType projectionType,
124  double viewDistance = 5.0);
125 
126  /// This constructor creates an instance from a camera matrix (always of a
127  /// y-Up camera, also see SetPositionAndRotationFromMatrix) and the given
128  /// viewing parameters.
129  GF_API GfFrustum(const GfMatrix4d &camToWorldXf,
130  const GfRange2d &window, const GfRange1d &nearFar,
131  GfFrustum::ProjectionType projectionType,
132  double viewDistance = 5.0);
133 
134  /// Copy assignment.
135  GfFrustum &operator=(GfFrustum const &o) noexcept {
136  if (this == &o) {
137  return *this;
138  }
139  _position = o._position;
140  _rotation = o._rotation;
141  _window = o._window;
142  _nearFar = o._nearFar;
143  _viewDistance = o._viewDistance;
144  _projectionType = o._projectionType;
145  delete _planes.load(std::memory_order_relaxed);
146  if (auto *planes = o._planes.load(std::memory_order_relaxed)) {
147  _planes.store(new std::array<GfPlane, 6>(*planes),
148  std::memory_order_relaxed);
149  }
150  else {
151  _planes.store(nullptr, std::memory_order_relaxed);
152  }
153  return *this;
154  }
155 
156  /// Move assignment.
157  GfFrustum &operator=(GfFrustum &&o) noexcept {
158  if (this == &o) {
159  return *this;
160  }
161  _position = o._position;
162  _rotation = o._rotation;
163  _window = o._window;
164  _nearFar = o._nearFar;
165  _viewDistance = o._viewDistance;
166  _projectionType = o._projectionType;
167  delete _planes.load(std::memory_order_relaxed);
168  _planes.store(o._planes.load(std::memory_order_relaxed),
169  std::memory_order_relaxed);
170  o._planes.store(nullptr, std::memory_order_relaxed);
171  return *this;
172  }
173 
174  friend inline size_t hash_value(const GfFrustum &f) {
175  return TfHash::Combine(
176  f._position,
177  f._rotation,
178  f._window,
179  f._nearFar,
180  f._viewDistance,
181  f._projectionType
182  );
183  }
184 
185  // Equality operator. true iff all parts match.
186  bool operator ==(const GfFrustum& f) const {
187  if (_position != f._position) return false;
188  if (_rotation != f._rotation) return false;
189  if (_window != f._window) return false;
190  if (_nearFar != f._nearFar) return false;
191  if (_viewDistance != f._viewDistance) return false;
192  if (_projectionType != f._projectionType) return false;
193 
194  return true;
195  }
196 
197  // Inequality operator. true iff not equality.
198  bool operator !=(const GfFrustum& f) const {
199  return !(*this == f);
200  }
201 
202  /// Destructor.
203  GF_API ~GfFrustum();
204 
205  /// \name Value setting and access
206  /// The methods in this group set and access the values that are used to
207  /// define a frustum.
208  ///@{
209 
210  /// Sets the position of the frustum in world space.
211  void SetPosition(const GfVec3d &position) {
212  _position = position;
213  _DirtyFrustumPlanes();
214  }
215 
216  /// Returns the position of the frustum in world space.
217  const GfVec3d & GetPosition() const {
218  return _position;
219  }
220 
221  /// Sets the orientation of the frustum in world space as a rotation to
222  /// apply to the default frame: looking along the -z axis with the +y axis
223  /// as "up".
225  _rotation = rotation;
226  _DirtyFrustumPlanes();
227  }
228 
229  /// Returns the orientation of the frustum in world space as a rotation to
230  /// apply to the -z axis.
231  const GfRotation & GetRotation() const {
232  return _rotation;
233  }
234 
235  /// Sets the position and rotation of the frustum from a camera matrix
236  /// (always from a y-Up camera). The resulting frustum's transform will
237  /// always represent a right-handed and orthonormal coordinate sytem
238  /// (scale, shear, and projection are removed from the given \p
239  /// camToWorldXf).
240  GF_API void SetPositionAndRotationFromMatrix(const GfMatrix4d &camToWorldXf);
241 
242  /// Sets the window rectangle in the reference plane that defines the
243  /// left, right, top, and bottom planes of the frustum.
244  void SetWindow(const GfRange2d &window) {
245  _window = window;
246  _DirtyFrustumPlanes();
247  }
248 
249  /// Returns the window rectangle in the reference plane.
250  const GfRange2d & GetWindow() const {
251  return _window;
252  }
253 
254  /// Returns the depth of the reference plane.
255  static double GetReferencePlaneDepth() {
256  return 1.0;
257  }
258 
259  /// Sets the near/far interval.
260  void SetNearFar(const GfRange1d &nearFar) {
261  _nearFar = nearFar;
262  _DirtyFrustumPlanes();
263  }
264 
265  /// Returns the near/far interval.
266  const GfRange1d & GetNearFar() const {
267  return _nearFar;
268  }
269 
270  /// Sets the view distance.
271  void SetViewDistance(double viewDistance) {
272  _viewDistance = viewDistance;
273  }
274 
275  /// Returns the view distance.
276  double GetViewDistance() const {
277  return _viewDistance;
278  }
279 
280  /// Sets the projection type.
282  _projectionType = projectionType;
283  _DirtyFrustumPlanes();
284  }
285 
286  /// Returns the projection type.
288  return _projectionType;
289  }
290 
291  ///@}
292 
293  /// \name Convenience methods
294  ///
295  /// The methods in this group allow the frustum's data to be accessed and
296  /// modified in terms of different representations that may be more
297  /// convenient for certain applications.
298  ///
299  ///@{
300 
301  /// Sets up the frustum in a manner similar to \c gluPerspective().
302  ///
303  /// It sets the projection type to \c GfFrustum::Perspective and sets the
304  /// window specification so that the resulting symmetric frustum encloses
305  /// an angle of \p fieldOfViewHeight degrees in the vertical direction,
306  /// with \p aspectRatio used to figure the angle in the horizontal
307  /// direction. The near and far distances are specified as well. The
308  /// window coordinates are computed as:
309  /// \code
310  /// top = tan(fieldOfViewHeight / 2)
311  /// bottom = -top
312  /// right = top * aspectRatio
313  /// left = -right
314  /// near = nearDistance
315  /// far = farDistance
316  /// \endcode
317  ///
318  GF_API void SetPerspective(double fieldOfViewHeight,
319  double aspectRatio,
320  double nearDistance, double farDistance);
321 
322  /// Sets up the frustum in a manner similar to gluPerspective().
323  ///
324  /// It sets the projection type to \c GfFrustum::Perspective and
325  /// sets the window specification so that:
326  ///
327  /// If \a isFovVertical is true, the resulting symmetric frustum encloses
328  /// an angle of \p fieldOfView degrees in the vertical direction, with \p
329  /// aspectRatio used to figure the angle in the horizontal direction.
330  ///
331  /// If \a isFovVertical is false, the resulting symmetric frustum encloses
332  /// an angle of \p fieldOfView degrees in the horizontal direction, with
333  /// \p aspectRatio used to figure the angle in the vertical direction.
334  ///
335  /// The near and far distances are specified as well. The window
336  /// coordinates are computed as follows:
337  ///
338  /// \li if isFovVertical:
339  /// \li top = tan(fieldOfView / 2)
340  /// \li right = top * aspectRatio
341  /// \li if NOT isFovVertical:
342  /// \li right = tan(fieldOfView / 2)
343  /// \li top = right / aspectRation
344  /// \li bottom = -top
345  /// \li left = -right
346  /// \li near = nearDistance
347  /// \li far = farDistance
348  ///
349  GF_API void SetPerspective(double fieldOfView,
350  bool isFovVertical,
351  double aspectRatio,
352  double nearDistance, double farDistance);
353 
354  /// Returns the current frustum in the format used by \c SetPerspective().
355  /// If the current frustum is not a perspective projection, this returns
356  /// \c false and leaves the parameters untouched.
357  GF_API bool GetPerspective(double *fieldOfViewHeight,
358  double *aspectRatio,
359  double *nearDistance,
360  double *farDistance) const;
361 
362  /// Returns the current frustum in the format used by \c SetPerspective().
363  /// If the current frustum is not a perspective projection, this returns
364  /// \c false and leaves the parameters untouched.
365  GF_API bool GetPerspective(bool isFovVertical,
366  double *fieldOfView,
367  double *aspectRatio,
368  double *nearDistance,
369  double *farDistance) const;
370 
371  /// Returns the horizontal or vertical fov of the frustum. The fov of the
372  /// frustum is not necessarily the same value as displayed in the viewer.
373  /// The displayed fov is a function of the focal length or FOV avar. The
374  /// frustum's fov may be different due to things like lens breathing.
375  ///
376  /// If the frustum is not of type \c GfFrustum::Perspective, the returned
377  /// FOV will be 0.0.
378  ///
379  /// \note The default value for \c isFovVertical is false so calling \c
380  /// GetFOV without an argument will return the horizontal field of view
381  /// which is compatible with menv2x's old GfFrustum::GetFOV routine.
382  GF_API double GetFOV(bool isFovVertical = false) const;
383 
384  /// Sets up the frustum in a manner similar to \c glOrtho().
385  ///
386  /// Sets the projection to \c GfFrustum::Orthographic and sets the window
387  /// and near/far specifications based on the given values.
388  GF_API
389  void SetOrthographic(double left, double right,
390  double bottom, double top,
391  double nearPlane, double farPlane);
392 
393  /// Returns the current frustum in the format used by \c
394  /// SetOrthographic(). If the current frustum is not an orthographic
395  /// projection, this returns \c false and leaves the parameters untouched.
396  GF_API bool GetOrthographic(double *left, double *right,
397  double *bottom, double *top,
398  double *nearPlane, double *farPlane)
399  const;
400 
401  /// Modifies the frustum to tightly enclose a sphere with the given center
402  /// and radius, using the current view direction. The planes of the
403  /// frustum are adjusted as necessary. The given amount of slack is added
404  /// to the sphere's radius is used around the sphere to avoid boundary
405  /// problems.
406  GF_API void FitToSphere(const GfVec3d &center,
407  double radius,
408  double slack = 0.0);
409 
410  /// Transforms the frustum by the given matrix.
411  ///
412  /// The transformation matrix is applied as follows: the position and the
413  /// direction vector are transformed with the given matrix. Then the
414  /// length of the new direction vector is used to rescale the near and far
415  /// plane and the view distance. Finally, the points that define the
416  /// reference plane are transformed by the matrix. This method assures
417  /// that the frustum will not be sheared or perspective-projected.
418  ///
419  /// \note Note that this definition means that the transformed frustum
420  /// does not preserve scales very well. Do \em not use this function to
421  /// transform a frustum that is to be used for precise operations such as
422  /// intersection testing.
423  GF_API GfFrustum& Transform(const GfMatrix4d &matrix);
424 
425  /// Returns the normalized world-space view direction vector, which is
426  /// computed by rotating the -z axis by the frustum's rotation.
428 
429  /// Returns the normalized world-space up vector, which is computed by
430  /// rotating the y axis by the frustum's rotation.
432 
433  /// Computes the view frame defined by this frustum. The frame consists of
434  /// the view direction, up vector and side vector, as shown in this
435  /// diagram.
436  ///
437  /// \code
438  /// up
439  /// ^ ^
440  /// | /
441  /// | / view
442  /// |/
443  /// +- - - - > side
444  /// \endcode
445  ///
446  GF_API void ComputeViewFrame(GfVec3d *side,
447  GfVec3d *up,
448  GfVec3d *view) const;
449 
450  /// Computes and returns the world-space look-at point from the eye point
451  /// (position), view direction (rotation), and view distance.
453 
454  /// Returns a matrix that represents the viewing transformation for this
455  /// frustum. That is, it returns the matrix that converts points from
456  /// world space to eye (frustum) space.
458 
459  /// Returns a matrix that represents the inverse viewing transformation
460  /// for this frustum. That is, it returns the matrix that converts points
461  /// from eye (frustum) space to world space.
463 
464  /// Returns a GL-style projection matrix corresponding to the frustum's
465  /// projection.
467 
468  /// Returns the aspect ratio of the frustum, defined as the width of the
469  /// window divided by the height. If the height is zero or negative, this
470  /// returns 0.
471  GF_API double ComputeAspectRatio() const;
472 
473  /// Returns the world-space corners of the frustum as a vector of 8
474  /// points, ordered as:
475  /// \li Left bottom near
476  /// \li Right bottom near
477  /// \li Left top near
478  /// \li Right top near
479  /// \li Left bottom far
480  /// \li Right bottom far
481  /// \li Left top far
482  /// \li Right top far
483  GF_API
484  std::vector<GfVec3d> ComputeCorners() const;
485 
486  /// Returns the world-space corners of the intersection of the frustum
487  /// with a plane parallel to the near/far plane at distance d from the
488  /// apex, ordered as:
489  /// \li Left bottom
490  /// \li Right bottom
491  /// \li Left top
492  /// \li Right top
493  /// In particular, it gives the partial result of ComputeCorners when given
494  /// near or far distance.
495  GF_API
496  std::vector<GfVec3d> ComputeCornersAtDistance(double d) const;
497 
498  /// Returns a frustum that is a narrowed-down version of this frustum. The
499  /// new frustum has the same near and far planes, but the other planes are
500  /// adjusted to be centered on \p windowPos with the new width and height
501  /// obtained from the existing width and height by multiplying by \p size[0]
502  /// and \p size[1], respectively. Finally, the new frustum is clipped
503  /// against this frustum so that it is completely contained in the existing
504  /// frustum.
505  ///
506  /// \p windowPos is given in normalized coords (-1 to +1 in both dimensions).
507  /// \p size is given as a scalar (0 to 1 in both dimensions).
508  ///
509  /// If the \p windowPos or \p size given is outside these ranges, it may
510  /// result in returning a collapsed frustum.
511  ///
512  /// This method is useful for computing a volume to use for interactive
513  /// picking.
515  const GfVec2d &size) const;
516 
517  /// Returns a frustum that is a narrowed-down version of this frustum. The
518  /// new frustum has the same near and far planes, but the other planes are
519  /// adjusted to be centered on \p worldPoint with the new width and height
520  /// obtained from the existing width and height by multiplying by \p size[0]
521  /// and \p size[1], respectively. Finally, the new frustum is clipped
522  /// against this frustum so that it is completely contained in the existing
523  /// frustum.
524  ///
525  /// \p worldPoint is given in world space coordinates.
526  /// \p size is given as a scalar (0 to 1 in both dimensions).
527  ///
528  /// If the \p size given is outside this range, it may result in returning
529  /// a collapsed frustum.
530  ///
531  /// If the \p worldPoint is at or behind the eye of the frustum, it will
532  /// return a frustum equal to this frustum.
533  ///
534  /// This method is useful for computing a volume to use for interactive
535  /// picking.
537  const GfVec2d &size) const;
538 
539  /// Builds and returns a \c GfRay that starts at the viewpoint and extends
540  /// through the given \a windowPos given in normalized coords (-1 to +1 in
541  /// both dimensions) window position.
542  ///
543  /// Contrasted with ComputePickRay(), this method returns a ray whose
544  /// origin is the eyepoint, while that method returns a ray whose origin
545  /// is on the near plane.
546  GF_API GfRay ComputeRay(const GfVec2d &windowPos) const;
547 
548  /// Builds and returns a \c GfRay that connects the viewpoint to the given
549  /// 3d point in worldspace.
550  ///
551  /// Contrasted with ComputePickRay(), this method returns a ray whose
552  /// origin is the eyepoint, while that method returns a ray whose origin
553  /// is on the near plane.
554  GF_API GfRay ComputeRay(const GfVec3d &worldSpacePos) const;
555 
556  /// Builds and returns a \c GfRay that can be used for picking at the
557  /// given normalized (-1 to +1 in both dimensions) window position.
558  ///
559  /// Contrasted with ComputeRay(), that method returns a ray whose origin
560  /// is the eyepoint, while this method returns a ray whose origin is on
561  /// the near plane.
562  GF_API GfRay ComputePickRay(const GfVec2d &windowPos) const;
563 
564  /// Builds and returns a \c GfRay that can be used for picking that
565  /// connects the viewpoint to the given 3d point in worldspace.
566  GF_API GfRay ComputePickRay(const GfVec3d &worldSpacePos) const;
567 
568  ///@}
569 
570  /// \name Intersection methods
571  ///
572  /// The methods in this group implement intersection operations
573  /// between this frustum and a given primitive.
574  ///
575  ///@{
576 
577  /// Returns true if the given axis-aligned bbox is inside or intersecting
578  /// the frustum. Otherwise, it returns false. Useful when doing picking or
579  /// frustum culling.
580  GF_API bool Intersects(const GfBBox3d &bbox) const;
581 
582  /// Returns true if the given point is inside or intersecting the frustum.
583  /// Otherwise, it returns false.
584  GF_API bool Intersects(const GfVec3d &point) const;
585 
586  /// Returns \c true if the line segment formed by the given points is
587  /// inside or intersecting the frustum. Otherwise, it returns false.
588  GF_API bool Intersects(const GfVec3d &p0,
589  const GfVec3d &p1) const;
590 
591  /// Returns \c true if the triangle formed by the given points is inside
592  /// or intersecting the frustum. Otherwise, it returns false.
593  GF_API bool Intersects(const GfVec3d &p0,
594  const GfVec3d &p1,
595  const GfVec3d &p2) const;
596 
597  /// Returns \c true if the bbox volume intersects the view volume given by
598  /// the view-projection matrix, erring on the side of false positives for
599  /// efficiency.
600  ///
601  /// This method is intended for cases where a GfFrustum is not available
602  /// or when the view-projection matrix yields a view volume that is not
603  /// expressable as a GfFrustum.
604  ///
605  /// Because it errs on the side of false positives, it is suitable for
606  /// early-out tests such as draw or intersection culling.
607  ///
608  GF_API static bool IntersectsViewVolume(const GfBBox3d &bbox,
609  const GfMatrix4d &vpMat);
610 
611  ///@}
612 
613  private:
614  // Dirty the result of _CalculateFrustumPlanes.
615  GF_API void _DirtyFrustumPlanes();
616 
617  // Calculates cached frustum planes used for intersection tests.
618  GF_API void _CalculateFrustumPlanes() const;
619 
620  // Builds and returns a \c GfRay that can be used for picking. Given an
621  // eye position and direction in camera space, offsets the ray to emanate
622  // from the near plane, then transforms into worldspace
623  GF_API GfRay _ComputePickRayOffsetToNearPlane(
624  const GfVec3d &camSpaceFrom,
625  const GfVec3d &camSpaceDir) const;
626 
627  // Returns a frustum that is a narrowed-down version of this frustum. The
628  // new frustum has the same near and far planes, but the other planes are
629  // adjusted to be centered on \p windowPoint with the new width and height
630  // obtained from the existing width and height by multiplying by \p size[0]
631  // and \p size[1], respectively. Finally, the new frustum is clipped
632  // against this frustum so that it is completely contained in the existing
633  // frustum.
634  //
635  // \p windowPoint is given in window coordinates.
636  // \p size is given as a scalar (0 to 1 in both dimensions).
637  //
638  // If the \p size given is outside this range, it may result in returning
639  // a collapsed frustum.
640  //
641  // This method is useful for computing a volume to use for interactive
642  // picking.
643  GfFrustum _ComputeNarrowedFrustumSub(const GfVec2d windowPoint,
644  const GfVec2d &size) const;
645 
646  bool _SegmentIntersects(GfVec3d const &p0, uint32_t p0Mask,
647  GfVec3d const &p1, uint32_t p1Mask) const;
648 
649  // Position of the frustum in world space.
650  GfVec3d _position;
651 
652  // Orientation of the frustum in world space as a rotation to apply to the
653  // -z axis.
654  GfRotation _rotation;
655 
656  // Window rectangle in the image plane.
657  GfRange2d _window;
658 
659  // Near/far interval.
660  GfRange1d _nearFar;
661 
662  // View distance.
663  double _viewDistance;
664 
665  // Projection type.
666  ProjectionType _projectionType;
667 
668  // Cached planes.
669  // If null, the planes have not been calculated.
670  mutable std::atomic<std::array<GfPlane, 6> *> _planes;
671 };
672 
673 /// Output a GfFrustum using the format [(position) (rotation) [window]
674 /// [nearFar] viewDistance type]
675 ///
676 /// The "type" is "perspective", or "orthographic, depending on the
677 /// projection type of the frustum.
678 ///
679 /// \ingroup group_gf_DebuggingOutput
680 GF_API std::ostream& operator<<(std::ostream& out, const GfFrustum& f);
681 
683 
684 #endif // PXR_BASE_GF_FRUSTUM_H
bool operator==(const GfFrustum &f) const
Definition: frustum.h:186
GF_API GfFrustum()
void SetRotation(const GfRotation &rotation)
Definition: frustum.h:224
GfFrustum(GfFrustum const &o)
Copy constructor.
Definition: frustum.h:91
void SetViewDistance(double viewDistance)
Sets the view distance.
Definition: frustum.h:271
friend size_t hash_value(const GfFrustum &f)
Definition: frustum.h:174
GfFrustum & operator=(GfFrustum const &o) noexcept
Copy assignment.
Definition: frustum.h:135
static double GetReferencePlaneDepth()
Returns the depth of the reference plane.
Definition: frustum.h:255
GF_API std::vector< GfVec3d > ComputeCorners() const
GF_API std::ostream & operator<<(std::ostream &out, const GfFrustum &f)
GLint left
Definition: glcorearb.h:2005
GF_API bool Intersects(const GfBBox3d &bbox) const
GF_API GfVec3d ComputeViewDirection() const
GF_API bool GetOrthographic(double *left, double *right, double *bottom, double *top, double *nearPlane, double *farPlane) const
Perspective projection.
Definition: frustum.h:77
GF_API double ComputeAspectRatio() const
GF_API GfFrustum & Transform(const GfMatrix4d &matrix)
GLdouble right
Definition: glad.h:2817
GF_API GfRay ComputePickRay(const GfVec2d &windowPos) const
GF_API void FitToSphere(const GfVec3d &center, double radius, double slack=0.0)
const GfVec3d & GetPosition() const
Returns the position of the frustum in world space.
Definition: frustum.h:217
GF_API void SetPositionAndRotationFromMatrix(const GfMatrix4d &camToWorldXf)
GF_API double GetFOV(bool isFovVertical=false) const
Definition: vec2d.h:45
GF_API GfVec3d ComputeLookAtPoint() const
GfFrustum(GfFrustum &&o) noexcept
Move constructor.
Definition: frustum.h:105
const GfRange1d & GetNearFar() const
Returns the near/far interval.
Definition: frustum.h:266
GF_API GfMatrix4d ComputeViewMatrix() const
GF_API GfMatrix4d ComputeViewInverse() const
GLfloat f
Definition: glcorearb.h:1926
GF_API void SetOrthographic(double left, double right, double bottom, double top, double nearPlane, double farPlane)
GF_API GfMatrix4d ComputeProjectionMatrix() const
void SetWindow(const GfRange2d &window)
Definition: frustum.h:244
GfFrustum::ProjectionType GetProjectionType() const
Returns the projection type.
Definition: frustum.h:287
static GF_API bool IntersectsViewVolume(const GfBBox3d &bbox, const GfMatrix4d &vpMat)
SIM_API const UT_StringHolder rotation
double GetViewDistance() const
Returns the view distance.
Definition: frustum.h:276
GF_API bool GetPerspective(double *fieldOfViewHeight, double *aspectRatio, double *nearDistance, double *farDistance) const
bool operator!=(const GfFrustum &f) const
Definition: frustum.h:198
GF_API std::vector< GfVec3d > ComputeCornersAtDistance(double d) const
const GfRange2d & GetWindow() const
Returns the window rectangle in the reference plane.
Definition: frustum.h:250
const GfRotation & GetRotation() const
Definition: frustum.h:231
void SetProjectionType(GfFrustum::ProjectionType projectionType)
Sets the projection type.
Definition: frustum.h:281
GLint GLint bottom
Definition: glcorearb.h:2005
ProjectionType
Definition: frustum.h:75
GLsizeiptr size
Definition: glcorearb.h:664
GF_API GfRay ComputeRay(const GfVec2d &windowPos) const
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GF_API GfFrustum ComputeNarrowedFrustum(const GfVec2d &windowPos, const GfVec2d &size) const
SIM_API const UT_StringHolder position
Definition: vec3d.h:45
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GF_API ~GfFrustum()
Destructor.
Definition: ray.h:44
GLdouble GLdouble GLdouble top
Definition: glad.h:2817
Orthographic projection.
Definition: frustum.h:76
GF_API void SetPerspective(double fieldOfViewHeight, double aspectRatio, double nearDistance, double farDistance)
void SetNearFar(const GfRange1d &nearFar)
Sets the near/far interval.
Definition: frustum.h:260
GF_API GfVec3d ComputeUpVector() const
GfFrustum & operator=(GfFrustum &&o) noexcept
Move assignment.
Definition: frustum.h:157
#define GF_API
Definition: api.h:23
void SetPosition(const GfVec3d &position)
Sets the position of the frustum in world space.
Definition: frustum.h:211
GF_API void ComputeViewFrame(GfVec3d *side, GfVec3d *up, GfVec3d *view) const