PhysX SDK 3.2 API Reference: PxExtended.h Source File

PhysX SDK 3.2 API

PxExtended.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_PHYSICS_CCT_EXTENDED
00032 #define PX_PHYSICS_CCT_EXTENDED
00033 
00037 // This needs to be included in Foundation just for the debug renderer
00038 
00039 #include "PxPhysX.h"
00040 #include "foundation/PxTransform.h"
00041 
00042 #ifndef PX_DOXYGEN
00043 namespace physx
00044 {
00045 #endif
00046 
00047 // This has to be done here since it also changes the top-level "Nx" API (as well as "Nv" and "Np" ones)
00048 #define PX_BIG_WORLDS
00049 
00050 #ifdef PX_BIG_WORLDS
00051 typedef double  PxExtended;
00052 #define PX_MAX_EXTENDED PX_MAX_F64
00053 #define PxExtendedAbs(x)    fabs(x)
00054 
00055 struct PxExtendedVec3
00056 {
00057     PX_INLINE   PxExtendedVec3()                                                                    {}
00058     PX_INLINE   PxExtendedVec3(PxExtended _x, PxExtended _y, PxExtended _z) : x(_x), y(_y), z(_z)   {}
00059 
00060     PX_INLINE   bool isZero()   const
00061     {
00062         if(x!=0.0 || y!=0.0 || z!=0.0)  return false;
00063         return true;
00064     }
00065 
00066     PX_INLINE PxExtended    dot(const PxVec3& v) const
00067     {
00068         return x * v.x + y * v.y + z * v.z;
00069     }
00070 
00071     PX_INLINE   PxExtended distanceSquared(const PxExtendedVec3& v) const
00072     {
00073         PxExtended dx = x - v.x;
00074         PxExtended dy = y - v.y;
00075         PxExtended dz = z - v.z;
00076         return dx * dx + dy * dy + dz * dz;
00077     }
00078 
00079     PX_INLINE PxExtended magnitudeSquared() const
00080     {
00081         return x * x + y * y + z * z;
00082     }
00083 
00084     PX_INLINE PxExtended magnitude() const
00085     {
00086         return PxSqrt(x * x + y * y + z * z);
00087     }
00088 
00089     PX_INLINE   PxExtended  normalize()
00090     {
00091         PxExtended m = magnitude();
00092         if (m)
00093         {
00094             const PxExtended il =  PxExtended(1.0) / m;
00095             x *= il;
00096             y *= il;
00097             z *= il;
00098         }
00099         return m;
00100     }
00101 
00102     PX_INLINE   bool isFinite() const
00103     {
00104         return PxIsFinite(x) && PxIsFinite(y) && PxIsFinite(z);
00105     }
00106 
00107     PX_INLINE   void maximum(const PxExtendedVec3& v)
00108     {
00109         if (x < v.x) x = v.x;
00110         if (y < v.y) y = v.y;
00111         if (z < v.z) z = v.z;
00112     }
00113 
00114 
00115     PX_INLINE   void minimum(const PxExtendedVec3& v)
00116     {
00117         if (x > v.x) x = v.x;
00118         if (y > v.y) y = v.y;
00119         if (z > v.z) z = v.z;
00120     }
00121 
00122     PX_INLINE   void    set(PxExtended x, PxExtended y, PxExtended z)
00123     {
00124         this->x = x;
00125         this->y = y;
00126         this->z = z;
00127     }
00128 
00129     PX_INLINE void  setPlusInfinity()
00130     {
00131         x = y = z = PX_MAX_EXTENDED;
00132     }
00133 
00134     PX_INLINE void  setMinusInfinity()
00135     {
00136         x = y = z = -PX_MAX_EXTENDED;
00137     }
00138 
00139     PX_INLINE void  cross(const PxExtendedVec3& left, const PxVec3& right)
00140     {
00141         // temps needed in case left or right is this.
00142         PxExtended a = (left.y * right.z) - (left.z * right.y);
00143         PxExtended b = (left.z * right.x) - (left.x * right.z);
00144         PxExtended c = (left.x * right.y) - (left.y * right.x);
00145 
00146         x = a;
00147         y = b;
00148         z = c;
00149     }
00150 
00151     PX_INLINE void  cross(const PxExtendedVec3& left, const PxExtendedVec3& right)
00152     {
00153         // temps needed in case left or right is this.
00154         PxExtended a = (left.y * right.z) - (left.z * right.y);
00155         PxExtended b = (left.z * right.x) - (left.x * right.z);
00156         PxExtended c = (left.x * right.y) - (left.y * right.x);
00157 
00158         x = a;
00159         y = b;
00160         z = c;
00161     }
00162 
00163     PX_INLINE PxExtendedVec3 cross(const PxExtendedVec3& v) const
00164     {
00165         PxExtendedVec3 temp;
00166         temp.cross(*this,v);
00167         return temp;
00168     }
00169 
00170     PX_INLINE void  cross(const PxVec3& left, const PxExtendedVec3& right)
00171     {
00172         // temps needed in case left or right is this.
00173         PxExtended a = (left.y * right.z) - (left.z * right.y);
00174         PxExtended b = (left.z * right.x) - (left.x * right.z);
00175         PxExtended c = (left.x * right.y) - (left.y * right.x);
00176 
00177         x = a;
00178         y = b;
00179         z = c;
00180     }
00181 
00182     PX_INLINE   PxExtendedVec3      operator-()     const
00183     {
00184         return PxExtendedVec3(-x, -y, -z);
00185     }
00186 
00187     PX_INLINE   PxExtendedVec3&     operator+=(const PxExtendedVec3& v)
00188     {
00189         x += v.x;
00190         y += v.y;
00191         z += v.z;
00192         return *this;
00193     }
00194 
00195     PX_INLINE   PxExtendedVec3&     operator-=(const PxExtendedVec3& v)
00196     {
00197         x -= v.x;
00198         y -= v.y;
00199         z -= v.z;
00200         return *this;
00201     }
00202 
00203     PX_INLINE   PxExtendedVec3&     operator+=(const PxVec3& v)
00204     {
00205         x += PxExtended(v.x);
00206         y += PxExtended(v.y);
00207         z += PxExtended(v.z);
00208         return *this;
00209     }
00210 
00211     PX_INLINE   PxExtendedVec3&     operator-=(const PxVec3& v)
00212     {
00213         x -= PxExtended(v.x);
00214         y -= PxExtended(v.y);
00215         z -= PxExtended(v.z);
00216         return *this;
00217     }
00218 
00219     PX_INLINE   PxExtendedVec3&     operator*=(const PxReal& s)
00220     {
00221         x *= PxExtended(s);
00222         y *= PxExtended(s);
00223         z *= PxExtended(s);
00224         return *this;
00225     }
00226 
00227     PX_INLINE   PxExtendedVec3      operator+(const PxExtendedVec3& v)  const
00228     {
00229         return PxExtendedVec3(x + v.x, y + v.y, z + v.z);
00230     }
00231 
00232     PX_INLINE   PxVec3          operator-(const PxExtendedVec3& v)  const
00233     {
00234         return PxVec3(PxReal(x - v.x), PxReal(y - v.y), PxReal(z - v.z));
00235     }
00236 
00237     PX_INLINE   PxExtended&         operator[](int index)
00238     {
00239         PX_ASSERT(index>=0 && index<=2);
00240         return (&x)[index];
00241     }
00242 
00243 
00244     PX_INLINE   PxExtended          operator[](int index) const
00245     {
00246         PX_ASSERT(index>=0 && index<=2);
00247         return (&x)[index];
00248     }
00249 
00250     PxExtended x,y,z;
00251 };
00252 
00253     PX_FORCE_INLINE PxVec3 toVec3(const PxExtendedVec3& v)
00254     {
00255         return PxVec3(float(v.x), float(v.y), float(v.z));
00256     }
00257 
00258 #else
00259 // Big worlds not defined
00260 
00261 typedef PxVec3      PxExtendedVec3;
00262 typedef PxReal      PxExtended;
00263 #define PX_MAX_EXTENDED PX_MAX_F32
00264 #define PxExtendedAbs(x)    fabsf(x)
00265 #endif
00266 
00267 #ifndef PX_DOXYGEN
00268 } // namespace physx
00269 #endif
00270 
00272 #endif


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