PhysX SDK 3.2 API Reference: PxBounds3.h Source File

PhysX SDK 3.2 API

PxBounds3.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you 
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and 
00007 // any modifications thereto. Any use, reproduction, disclosure, or 
00008 // distribution of this software and related documentation without an express 
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 // 
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2012 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  
00029 
00030 
00031 #ifndef PX_FOUNDATION_PX_BOUNDS3_H
00032 #define PX_FOUNDATION_PX_BOUNDS3_H
00033 
00038 #include "foundation/PxTransform.h"
00039 #include "foundation/PxMat33.h"
00040 
00041 #ifndef PX_DOXYGEN
00042 namespace physx
00043 {
00044 #endif
00045 
00053 class PxBounds3
00054 {
00055 public:
00056 
00061     PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3()    {}
00062 
00066     PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3(const PxVec3& minimum, const PxVec3& maximum);
00067 
00071     static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 empty();
00072 
00078     static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 boundsOfPoints(const PxVec3& v0, const PxVec3& v1);
00079 
00085     static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 centerExtents(const PxVec3& center, const PxVec3& extent);
00086 
00090     static PX_CUDA_CALLABLE PX_INLINE PxBounds3 basisExtent(const PxVec3& center, const PxMat33& basis, const PxVec3& extent);
00091 
00095     static PX_CUDA_CALLABLE PX_INLINE PxBounds3 poseExtent(const PxTransform& pose, const PxVec3& extent);
00096 
00102     static PX_CUDA_CALLABLE PX_INLINE PxBounds3 transform(const PxMat33& matrix, const PxBounds3& bounds);
00103 
00109     static PX_CUDA_CALLABLE PX_INLINE PxBounds3 transform(const PxTransform& transform, const PxBounds3& bounds);
00110 
00114     PX_CUDA_CALLABLE PX_FORCE_INLINE void setEmpty();
00115 
00119     PX_CUDA_CALLABLE PX_FORCE_INLINE void setInfinite();
00120 
00125     PX_CUDA_CALLABLE PX_FORCE_INLINE void include(const PxVec3& v);
00126 
00131     PX_CUDA_CALLABLE PX_FORCE_INLINE void include(const PxBounds3& b);
00132 
00133     PX_CUDA_CALLABLE PX_FORCE_INLINE bool isEmpty() const;
00134 
00139     PX_CUDA_CALLABLE PX_FORCE_INLINE bool intersects(const PxBounds3& b) const;
00140 
00146     PX_CUDA_CALLABLE PX_FORCE_INLINE bool intersects1D(const PxBounds3& a, PxU32 axis)  const;
00147 
00152     PX_CUDA_CALLABLE PX_FORCE_INLINE bool contains(const PxVec3& v) const;
00153 
00158     PX_CUDA_CALLABLE PX_FORCE_INLINE bool isInside(const PxBounds3& box) const;
00159 
00163     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getCenter() const;
00164 
00168     PX_CUDA_CALLABLE PX_FORCE_INLINE float  getCenter(PxU32 axis)   const;
00169 
00173     PX_CUDA_CALLABLE PX_FORCE_INLINE float  getExtents(PxU32 axis)  const;
00174 
00178     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getDimensions() const;
00179 
00183     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getExtents() const;
00184 
00189     PX_CUDA_CALLABLE PX_FORCE_INLINE void scale(PxF32 scale);
00190 
00194     PX_CUDA_CALLABLE PX_FORCE_INLINE void fatten(PxReal distance);
00195 
00200     PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite() const;
00201 
00202     PxVec3 minimum, maximum;
00203 };
00204 
00205 
00206 PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3::PxBounds3(const PxVec3& minimum, const PxVec3& maximum)
00207 : minimum(minimum), maximum(maximum)
00208 {
00209 }
00210 
00211 PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 PxBounds3::empty()
00212 {
00213     // PT: DE4900: avoid FPU exceptions when computing box extents
00214 //  return PxBounds3(PxVec3(PX_MAX_REAL), PxVec3(-PX_MAX_REAL));
00215     return PxBounds3(PxVec3(10000.0f), PxVec3(-10000.0f));
00216 }
00217 
00218 PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxBounds3::isFinite() const
00219     {
00220     return minimum.isFinite() && maximum.isFinite();
00221 }
00222 
00223 PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 PxBounds3::boundsOfPoints(const PxVec3& v0, const PxVec3& v1)
00224 {
00225     return PxBounds3(v0.minimum(v1), v0.maximum(v1));
00226 }
00227 
00228 PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 PxBounds3::centerExtents(const PxVec3& center, const PxVec3& extent)
00229 {
00230     return PxBounds3(center - extent, center + extent);
00231 }
00232 
00233 PX_CUDA_CALLABLE PX_INLINE PxBounds3 PxBounds3::basisExtent(const PxVec3& center, const PxMat33& basis, const PxVec3& extent)
00234 {
00235     // extended basis vectors
00236     PxVec3 c0 = basis.column0 * extent.x;
00237     PxVec3 c1 = basis.column1 * extent.y;
00238     PxVec3 c2 = basis.column2 * extent.z;
00239 
00240     PxVec3 w;
00241     // find combination of base vectors that produces max. distance for each component = sum of abs()
00242     w.x = PxAbs(c0.x) + PxAbs(c1.x) + PxAbs(c2.x);
00243     w.y = PxAbs(c0.y) + PxAbs(c1.y) + PxAbs(c2.y);
00244     w.z = PxAbs(c0.z) + PxAbs(c1.z) + PxAbs(c2.z);
00245 
00246     return PxBounds3(center - w, center + w);
00247 }
00248 
00249 PX_CUDA_CALLABLE PX_INLINE PxBounds3 PxBounds3::poseExtent(const PxTransform& pose, const PxVec3& extent)
00250 {
00251     return basisExtent(pose.p, PxMat33(pose.q), extent);
00252 }
00253 
00254 PX_CUDA_CALLABLE PX_FORCE_INLINE void PxBounds3::setEmpty()
00255 {
00256     // PT: DE4900: avoid FPU exceptions when computing box extents
00257 //  minimum = PxVec3(PX_MAX_REAL);
00258 //  maximum = PxVec3(-PX_MAX_REAL);
00259     minimum = PxVec3(10000.0f);
00260     maximum = PxVec3(-10000.0f);
00261 }
00262 
00263 PX_CUDA_CALLABLE PX_FORCE_INLINE void PxBounds3::setInfinite()
00264 {
00265     minimum = PxVec3(-PX_MAX_REAL);
00266     maximum = PxVec3(PX_MAX_REAL);
00267 }
00268 
00269 PX_CUDA_CALLABLE PX_FORCE_INLINE void PxBounds3::include(const PxVec3& v)
00270 {
00271     PX_ASSERT(isFinite());
00272     minimum = minimum.minimum(v);
00273     maximum = maximum.maximum(v);
00274 }
00275 
00276 PX_CUDA_CALLABLE PX_FORCE_INLINE void PxBounds3::include(const PxBounds3& b)
00277 {
00278     PX_ASSERT(isFinite());
00279     minimum = minimum.minimum(b.minimum);
00280     maximum = maximum.maximum(b.maximum);
00281 }
00282 
00283 PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxBounds3::isEmpty() const
00284 {
00285     PX_ASSERT(isFinite());
00286     // Consistency condition for (Min, Max) boxes: minimum < maximum
00287     return minimum.x > maximum.x || minimum.y > maximum.y || minimum.z > maximum.z;
00288 }
00289 
00290 PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxBounds3::intersects(const PxBounds3& b) const
00291 {
00292     PX_ASSERT(isFinite() && b.isFinite());
00293     return !(b.minimum.x > maximum.x || minimum.x > b.maximum.x ||
00294              b.minimum.y > maximum.y || minimum.y > b.maximum.y ||
00295              b.minimum.z > maximum.z || minimum.z > b.maximum.z);
00296 }
00297 
00298 PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxBounds3::intersects1D(const PxBounds3& a, PxU32 axis)   const
00299 {
00300     PX_ASSERT(isFinite() && a.isFinite());
00301     return maximum[axis] >= a.minimum[axis] && a.maximum[axis] >= minimum[axis];
00302 }
00303 
00304 PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxBounds3::contains(const PxVec3& v) const
00305 {
00306     PX_ASSERT(isFinite());
00307 
00308     return !(v.x < minimum.x || v.x > maximum.x ||
00309         v.y < minimum.y || v.y > maximum.y ||
00310         v.z < minimum.z || v.z > maximum.z);
00311 }
00312 
00313 PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxBounds3::isInside(const PxBounds3& box) const
00314 {
00315     PX_ASSERT(isFinite() && box.isFinite());
00316     if(box.minimum.x>minimum.x) return false;
00317     if(box.minimum.y>minimum.y) return false;
00318     if(box.minimum.z>minimum.z) return false;
00319     if(box.maximum.x<maximum.x) return false;
00320     if(box.maximum.y<maximum.y) return false;
00321     if(box.maximum.z<maximum.z) return false;
00322     return true;
00323 }
00324 
00325 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 PxBounds3::getCenter() const
00326 {
00327     PX_ASSERT(isFinite());
00328     return (minimum+maximum) * PxReal(0.5);
00329 }
00330 
00331 PX_CUDA_CALLABLE PX_FORCE_INLINE float  PxBounds3::getCenter(PxU32 axis)    const
00332 {
00333     PX_ASSERT(isFinite());
00334     return (minimum[axis] + maximum[axis]) * PxReal(0.5);
00335 }
00336 
00337 PX_CUDA_CALLABLE PX_FORCE_INLINE float  PxBounds3::getExtents(PxU32 axis)   const
00338 {
00339     PX_ASSERT(isFinite());
00340     return (maximum[axis] - minimum[axis]) * PxReal(0.5);
00341 }
00342 
00343 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 PxBounds3::getDimensions() const
00344 {
00345     PX_ASSERT(isFinite());
00346     return maximum - minimum;
00347 }
00348 
00349 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 PxBounds3::getExtents() const
00350 {
00351     PX_ASSERT(isFinite());
00352     return getDimensions() * PxReal(0.5);
00353 }
00354 
00355 PX_CUDA_CALLABLE PX_FORCE_INLINE void PxBounds3::scale(PxF32 scale)
00356 {
00357     PX_ASSERT(isFinite());
00358     *this = centerExtents(getCenter(), getExtents() * scale);
00359 }
00360 
00361 PX_CUDA_CALLABLE PX_FORCE_INLINE void PxBounds3::fatten(PxReal distance)
00362 {
00363     PX_ASSERT(isFinite());
00364     minimum.x -= distance;
00365     minimum.y -= distance;
00366     minimum.z -= distance;
00367 
00368     maximum.x += distance;
00369     maximum.y += distance;
00370     maximum.z += distance;
00371 }
00372 
00373 PX_CUDA_CALLABLE PX_INLINE PxBounds3 PxBounds3::transform(const PxMat33& matrix, const PxBounds3& bounds)
00374 {
00375     PX_ASSERT(bounds.isFinite());
00376     return bounds.isEmpty() ? bounds :
00377         PxBounds3::basisExtent(matrix * bounds.getCenter(), matrix, bounds.getExtents());
00378 }
00379 
00380 PX_CUDA_CALLABLE PX_INLINE PxBounds3 PxBounds3::transform(const PxTransform& transform, const PxBounds3& bounds)
00381 {
00382     PX_ASSERT(bounds.isFinite());
00383     return bounds.isEmpty() ? bounds :
00384         PxBounds3::basisExtent(transform.transform(bounds.getCenter()), PxMat33(transform.q), bounds.getExtents());
00385 }
00386 
00387 #ifndef PX_DOXYGEN
00388 } // namespace physx
00389 #endif
00390 
00392 #endif // PX_FOUNDATION_PX_BOUNDS3_H


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