PxExtended.h

Go to the documentation of this file.
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 //
00026 // Copyright (c) 2008-2018 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-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com