7#ifndef PXR_BASE_GF_FRUSTUM_H
8#define PXR_BASE_GF_FRUSTUM_H
23#include "pxr/base/gf/api.h"
31PXR_NAMESPACE_OPEN_SCOPE
92 : _position(o._position)
93 , _rotation(o._rotation)
95 , _nearFar(o._nearFar)
96 , _viewDistance(o._viewDistance)
97 , _projectionType(o._projectionType)
99 if (
auto *planes = o._planes.load()) {
100 _planes =
new std::array<GfPlane, 6>(*planes);
106 : _position(o._position)
107 , _rotation(o._rotation)
109 , _nearFar(o._nearFar)
110 , _viewDistance(o._viewDistance)
111 , _projectionType(o._projectionType)
114 o._planes.exchange(
nullptr, std::memory_order_relaxed)) {
124 double viewDistance = 5.0);
132 double viewDistance = 5.0);
139 _position = o._position;
140 _rotation = o._rotation;
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);
151 _planes.store(
nullptr, std::memory_order_relaxed);
161 _position = o._position;
162 _rotation = o._rotation;
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);
174 friend inline size_t hash_value(
const GfFrustum &f) {
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;
198 bool operator !=(
const GfFrustum& f)
const {
199 return !(*
this == f);
212 _position = position;
213 _DirtyFrustumPlanes();
225 _rotation = rotation;
226 _DirtyFrustumPlanes();
246 _DirtyFrustumPlanes();
262 _DirtyFrustumPlanes();
272 _viewDistance = viewDistance;
277 return _viewDistance;
282 _projectionType = projectionType;
283 _DirtyFrustumPlanes();
288 return _projectionType;
320 double nearDistance,
double farDistance);
352 double nearDistance,
double farDistance);
359 double *nearDistance,
360 double *farDistance)
const;
368 double *nearDistance,
369 double *farDistance)
const;
382 GF_API
double GetFOV(
bool isFovVertical =
false)
const;
390 double bottom,
double top,
391 double nearPlane,
double farPlane);
397 double *bottom,
double *top,
398 double *nearPlane,
double *farPlane)
615 GF_API
void _DirtyFrustumPlanes();
618 GF_API
void _CalculateFrustumPlanes()
const;
623 GF_API
GfRay _ComputePickRayOffsetToNearPlane(
625 const GfVec3d &camSpaceDir)
const;
646 bool _SegmentIntersects(
GfVec3d const &p0, uint32_t p0Mask,
647 GfVec3d const &p1, uint32_t p1Mask)
const;
663 double _viewDistance;
670 mutable std::atomic<std::array<GfPlane, 6> *> _planes;
682PXR_NAMESPACE_CLOSE_SCOPE
Basic type: arbitrarily oriented 3D bounding box.
Basic type: View frustum.
GF_API GfRay ComputeRay(const GfVec3d &worldSpacePos) const
Builds and returns a GfRay that connects the viewpoint to the given 3d point in worldspace.
static double GetReferencePlaneDepth()
Returns the depth of the reference plane.
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 double ComputeAspectRatio() const
Returns the aspect ratio of the frustum, defined as the width of the window divided by the height.
GfFrustum & operator=(GfFrustum &&o) noexcept
Move assignment.
GF_API void SetPerspective(double fieldOfView, bool isFovVertical, double aspectRatio, double nearDistance, double farDistance)
Sets up the frustum in a manner similar to gluPerspective().
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...
void SetViewDistance(double viewDistance)
Sets the view distance.
GfFrustum & operator=(GfFrustum const &o) noexcept
Copy assignment.
void SetNearFar(const GfRange1d &nearFar)
Sets the near/far interval.
const GfRange2d & GetWindow() const
Returns the window rectangle in the reference plane.
GF_API GfFrustum ComputeNarrowedFrustum(const GfVec3d &worldPoint, const GfVec2d &size) const
Returns a frustum that is a narrowed-down version of this frustum.
GF_API ~GfFrustum()
Destructor.
GF_API void SetPerspective(double fieldOfViewHeight, double aspectRatio, double nearDistance, double farDistance)
Sets up the frustum in a manner similar to gluPerspective().
const GfRange1d & GetNearFar() const
Returns the near/far interval.
GF_API GfFrustum()
This constructor creates an instance with default viewing parameters:
GF_API bool Intersects(const GfVec3d &point) const
Returns true if the given point is inside or intersecting the frustum.
void SetProjectionType(GfFrustum::ProjectionType projectionType)
Sets the projection type.
GF_API double GetFOV(bool isFovVertical=false) const
Returns the horizontal or vertical fov of the frustum.
double GetViewDistance() const
Returns the view distance.
GfFrustum::ProjectionType GetProjectionType() const
Returns the projection type.
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 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 bool Intersects(const GfBBox3d &bbox) const
Returns true if the given axis-aligned bbox is inside or intersecting the frustum.
void SetPosition(const GfVec3d &position)
Sets the position of the frustum in world space.
GF_API bool GetPerspective(bool isFovVertical, double *fieldOfView, double *aspectRatio, double *nearDistance, double *farDistance) const
Returns the current frustum in the format used by SetPerspective().
GF_API GfVec3d ComputeUpVector() const
Returns the normalized world-space up vector, which is computed by rotating the y axis by the frustum...
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,...
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 GfFrustum(const GfMatrix4d &camToWorldXf, const GfRange2d &window, const GfRange1d &nearFar, GfFrustum::ProjectionType projectionType, double viewDistance=5.0)
This constructor creates an instance from a camera matrix (always of a y-Up camera,...
GfFrustum(GfFrustum const &o)
Copy constructor.
GF_API bool Intersects(const GfVec3d &p0, const GfVec3d &p1) const
Returns true if the line segment formed by the given points is inside or intersecting the frustum.
GF_API GfRay ComputePickRay(const GfVec3d &worldSpacePos) const
Builds and returns a GfRay that can be used for picking that connects the viewpoint to the given 3d p...
GF_API std::vector< GfVec3d > ComputeCorners() const
Returns the world-space corners of the frustum as a vector of 8 points, ordered as:
const GfRotation & GetRotation() const
Returns the orientation of the frustum in world space as a rotation to apply to the -z axis.
GF_API GfMatrix4d ComputeViewMatrix() const
Returns a matrix that represents the viewing transformation for this frustum.
GF_API bool GetPerspective(double *fieldOfViewHeight, double *aspectRatio, double *nearDistance, double *farDistance) const
Returns the current frustum in the format used by SetPerspective().
GF_API GfVec3d ComputeViewDirection() const
Returns the normalized world-space view direction vector, which is computed by rotating the -z axis b...
GF_API bool Intersects(const GfVec3d &p0, const GfVec3d &p1, const GfVec3d &p2) const
Returns true if the triangle formed by the given points is inside or intersecting the frustum.
GF_API GfMatrix4d ComputeProjectionMatrix() const
Returns a GL-style projection matrix corresponding to the frustum's projection.
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).
void SetWindow(const GfRange2d &window)
Sets the window rectangle in the reference plane that defines the left, right, top,...
GfFrustum(GfFrustum &&o) noexcept
Move constructor.
GF_API GfVec3d ComputeLookAtPoint() const
Computes and returns the world-space look-at point from the eye point (position), view direction (rot...
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 GfFrustum(const GfVec3d &position, const GfRotation &rotation, const GfRange2d &window, const GfRange1d &nearFar, GfFrustum::ProjectionType projectionType, double viewDistance=5.0)
This constructor creates an instance with the given viewing parameters.
GF_API void ComputeViewFrame(GfVec3d *side, GfVec3d *up, GfVec3d *view) const
Computes the view frame defined by this frustum.
GF_API GfFrustum & Transform(const GfMatrix4d &matrix)
Transforms the frustum by the given matrix.
GF_API GfMatrix4d ComputeViewInverse() const
Returns a matrix that represents the inverse viewing transformation for this frustum.
ProjectionType
This enum is used to determine the type of projection represented by a frustum.
@ Orthographic
Orthographic projection.
@ Perspective
Perspective projection.
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...
const GfVec3d & GetPosition() const
Returns the position of the frustum in world space.
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,...
Stores a 4x4 matrix of double elements.
Basic type: 1-dimensional floating point range.
Basic type: 2-dimensional floating point range.
Basic type: Ray used for intersection testing.
Basic type: 3-space rotation specification.
Basic type for a vector of 2 double components.
Basic type for a vector of 3 double components.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].