PhysX SDK 3.2 API Reference: PxVec3.h Source File

PhysX SDK 3.2 API

PxVec3.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_VEC3_H
00032 #define PX_FOUNDATION_PX_VEC3_H
00033 
00038 #include "foundation/PxMath.h"
00039 
00040 #ifndef PX_DOXYGEN
00041 namespace physx
00042 {
00043 #endif
00044 
00045 
00051 class PxVec3
00052 {
00053 public:
00054 
00058     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3() {}
00059 
00067     explicit PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3(PxReal a): x(a), y(a), z(a) {}
00068 
00076     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3(PxReal nx, PxReal ny, PxReal nz): x(nx), y(ny), z(nz) {}
00077 
00081     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3(const PxVec3& v): x(v.x), y(v.y), z(v.z) {}
00082 
00083     //Operators
00084 
00088     PX_CUDA_CALLABLE PX_FORCE_INLINE    PxVec3& operator=(const PxVec3& p)          { x = p.x; y = p.y; z = p.z;    return *this;       }
00089 
00093     PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal& operator[](int index)                  { PX_ASSERT(index>=0 && index<=2); return (&x)[index]; }
00094 
00098     PX_CUDA_CALLABLE PX_FORCE_INLINE const PxReal& operator[](int index) const      { PX_ASSERT(index>=0 && index<=2); return (&x)[index]; }
00099 
00103     PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator==(const PxVec3&v) const  { return x == v.x && y == v.y && z == v.z; }
00104 
00108     PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator!=(const PxVec3&v) const  { return x != v.x || y != v.y || z != v.z; }
00109 
00113     PX_CUDA_CALLABLE PX_FORCE_INLINE bool isZero()  const                   { return x==0.0f && y==0.0f && z == 0.0f;           }
00114 
00118     PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
00119     {
00120         return PxIsFinite(x) && PxIsFinite(y) && PxIsFinite(z);
00121     }
00122 
00126     PX_CUDA_CALLABLE PX_FORCE_INLINE bool isNormalized() const
00127     {
00128         const float unitTolerance = PxReal(1e-4);
00129         return isFinite() && PxAbs(magnitude()-1)<unitTolerance;
00130     }
00131 
00137     PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal magnitudeSquared() const        {   return x * x + y * y + z * z;                   }
00138 
00142     PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal magnitude() const               {   return PxSqrt(magnitudeSquared());      }
00143 
00147     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 operator -() const
00148     {
00149         return PxVec3(-x, -y, -z);
00150     }
00151 
00155     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 operator +(const PxVec3& v) const       {   return PxVec3(x + v.x, y + v.y, z + v.z);   }
00156 
00160     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 operator -(const PxVec3& v) const       {   return PxVec3(x - v.x, y - v.y, z - v.z);   }
00161 
00165     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 operator *(PxReal f) const              {   return PxVec3(x * f, y * f, z * f);         }
00166 
00170     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 operator /(PxReal f) const
00171     {
00172         f = PxReal(1) / f;  // PT: inconsistent notation with operator /=
00173         return PxVec3(x * f, y * f, z * f);
00174     }
00175 
00179     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3& operator +=(const PxVec3& v)
00180     {
00181         x += v.x;
00182         y += v.y;
00183         z += v.z;
00184         return *this;
00185     }
00186     
00190     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3& operator -=(const PxVec3& v)
00191     {
00192         x -= v.x;
00193         y -= v.y;
00194         z -= v.z;
00195         return *this;
00196     }
00197 
00201     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3& operator *=(PxReal f)
00202     {
00203         x *= f;
00204         y *= f;
00205         z *= f;
00206         return *this;
00207     }
00211     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3& operator /=(PxReal f)
00212     {
00213         f = 1.0f/f; // PT: inconsistent notation with operator /
00214         x *= f;
00215         y *= f;
00216         z *= f;
00217         return *this;
00218     }
00219 
00223     PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal dot(const PxVec3& v) const      
00224     {   
00225         return x * v.x + y * v.y + z * v.z;             
00226     }
00227 
00231     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 cross(const PxVec3& v) const
00232     {
00233         return PxVec3(y * v.z - z * v.y, 
00234                       z * v.x - x * v.z, 
00235                       x * v.y - y * v.x);
00236     }
00237 
00240     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getNormalized() const
00241     {
00242         const PxReal m = magnitudeSquared();
00243         return m>0 ? *this * PxRecipSqrt(m) : PxVec3(0,0,0);
00244     }
00245 
00249     PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal normalize()
00250     {
00251         const PxReal m = magnitude();
00252         if (m>0) 
00253             *this /= m;
00254         return m;
00255     }
00256 
00261     PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal normalizeSafe()
00262     {
00263         const PxReal mag = magnitude();
00264         if (mag < PX_NORMALIZATION_EPSILON)
00265             return 0.0f;
00266         *this *= PxReal(1) / mag;
00267         return mag;
00268     }
00269 
00274     PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal normalizeFast()
00275     {
00276         const PxReal mag = magnitude();
00277         PX_ASSERT(mag >= PX_NORMALIZATION_EPSILON);
00278         *this *= PxReal(1) / mag;
00279         return mag;
00280     }
00281 
00285     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 multiply(const PxVec3& a) const
00286     {
00287         return PxVec3(x*a.x, y*a.y, z*a.z);
00288     }
00289 
00293     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 minimum(const PxVec3& v) const
00294     { 
00295         return PxVec3(PxMin(x, v.x), PxMin(y,v.y), PxMin(z,v.z));   
00296     }
00297 
00301     PX_CUDA_CALLABLE PX_FORCE_INLINE float minElement() const
00302     {
00303         return PxMin(x, PxMin(y, z));
00304     }
00305     
00309     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 maximum(const PxVec3& v) const
00310     { 
00311         return PxVec3(PxMax(x, v.x), PxMax(y,v.y), PxMax(z,v.z));   
00312     } 
00313 
00317     PX_CUDA_CALLABLE PX_FORCE_INLINE float maxElement() const
00318     {
00319         return PxMax(x, PxMax(y, z));
00320     }
00321 
00322     PxReal x,y,z;
00323 };
00324 
00325 PX_CUDA_CALLABLE static PX_FORCE_INLINE PxVec3 operator *(PxReal f, const PxVec3& v)
00326 {
00327     return PxVec3(f * v.x, f * v.y, f * v.z);
00328 }
00329 
00330 #ifndef PX_DOXYGEN
00331 } // namespace physx
00332 #endif
00333 
00335 #endif // PX_FOUNDATION_PX_VEC3_H


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