24 #ifndef PXR_BASE_GF_FRUSTUM_H
25 #define PXR_BASE_GF_FRUSTUM_H
42 #include <hboost/functional/hash.hpp>
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);
194 hboost::hash_combine(h, f._position);
195 hboost::hash_combine(h, f._rotation);
196 hboost::hash_combine(h, f._window);
197 hboost::hash_combine(h, f._nearFar);
198 hboost::hash_combine(h, f._viewDistance);
199 hboost::hash_combine(h, f._projectionType);
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;
217 return !(*
this ==
f);
230 _position = position;
231 _DirtyFrustumPlanes();
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;
409 double nearPlane,
double farPlane);
416 double *nearPlane,
double *farPlane)
530 const GfVec2d &halfSize)
const;
546 const GfVec2d &halfSize)
const;
624 GF_API void _DirtyFrustumPlanes();
627 GF_API void _CalculateFrustumPlanes()
const;
634 const GfVec3d &camSpaceDir)
const;
650 const GfVec2d &halfSize)
const;
652 bool _SegmentIntersects(
GfVec3d const &p0, uint32_t p0Mask,
653 GfVec3d const &p1, uint32_t p1Mask)
const;
669 double _viewDistance;
676 mutable std::atomic<std::array<GfPlane, 6> *> _planes;
690 #endif // PXR_BASE_GF_FRUSTUM_H
GLfloat GLfloat GLfloat top
bool operator==(const GfFrustum &f) const
void SetRotation(const GfRotation &rotation)
GfFrustum(GfFrustum const &o)
Copy constructor.
void SetViewDistance(double viewDistance)
Sets the view distance.
friend size_t hash_value(const GfFrustum &f)
GfFrustum & operator=(GfFrustum const &o) noexcept
Copy assignment.
static double GetReferencePlaneDepth()
Returns the depth of the reference plane.
GF_API std::vector< GfVec3d > ComputeCorners() const
GF_API std::ostream & operator<<(std::ostream &out, const GfFrustum &f)
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
GF_API double ComputeAspectRatio() const
GF_API GfFrustum & Transform(const GfMatrix4d &matrix)
GF_API GfRay ComputePickRay(const GfVec2d &windowPos) const
GF_API void FitToSphere(const GfVec3d ¢er, double radius, double slack=0.0)
GF_API GfFrustum ComputeNarrowedFrustum(const GfVec2d &point, const GfVec2d &halfSize) const
const GfVec3d & GetPosition() const
Returns the position of the frustum in world space.
GF_API void SetPositionAndRotationFromMatrix(const GfMatrix4d &camToWorldXf)
GF_API GfVec3d ComputeLookAtPoint() const
GfFrustum(GfFrustum &&o) noexcept
Move constructor.
const GfRange1d & GetNearFar() const
Returns the near/far interval.
GF_API GfMatrix4d ComputeViewMatrix() const
GF_API GfMatrix4d ComputeViewInverse() const
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)
GfFrustum::ProjectionType GetProjectionType() const
Returns the projection type.
static GF_API bool IntersectsViewVolume(const GfBBox3d &bbox, const GfMatrix4d &vpMat)
double GetViewDistance() const
Returns the view distance.
GF_API bool GetPerspective(double *fieldOfViewHeight, double *aspectRatio, double *nearDistance, double *farDistance) const
bool operator!=(const GfFrustum &f) const
GF_API std::vector< GfVec3d > ComputeCornersAtDistance(double d) const
const GfRange2d & GetWindow() const
Returns the window rectangle in the reference plane.
const GfRotation & GetRotation() const
void SetProjectionType(GfFrustum::ProjectionType projectionType)
Sets the projection type.
GLfloat GLfloat GLfloat GLfloat h
GF_API GfRay ComputeRay(const GfVec2d &windowPos) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
GA_API const UT_StringHolder up
#define PXR_NAMESPACE_CLOSE_SCOPE
GF_API ~GfFrustum()
Destructor.
GF_API void SetPerspective(double fieldOfViewHeight, double aspectRatio, double nearDistance, double farDistance)
GF_API double GetFOV(bool isFovVertical=false)
void SetNearFar(const GfRange1d &nearFar)
Sets the near/far interval.
GF_API GfVec3d ComputeUpVector() const
GfFrustum & operator=(GfFrustum &&o) noexcept
Move assignment.
void SetPosition(const GfVec3d &position)
Sets the position of the frustum in world space.
GF_API void ComputeViewFrame(GfVec3d *side, GfVec3d *up, GfVec3d *view) const
MatType rotation(const Quat< typename MatType::value_type > &q, typename MatType::value_type eps=static_cast< typename MatType::value_type >(1.0e-8))
Return the rotation matrix specified by the given quaternion.