PxBounds3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3  *
4  * NVIDIA CORPORATION and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA CORPORATION is strictly prohibited.
9  */
10 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12 
13 
14 #ifndef PX_FOUNDATION_PX_BOUNDS3_H
15 #define PX_FOUNDATION_PX_BOUNDS3_H
16 
21 #include "foundation/PxTransform.h"
22 #include "foundation/PxMat33.h"
23 
24 #ifndef PX_DOXYGEN
25 namespace physx
26 {
27 #endif
28 
29 // maximum extents defined such that floating point exceptions are avoided for standard use cases
30 #define PX_MAX_BOUNDS_EXTENTS (PX_MAX_REAL * 0.25f)
31 
41 class PxBounds3
42 {
43 public:
44 
50 
54  PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3(const PxVec3& minimum, const PxVec3& maximum);
55 
60 
66  static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 boundsOfPoints(const PxVec3& v0, const PxVec3& v1);
67 
73  static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 centerExtents(const PxVec3& center, const PxVec3& extent);
74 
78  static PX_CUDA_CALLABLE PX_INLINE PxBounds3 basisExtent(const PxVec3& center, const PxMat33& basis, const PxVec3& extent);
79 
83  static PX_CUDA_CALLABLE PX_INLINE PxBounds3 poseExtent(const PxTransform& pose, const PxVec3& extent);
84 
93  static PX_CUDA_CALLABLE PX_INLINE PxBounds3 transformSafe(const PxMat33& matrix, const PxBounds3& bounds);
94 
103  static PX_CUDA_CALLABLE PX_INLINE PxBounds3 transformFast(const PxMat33& matrix, const PxBounds3& bounds);
104 
113  static PX_CUDA_CALLABLE PX_INLINE PxBounds3 transformSafe(const PxTransform& transform, const PxBounds3& bounds);
114 
123  static PX_CUDA_CALLABLE PX_INLINE PxBounds3 transformFast(const PxTransform& transform, const PxBounds3& bounds);
124 
128  PX_CUDA_CALLABLE PX_FORCE_INLINE void setEmpty();
129 
133  PX_CUDA_CALLABLE PX_FORCE_INLINE void setMaximal();
134 
139  PX_CUDA_CALLABLE PX_FORCE_INLINE void include(const PxVec3& v);
140 
145  PX_CUDA_CALLABLE PX_FORCE_INLINE void include(const PxBounds3& b);
146 
147  PX_CUDA_CALLABLE PX_FORCE_INLINE bool isEmpty() const;
148 
153  PX_CUDA_CALLABLE PX_FORCE_INLINE bool intersects(const PxBounds3& b) const;
154 
160  PX_CUDA_CALLABLE PX_FORCE_INLINE bool intersects1D(const PxBounds3& a, PxU32 axis) const;
161 
166  PX_CUDA_CALLABLE PX_FORCE_INLINE bool contains(const PxVec3& v) const;
167 
172  PX_CUDA_CALLABLE PX_FORCE_INLINE bool isInside(const PxBounds3& box) const;
173 
177  PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getCenter() const;
178 
182  PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getCenter(PxU32 axis) const;
183 
187  PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal getExtents(PxU32 axis) const;
188 
192  PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getDimensions() const;
193 
197  PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getExtents() const;
198 
206  PX_CUDA_CALLABLE PX_FORCE_INLINE void scaleSafe(PxF32 scale);
207 
215  PX_CUDA_CALLABLE PX_FORCE_INLINE void scaleFast(PxF32 scale);
216 
222  PX_CUDA_CALLABLE PX_FORCE_INLINE void fattenSafe(PxReal distance);
223 
229  PX_CUDA_CALLABLE PX_FORCE_INLINE void fattenFast(PxReal distance);
230 
234  PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite() const;
235 
239  PX_CUDA_CALLABLE PX_FORCE_INLINE bool isValid() const;
240 
241  PxVec3 minimum, maximum;
242 };
243 
244 
246 : minimum(minimum_), maximum(maximum_)
247 {
248 }
249 
251 {
253 }
254 
256 {
257  return minimum.isFinite() && maximum.isFinite();
258 }
259 
261 {
262  return PxBounds3(v0.minimum(v1), v0.maximum(v1));
263 }
264 
266 {
267  return PxBounds3(center - extent, center + extent);
268 }
269 
271 {
272  // extended basis vectors
273  PxVec3 c0 = basis.column0 * extent.x;
274  PxVec3 c1 = basis.column1 * extent.y;
275  PxVec3 c2 = basis.column2 * extent.z;
276 
277  PxVec3 w;
278  // find combination of base vectors that produces max. distance for each component = sum of abs()
279  w.x = PxAbs(c0.x) + PxAbs(c1.x) + PxAbs(c2.x);
280  w.y = PxAbs(c0.y) + PxAbs(c1.y) + PxAbs(c2.y);
281  w.z = PxAbs(c0.z) + PxAbs(c1.z) + PxAbs(c2.z);
282 
283  return PxBounds3(center - w, center + w);
284 }
285 
287 {
288  return basisExtent(pose.p, PxMat33(pose.q), extent);
289 }
290 
292 {
295 }
296 
298 {
301 }
302 
304 {
305  PX_ASSERT(isValid());
306  minimum = minimum.minimum(v);
307  maximum = maximum.maximum(v);
308 }
309 
311 {
312  PX_ASSERT(isValid());
315 }
316 
318 {
319  PX_ASSERT(isValid());
320  return minimum.x > maximum.x;
321 }
322 
324 {
325  PX_ASSERT(isValid() && b.isValid());
326  return !(b.minimum.x > maximum.x || minimum.x > b.maximum.x ||
327  b.minimum.y > maximum.y || minimum.y > b.maximum.y ||
328  b.minimum.z > maximum.z || minimum.z > b.maximum.z);
329 }
330 
332 {
333  PX_ASSERT(isValid() && a.isValid());
334  return maximum[axis] >= a.minimum[axis] && a.maximum[axis] >= minimum[axis];
335 }
336 
338 {
339  PX_ASSERT(isValid());
340 
341  return !(v.x < minimum.x || v.x > maximum.x ||
342  v.y < minimum.y || v.y > maximum.y ||
343  v.z < minimum.z || v.z > maximum.z);
344 }
345 
347 {
348  PX_ASSERT(isValid() && box.isValid());
349  if(box.minimum.x>minimum.x) return false;
350  if(box.minimum.y>minimum.y) return false;
351  if(box.minimum.z>minimum.z) return false;
352  if(box.maximum.x<maximum.x) return false;
353  if(box.maximum.y<maximum.y) return false;
354  if(box.maximum.z<maximum.z) return false;
355  return true;
356 }
357 
359 {
360  PX_ASSERT(isValid());
361  return (minimum+maximum) * 0.5f;
362 }
363 
365 {
366  PX_ASSERT(isValid());
367  return (minimum[axis] + maximum[axis]) * 0.5f;
368 }
369 
371 {
372  PX_ASSERT(isValid());
373  return (maximum[axis] - minimum[axis]) * 0.5f;
374 }
375 
377 {
378  PX_ASSERT(isValid());
379  return maximum - minimum;
380 }
381 
383 {
384  PX_ASSERT(isValid());
385  return getDimensions() * 0.5f;
386 }
387 
389 {
390  PX_ASSERT(isValid());
391  if (!isEmpty())
392  scaleFast(scale);
393 }
394 
396 {
397  PX_ASSERT(isValid());
398  *this = centerExtents(getCenter(), getExtents() * scale);
399 }
400 
402 {
403  PX_ASSERT(isValid());
404  if (!isEmpty())
405  fattenFast(distance);
406 }
407 
409 {
410  PX_ASSERT(isValid());
411  minimum.x -= distance;
412  minimum.y -= distance;
413  minimum.z -= distance;
414 
415  maximum.x += distance;
416  maximum.y += distance;
417  maximum.z += distance;
418 }
419 
421 {
422  PX_ASSERT(bounds.isValid());
423  return !bounds.isEmpty() ? transformFast(matrix, bounds) : bounds;
424 }
425 
427 {
428  PX_ASSERT(bounds.isValid());
429  return PxBounds3::basisExtent(matrix * bounds.getCenter(), matrix, bounds.getExtents());
430 }
431 
433 {
434  PX_ASSERT(bounds.isValid());
435  return !bounds.isEmpty() ? transformFast(transform, bounds) : bounds;
436 }
437 
439 {
440  PX_ASSERT(bounds.isValid());
441  return PxBounds3::basisExtent(transform.transform(bounds.getCenter()), PxMat33(transform.q), bounds.getExtents());
442 }
443 
445 {
446  return (isFinite() &&
447  (((minimum.x <= maximum.x) && (minimum.y <= maximum.y) && (minimum.z <= maximum.z)) ||
450  );
451 }
452 
453 #ifndef PX_DOXYGEN
454 } // namespace physx
455 #endif
456 
458 #endif // PX_FOUNDATION_PX_BOUNDS3_H


Copyright © 2008-2015 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com