24 #ifndef PXR_BASE_GF_FRUSTUM_H 25 #define PXR_BASE_GF_FRUSTUM_H 40 #include "pxr/base/gf/api.h" 42 #include <boost/functional/hash.hpp> 49 PXR_NAMESPACE_OPEN_SCOPE
110 : _position(o._position)
111 , _rotation(o._rotation)
113 , _nearFar(o._nearFar)
114 , _viewDistance(o._viewDistance)
115 , _projectionType(o._projectionType)
117 if (
auto *planes = o._planes.load()) {
118 _planes =
new std::array<GfPlane, 6>(*planes);
124 : _position(o._position)
125 , _rotation(o._rotation)
127 , _nearFar(o._nearFar)
128 , _viewDistance(o._viewDistance)
129 , _projectionType(o._projectionType)
132 o._planes.exchange(
nullptr, std::memory_order_relaxed)) {
142 double viewDistance = 5.0);
150 double viewDistance = 5.0);
157 _position = o._position;
158 _rotation = o._rotation;
160 _nearFar = o._nearFar;
161 _viewDistance = o._viewDistance;
162 _projectionType = o._projectionType;
163 delete _planes.load(std::memory_order_relaxed);
164 if (
auto *planes = o._planes.load(std::memory_order_relaxed)) {
165 _planes.store(
new std::array<GfPlane, 6>(*planes),
166 std::memory_order_relaxed);
169 _planes.store(
nullptr, std::memory_order_relaxed);
179 _position = o._position;
180 _rotation = o._rotation;
182 _nearFar = o._nearFar;
183 _viewDistance = o._viewDistance;
184 _projectionType = o._projectionType;
185 delete _planes.load(std::memory_order_relaxed);
186 _planes.store(o._planes.load(std::memory_order_relaxed),
187 std::memory_order_relaxed);
188 o._planes.store(
nullptr, std::memory_order_relaxed);
192 friend inline size_t hash_value(
const GfFrustum &f) {
194 boost::hash_combine(h, f._position);
195 boost::hash_combine(h, f._rotation);
196 boost::hash_combine(h, f._window);
197 boost::hash_combine(h, f._nearFar);
198 boost::hash_combine(h, f._viewDistance);
199 boost::hash_combine(h, f._projectionType);
204 bool operator ==(
const GfFrustum& f)
const {
205 if (_position != f._position)
return false;
206 if (_rotation != f._rotation)
return false;
207 if (_window != f._window)
return false;
208 if (_nearFar != f._nearFar)
return false;
209 if (_viewDistance != f._viewDistance)
return false;
210 if (_projectionType != f._projectionType)
return false;
216 bool operator !=(
const GfFrustum& f)
const {
217 return !(*
this == f);
230 _position = position;
231 _DirtyFrustumPlanes();
243 _rotation = rotation;
244 _DirtyFrustumPlanes();
264 _DirtyFrustumPlanes();
280 _DirtyFrustumPlanes();
290 _viewDistance = viewDistance;
295 return _viewDistance;
300 _projectionType = projectionType;
301 _DirtyFrustumPlanes();
306 return _projectionType;
338 double nearDistance,
double farDistance);
370 double nearDistance,
double farDistance);
377 double *nearDistance,
378 double *farDistance)
const;
386 double *nearDistance,
387 double *farDistance)
const;
400 GF_API
double GetFOV(
bool isFovVertical =
false);
408 double bottom,
double top,
409 double nearPlane,
double farPlane);
415 double *bottom,
double *top,
416 double *nearPlane,
double *farPlane)
633 GF_API
void _DirtyFrustumPlanes();
636 GF_API
void _CalculateFrustumPlanes()
const;
641 GF_API
GfRay _ComputePickRayOffsetToNearPlane(
643 const GfVec3d &camSpaceDir)
const;
664 bool _SegmentIntersects(
GfVec3d const &p0, uint32_t p0Mask,
665 GfVec3d const &p1, uint32_t p1Mask)
const;
681 double _viewDistance;
688 mutable std::atomic<std::array<GfPlane, 6> *> _planes;
700 PXR_NAMESPACE_CLOSE_SCOPE
702 #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,...
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...