NVIDIA(R) PhysX(R) SDK 3.4 API Reference: PxExtended.h Source File

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


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