24 #ifndef PXR_BASE_GF_FRUSTUM_H 25 #define PXR_BASE_GF_FRUSTUM_H 40 #include "pxr/base/gf/api.h" 48 PXR_NAMESPACE_OPEN_SCOPE
109 : _position(o._position)
110 , _rotation(o._rotation)
112 , _nearFar(o._nearFar)
113 , _viewDistance(o._viewDistance)
114 , _projectionType(o._projectionType)
116 if (
auto *planes = o._planes.load()) {
117 _planes =
new std::array<GfPlane, 6>(*planes);
123 : _position(o._position)
124 , _rotation(o._rotation)
126 , _nearFar(o._nearFar)
127 , _viewDistance(o._viewDistance)
128 , _projectionType(o._projectionType)
131 o._planes.exchange(
nullptr, std::memory_order_relaxed)) {
141 double viewDistance = 5.0);
149 double viewDistance = 5.0);
156 _position = o._position;
157 _rotation = o._rotation;
159 _nearFar = o._nearFar;
160 _viewDistance = o._viewDistance;
161 _projectionType = o._projectionType;
162 delete _planes.load(std::memory_order_relaxed);
163 if (
auto *planes = o._planes.load(std::memory_order_relaxed)) {
164 _planes.store(
new std::array<GfPlane, 6>(*planes),
165 std::memory_order_relaxed);
168 _planes.store(
nullptr, std::memory_order_relaxed);
178 _position = o._position;
179 _rotation = o._rotation;
181 _nearFar = o._nearFar;
182 _viewDistance = o._viewDistance;
183 _projectionType = o._projectionType;
184 delete _planes.load(std::memory_order_relaxed);
185 _planes.store(o._planes.load(std::memory_order_relaxed),
186 std::memory_order_relaxed);
187 o._planes.store(
nullptr, std::memory_order_relaxed);
191 friend inline size_t hash_value(
const GfFrustum &f) {
203 bool operator ==(
const GfFrustum& f)
const {
204 if (_position != f._position)
return false;
205 if (_rotation != f._rotation)
return false;
206 if (_window != f._window)
return false;
207 if (_nearFar != f._nearFar)
return false;
208 if (_viewDistance != f._viewDistance)
return false;
209 if (_projectionType != f._projectionType)
return false;
215 bool operator !=(
const GfFrustum& f)
const {
216 return !(*
this == f);
229 _position = position;
230 _DirtyFrustumPlanes();
242 _rotation = rotation;
243 _DirtyFrustumPlanes();
263 _DirtyFrustumPlanes();
279 _DirtyFrustumPlanes();
289 _viewDistance = viewDistance;
294 return _viewDistance;
299 _projectionType = projectionType;
300 _DirtyFrustumPlanes();
305 return _projectionType;
337 double nearDistance,
double farDistance);
369 double nearDistance,
double farDistance);
376 double *nearDistance,
377 double *farDistance)
const;
385 double *nearDistance,
386 double *farDistance)
const;
399 GF_API
double GetFOV(
bool isFovVertical =
false);
407 double bottom,
double top,
408 double nearPlane,
double farPlane);
414 double *bottom,
double *top,
415 double *nearPlane,
double *farPlane)
632 GF_API
void _DirtyFrustumPlanes();
635 GF_API
void _CalculateFrustumPlanes()
const;
640 GF_API
GfRay _ComputePickRayOffsetToNearPlane(
642 const GfVec3d &camSpaceDir)
const;
663 bool _SegmentIntersects(
GfVec3d const &p0, uint32_t p0Mask,
664 GfVec3d const &p1, uint32_t p1Mask)
const;
680 double _viewDistance;
687 mutable std::atomic<std::array<GfPlane, 6> *> _planes;
699 PXR_NAMESPACE_CLOSE_SCOPE
701 #endif // PXR_BASE_GF_FRUSTUM_H const GfVec3d & GetPosition() const
Returns the position of the frustum in world space.
GF_API GfMatrix4d ComputeProjectionMatrix() const
Returns a GL-style projection matrix corresponding to the frustum's projection.
GF_API GfVec3d ComputeUpVector() const
Returns the normalized world-space up vector, which is computed by rotating the y axis by the frustum...
void SetProjectionType(GfFrustum::ProjectionType projectionType)
Sets the projection type.
Basic type: 1-dimensional floating point range.
const GfRange1d & GetNearFar() const
Returns the near/far interval.
GF_API void FitToSphere(const GfVec3d ¢er, double radius, double slack=0.0)
Modifies the frustum to tightly enclose a sphere with the given center and radius,...
GF_API GfVec3d ComputeLookAtPoint() const
Computes and returns the world-space look-at point from the eye point (position), view direction (rot...
GF_API std::vector< GfVec3d > ComputeCorners() const
Returns the world-space corners of the frustum as a vector of 8 points, ordered as:
const GfRange2d & GetWindow() const
Returns the window rectangle in the reference plane.
GF_API GfFrustum & Transform(const GfMatrix4d &matrix)
Transforms the frustum by the given matrix.
Basic type for a vector of 2 double components.
GF_API GfMatrix4d ComputeViewMatrix() const
Returns a matrix that represents the viewing transformation for this frustum.
GF_API void SetOrthographic(double left, double right, double bottom, double top, double nearPlane, double farPlane)
Sets up the frustum in a manner similar to glOrtho().
GF_API void SetPositionAndRotationFromMatrix(const GfMatrix4d &camToWorldXf)
Sets the position and rotation of the frustum from a camera matrix (always from a y-Up camera).
GF_API double ComputeAspectRatio() const
Returns the aspect ratio of the frustum, defined as the width of the window divided by the height.
static GF_API bool IntersectsViewVolume(const GfBBox3d &bbox, const GfMatrix4d &vpMat)
Returns true if the bbox volume intersects the view volume given by the view-projection matrix,...
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
GF_API GfMatrix4d ComputeViewInverse() const
Returns a matrix that represents the inverse viewing transformation for this frustum.
void SetWindow(const GfRange2d &window)
Sets the window rectangle in the reference plane that defines the left, right, top,...
void SetViewDistance(double viewDistance)
Sets the view distance.
Stores a 4x4 matrix of double elements.
GF_API double GetFOV(bool isFovVertical=false)
Returns the horizontal or vertical fov of the frustum.
Basic type: 2-dimensional floating point range.
Basic type: View frustum.
GF_API bool GetOrthographic(double *left, double *right, double *bottom, double *top, double *nearPlane, double *farPlane) const
Returns the current frustum in the format used by SetOrthographic().
GF_API void SetPerspective(double fieldOfViewHeight, double aspectRatio, double nearDistance, double farDistance)
Sets up the frustum in a manner similar to gluPerspective().
const GfRotation & GetRotation() const
Returns the orientation of the frustum in world space as a rotation to apply to the -z axis.
GF_API GfRay ComputeRay(const GfVec2d &windowPos) const
Builds and returns a GfRay that starts at the viewpoint and extends through the given windowPos given...
GfFrustum & operator=(GfFrustum &&o) noexcept
Move assignment.
GfFrustum(GfFrustum const &o)
Copy constructor.
void SetNearFar(const GfRange1d &nearFar)
Sets the near/far interval.
ProjectionType
This enum is used to determine the type of projection represented by a frustum.
GfFrustum(GfFrustum &&o) noexcept
Move constructor.
GF_API GfFrustum ComputeNarrowedFrustum(const GfVec2d &windowPos, const GfVec2d &size) const
Returns a frustum that is a narrowed-down version of this frustum.
GF_API ~GfFrustum()
Destructor.
GF_API GfVec3d ComputeViewDirection() const
Returns the normalized world-space view direction vector, which is computed by rotating the -z axis b...
GF_API GfFrustum()
This constructor creates an instance with default viewing parameters:
GF_API void ComputeViewFrame(GfVec3d *side, GfVec3d *up, GfVec3d *view) const
Computes the view frame defined by this frustum.
GF_API bool Intersects(const GfBBox3d &bbox) const
Returns true if the given axis-aligned bbox is inside or intersecting the frustum.
GfFrustum & operator=(GfFrustum const &o) noexcept
Copy assignment.
void SetPosition(const GfVec3d &position)
Sets the position of the frustum in world space.
Basic type for a vector of 3 double components.
GF_API std::ostream & operator<<(std::ostream &out, const GfFrustum &f)
Output a GfFrustum using the format [(position) (rotation) [window] [nearFar] viewDistance type].
GfFrustum::ProjectionType GetProjectionType() const
Returns the projection type.
Basic type: Ray used for intersection testing.
static double GetReferencePlaneDepth()
Returns the depth of the reference plane.
double GetViewDistance() const
Returns the view distance.
GF_API bool GetPerspective(double *fieldOfViewHeight, double *aspectRatio, double *nearDistance, double *farDistance) const
Returns the current frustum in the format used by SetPerspective().
Basic type: 3-space rotation specification.
Basic type: arbitrarily oriented 3D bounding box.
void SetRotation(const GfRotation &rotation)
Sets the orientation of the frustum in world space as a rotation to apply to the default frame: looki...
GF_API std::vector< GfVec3d > ComputeCornersAtDistance(double d) const
Returns the world-space corners of the intersection of the frustum with a plane parallel to the near/...
GF_API GfRay ComputePickRay(const GfVec2d &windowPos) const
Builds and returns a GfRay that can be used for picking at the given normalized (-1 to +1 in both dim...