RavEngine
Loading...
Searching...
No Matches
GuCenterExtents.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef GU_CENTER_EXTENTS_H
30#define GU_CENTER_EXTENTS_H
31
36#include "foundation/PxUserAllocated.h"
37#include "foundation/PxBounds3.h"
38
39namespace physx
40{
41namespace Gu
42{
44 {
45 public:
47 PX_FORCE_INLINE CenterExtents(const PxBounds3& b) { mCenter = b.getCenter(); mExtents = b.getExtents(); }
49
50 PX_FORCE_INLINE void getMin(PxVec3& min) const { min = mCenter - mExtents; }
51 PX_FORCE_INLINE void getMax(PxVec3& max) const { max = mCenter + mExtents; }
52
53 PX_FORCE_INLINE float getMin(PxU32 axis) const { return mCenter[axis] - mExtents[axis]; }
54 PX_FORCE_INLINE float getMax(PxU32 axis) const { return mCenter[axis] + mExtents[axis]; }
55
56 PX_FORCE_INLINE PxVec3 getMin() const { return mCenter - mExtents; }
57 PX_FORCE_INLINE PxVec3 getMax() const { return mCenter + mExtents; }
58
59 PX_FORCE_INLINE void setMinMax(const PxVec3& min, const PxVec3& max)
60 {
61 mCenter = (max + min)*0.5f;
62 mExtents = (max - min)*0.5f;
63 }
64
65 PX_FORCE_INLINE PxU32 isInside(const CenterExtents& box) const
66 {
67 if(box.getMin(0)>getMin(0)) return 0;
68 if(box.getMin(1)>getMin(1)) return 0;
69 if(box.getMin(2)>getMin(2)) return 0;
70 if(box.getMax(0)<getMax(0)) return 0;
71 if(box.getMax(1)<getMax(1)) return 0;
72 if(box.getMax(2)<getMax(2)) return 0;
73 return 1;
74 }
75
76 PX_FORCE_INLINE void setEmpty()
77 {
78 mExtents = PxVec3(-PX_MAX_BOUNDS_EXTENTS);
79 }
80
81 PX_FORCE_INLINE bool isEmpty() const
82 {
83 PX_ASSERT(isValid());
84 return mExtents.x<0.0f;
85 }
86
87 PX_FORCE_INLINE bool isFinite() const
88 {
89 return mCenter.isFinite() && mExtents.isFinite();
90 }
91
92 PX_FORCE_INLINE bool isValid() const
93 {
94 const PxVec3& c = mCenter;
95 const PxVec3& e = mExtents;
96 return (c.isFinite() && e.isFinite() && (((e.x >= 0.0f) && (e.y >= 0.0f) && (e.z >= 0.0f)) ||
97 ((e.x == -PX_MAX_BOUNDS_EXTENTS) &&
98 (e.y == -PX_MAX_BOUNDS_EXTENTS) &&
99 (e.z == -PX_MAX_BOUNDS_EXTENTS))));
100 }
101
102 PX_FORCE_INLINE PxBounds3 transformFast(const PxMat33& matrix) const
103 {
104 PX_ASSERT(isValid());
105 return PxBounds3::basisExtent(matrix * mCenter, matrix, mExtents);
106 }
107
108 PxVec3 mCenter;
109 PxVec3 mExtents;
110 };
111
114 {
115 public:
118 PxU32 padding;
119 };
121
122}
123
124}
125
127#endif
A padded version of CenterExtents, to safely load its data using SIMD.
Definition GuCenterExtents.h:114
Definition GuCenterExtents.h:44
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
static PX_CUDA_CALLABLE PX_INLINE PxBounds3 basisExtent(const PxVec3 &center, const PxMat33 &basis, const PxVec3 &extent)
Construct from center, extent, and (not necessarily orthogonal) basis.
Definition PxBounds3.h:305
3x3 matrix class
Definition PxMat33.h:91
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
returns true if all 3 elems of the vector are finite (not NAN or INF, etc.)
Definition PxVec3.h:156
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39