RavEngine
Loading...
Searching...
No Matches
GuBox.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_BOX_H
30#define GU_BOX_H
31
36#include "foundation/PxTransform.h"
37#include "foundation/PxMat33.h"
38#include "common/PxPhysXCommonConfig.h"
39
40namespace physx
41{
42namespace Gu
43{
44 class Capsule;
45
46 PX_PHYSX_COMMON_API void computeOBBPoints(PxVec3* PX_RESTRICT pts, const PxVec3& center, const PxVec3& extents, const PxVec3& base0, const PxVec3& base1, const PxVec3& base2);
47
48
67#if PX_VC
68 #pragma warning(push)
69 #pragma warning( disable : 4251 ) // class needs to have dll-interface to be used by clients of class
70#endif
71 class PX_PHYSX_COMMON_API Box
72 {
73 public:
78 {
79 }
80
89 PX_FORCE_INLINE Box(const PxVec3& origin, const PxVec3& extent, const PxMat33& base) : rot(base), center(origin), extents(extent)
90 {}
91
93 PX_FORCE_INLINE Box(const Box& other) : rot(other.rot), center(other.center), extents(other.extents)
94 {}
95
100 {
101 }
102
104 PX_FORCE_INLINE const Box& operator=(const Box& other)
105 {
106 rot = other.rot;
107 center = other.center;
108 extents = other.extents;
109 return *this;
110 }
111
116 {
117 center = PxVec3(0);
118 extents = PxVec3(-PX_MAX_REAL, -PX_MAX_REAL, -PX_MAX_REAL);
119 rot = PxMat33(PxIdentity);
120 }
121
127 PX_INLINE bool isValid() const
128 {
129 // Consistency condition for (Center, Extents) boxes: Extents >= 0.0f
130 if(extents.x < 0.0f) return false;
131 if(extents.y < 0.0f) return false;
132 if(extents.z < 0.0f) return false;
133 return true;
134 }
135
137 PX_FORCE_INLINE void setAxes(const PxVec3& axis0, const PxVec3& axis1, const PxVec3& axis2)
138 {
139 rot.column0 = axis0;
140 rot.column1 = axis1;
141 rot.column2 = axis2;
142 }
143
144 PX_FORCE_INLINE PxVec3 rotate(const PxVec3& src) const
145 {
146 return rot * src;
147 }
148
149 PX_FORCE_INLINE PxVec3 rotateInv(const PxVec3& src) const
150 {
151 return rot.transformTranspose(src);
152 }
153
154 PX_FORCE_INLINE PxVec3 transform(const PxVec3& src) const
155 {
156 return rot * src + center;
157 }
158
159 PX_FORCE_INLINE PxTransform getTransform() const
160 {
161 return PxTransform(center, PxQuat(rot));
162 }
163
164 PX_INLINE PxVec3 computeAABBExtent() const
165 {
166 const PxReal a00 = PxAbs(rot[0][0]);
167 const PxReal a01 = PxAbs(rot[0][1]);
168 const PxReal a02 = PxAbs(rot[0][2]);
169
170 const PxReal a10 = PxAbs(rot[1][0]);
171 const PxReal a11 = PxAbs(rot[1][1]);
172 const PxReal a12 = PxAbs(rot[1][2]);
173
174 const PxReal a20 = PxAbs(rot[2][0]);
175 const PxReal a21 = PxAbs(rot[2][1]);
176 const PxReal a22 = PxAbs(rot[2][2]);
177
178 const PxReal ex = extents.x;
179 const PxReal ey = extents.y;
180 const PxReal ez = extents.z;
181
182 return PxVec3( a00 * ex + a10 * ey + a20 * ez,
183 a01 * ex + a11 * ey + a21 * ez,
184 a02 * ex + a12 * ey + a22 * ez);
185 }
186
192 {
193 Gu::computeOBBPoints(pts, center, extents, rot.column0, rot.column1, rot.column2);
194 }
195
196 void create(const Gu::Capsule& capsule);
197
198 PxMat33 rot;
199 PxVec3 center;
200 PxVec3 extents;
201 };
202 PX_COMPILE_TIME_ASSERT(sizeof(Gu::Box) == 60);
203
205 class BoxPadded : public Box
206 {
207 public:
210 PxU32 padding;
211 };
213
214#if PX_VC
215 #pragma warning(pop)
216#endif
217
218}
219
220}
221
223#endif
A padded version of Gu::Box, to safely load its data using SIMD.
Definition GuBox.h:206
Represents an oriented bounding box.
Definition GuBox.h:72
PX_INLINE bool isValid() const
Checks the box is valid.
Definition GuBox.h:127
PX_FORCE_INLINE ~Box()
Destructor.
Definition GuBox.h:99
PX_FORCE_INLINE Box(const PxVec3 &origin, const PxVec3 &extent, const PxMat33 &base)
Constructor.
Definition GuBox.h:89
PX_FORCE_INLINE Box()
Constructor.
Definition GuBox.h:77
PX_FORCE_INLINE void computeBoxPoints(PxVec3 *PX_RESTRICT pts) const
Definition GuBox.h:191
PX_INLINE void setEmpty()
Setups an empty box.
Definition GuBox.h:115
PX_FORCE_INLINE Box(const Box &other)
Copy constructor.
Definition GuBox.h:93
PX_FORCE_INLINE const Box & operator=(const Box &other)
Assignment operator.
Definition GuBox.h:104
Represents a capsule.
Definition GuCapsule.h:47
3x3 matrix class
Definition PxMat33.h:91
3 Element vector class.
Definition PxVec3.h:50
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
#define PX_INLINE
Definition PxPreprocessor.h:320
transform(pattern)
Definition docopt.py:72
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxAbs(float a)
abs returns the absolute value of its argument.
Definition PxMath.h:109