PhysX SDK 3.2 API Reference: PxVec4.h Source File

PhysX SDK 3.2 API

PxVec4.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_VEC4_H
00032 #define PX_FOUNDATION_PX_VEC4_H
00033 
00036 #include "foundation/PxMath.h"
00037 #include "foundation/PxVec3.h"
00038 #include "foundation/PxAssert.h"
00039 
00040 
00046 #ifndef PX_DOXYGEN
00047 namespace physx
00048 {
00049 #endif
00050 
00051 class PxVec4
00052 {
00053 public:
00054 
00058     PX_CUDA_CALLABLE PX_INLINE PxVec4() {}
00059 
00067     explicit PX_CUDA_CALLABLE PX_INLINE PxVec4(PxReal a): x(a), y(a), z(a), w(a) {}
00068 
00077     PX_CUDA_CALLABLE PX_INLINE PxVec4(PxReal nx, PxReal ny, PxReal nz, PxReal nw): x(nx), y(ny), z(nz), w(nw) {}
00078 
00079 
00086     PX_CUDA_CALLABLE PX_INLINE PxVec4(const PxVec3& v, PxReal nw): x(v.x), y(v.y), z(v.z), w(nw) {}
00087 
00088 
00094     explicit PX_CUDA_CALLABLE PX_INLINE PxVec4(const PxReal v[]): x(v[0]), y(v[1]), z(v[2]), w(v[3]) {}
00095 
00099     PX_CUDA_CALLABLE PX_INLINE PxVec4(const PxVec4& v): x(v.x), y(v.y), z(v.z), w(v.w) {}
00100 
00101     //Operators
00102 
00106     PX_CUDA_CALLABLE PX_INLINE  PxVec4& operator=(const PxVec4& p)          { x = p.x; y = p.y; z = p.z; w = p.w;   return *this;       }
00107 
00111     PX_CUDA_CALLABLE PX_INLINE PxReal& operator[](int index)                { PX_ASSERT(index>=0 && index<=3); return (&x)[index]; }
00112 
00116     PX_CUDA_CALLABLE PX_INLINE const PxReal& operator[](int index) const    { PX_ASSERT(index>=0 && index<=3); return (&x)[index]; }
00117 
00121     PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxVec4&v) const    { return x == v.x && y == v.y && z == v.z && w == v.w; }
00122 
00126     PX_CUDA_CALLABLE PX_INLINE bool operator!=(const PxVec4&v) const    { return x != v.x || y != v.y || z != v.z || w!= v.w; }
00127 
00131     PX_CUDA_CALLABLE PX_INLINE bool isZero()    const                   { return x==0 && y==0 && z == 0 && w == 0;          }
00132 
00136     PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
00137     {
00138         return PxIsFinite(x) && PxIsFinite(y) && PxIsFinite(z) && PxIsFinite(w);
00139     }
00140 
00144     PX_CUDA_CALLABLE PX_INLINE bool isNormalized() const
00145     {
00146         const float unitTolerance = PxReal(1e-4);
00147         return isFinite() && PxAbs(magnitude()-1)<unitTolerance;
00148     }
00149 
00150 
00156     PX_CUDA_CALLABLE PX_INLINE PxReal magnitudeSquared() const      {   return x * x + y * y + z * z + w * w;       }
00157 
00161     PX_CUDA_CALLABLE PX_INLINE PxReal magnitude() const             {   return PxSqrt(magnitudeSquared());      }
00162 
00166     PX_CUDA_CALLABLE PX_INLINE PxVec4 operator -() const
00167     {
00168         return PxVec4(-x, -y, -z, -w);
00169     }
00170 
00174     PX_CUDA_CALLABLE PX_INLINE PxVec4 operator +(const PxVec4& v) const     {   return PxVec4(x + v.x, y + v.y, z + v.z, w + v.w);  }
00175 
00179     PX_CUDA_CALLABLE PX_INLINE PxVec4 operator -(const PxVec4& v) const     {   return PxVec4(x - v.x, y - v.y, z - v.z, w - v.w);  }
00180 
00185     PX_CUDA_CALLABLE PX_INLINE PxVec4 operator *(PxReal f) const                {   return PxVec4(x * f, y * f, z * f, w * f);      }
00186 
00190     PX_CUDA_CALLABLE PX_INLINE PxVec4 operator /(PxReal f) const
00191     {
00192         f = PxReal(1) / f; 
00193         return PxVec4(x * f, y * f, z * f, w * f);
00194     }
00195 
00199     PX_CUDA_CALLABLE PX_INLINE PxVec4& operator +=(const PxVec4& v)
00200     {
00201         x += v.x;
00202         y += v.y;
00203         z += v.z;
00204         w += v.w;
00205         return *this;
00206     }
00207     
00211     PX_CUDA_CALLABLE PX_INLINE PxVec4& operator -=(const PxVec4& v)
00212     {
00213         x -= v.x;
00214         y -= v.y;
00215         z -= v.z;
00216         w -= v.w;
00217         return *this;
00218     }
00219 
00223     PX_CUDA_CALLABLE PX_INLINE PxVec4& operator *=(PxReal f)
00224     {
00225         x *= f;
00226         y *= f;
00227         z *= f;
00228         w *= f;
00229         return *this;
00230     }
00234     PX_CUDA_CALLABLE PX_INLINE PxVec4& operator /=(PxReal f)
00235     {
00236         f = 1.0f/f;
00237         x *= f;
00238         y *= f;
00239         z *= f;
00240         w *= f;
00241         return *this;
00242     }
00243 
00247     PX_CUDA_CALLABLE PX_INLINE PxReal dot(const PxVec4& v) const        
00248     {   
00249         return x * v.x + y * v.y + z * v.z + w * v.w;               
00250     }
00251 
00254     PX_CUDA_CALLABLE PX_INLINE PxVec4 getNormalized() const
00255     {
00256         PxReal m = magnitudeSquared();
00257         return m>0 ? *this * PxRecipSqrt(m) : PxVec4(0,0,0,0);
00258     }
00259 
00260 
00264     PX_CUDA_CALLABLE PX_INLINE PxReal normalize()
00265     {
00266         PxReal m = magnitude();
00267         if (m>0) 
00268             *this /= m;
00269         return m;
00270     }
00271 
00275     PX_CUDA_CALLABLE PX_INLINE PxVec4 multiply(const PxVec4& a) const
00276     {
00277         return PxVec4(x*a.x, y*a.y, z*a.z, w*a.w);
00278     }
00279 
00283     PX_CUDA_CALLABLE PX_INLINE PxVec4 minimum(const PxVec4& v) const
00284     { 
00285         return PxVec4(PxMin(x, v.x), PxMin(y,v.y), PxMin(z,v.z), PxMin(w,v.w)); 
00286     }
00287 
00291     PX_CUDA_CALLABLE PX_INLINE PxVec4 maximum(const PxVec4& v) const
00292     { 
00293         return PxVec4(PxMax(x, v.x), PxMax(y,v.y), PxMax(z,v.z), PxMax(w,v.w)); 
00294     } 
00295 
00296     PX_CUDA_CALLABLE PX_INLINE PxVec3 getXYZ() const
00297     {
00298         return PxVec3(x,y,z);
00299     }
00300 
00304     PX_CUDA_CALLABLE PX_INLINE void setZero() { x = y = z = w = PxReal(0); }
00305 
00306     PxReal x,y,z,w;
00307 };
00308 
00309 
00310 PX_CUDA_CALLABLE static PX_INLINE PxVec4 operator *(PxReal f, const PxVec4& v)
00311 {
00312     return PxVec4(f * v.x, f * v.y, f * v.z, f * v.w);
00313 }
00314 
00315 #ifndef PX_DOXYGEN
00316 } // namespace physx
00317 #endif
00318 
00320 #endif // PX_FOUNDATION_PX_VEC4_H


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