PhysX SDK 3.2 API Reference: PxVec2.h Source File

PhysX SDK 3.2 API

PxVec2.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_VEC2_H
00032 #define PX_FOUNDATION_PX_VEC2_H
00033 
00038 #include "foundation/PxMath.h"
00039 
00040 #ifndef PX_DOXYGEN
00041 namespace physx
00042 {
00043 #endif
00044 
00045 
00051 class PxVec2
00052 {
00053 public:
00054 
00058     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2() {}
00059 
00067     explicit PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2(PxReal a): x(a), y(a) {}
00068 
00075     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2(PxReal nx, PxReal ny): x(nx), y(ny){}
00076 
00080     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2(const PxVec2& v): x(v.x), y(v.y) {}
00081 
00082     //Operators
00083 
00087     PX_CUDA_CALLABLE PX_FORCE_INLINE    PxVec2& operator=(const PxVec2& p)          { x = p.x; y = p.y; return *this;       }
00088 
00092     PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal& operator[](int index)                  { PX_ASSERT(index>=0 && index<=1); return (&x)[index]; }
00093 
00097     PX_CUDA_CALLABLE PX_FORCE_INLINE const PxReal& operator[](int index) const      { PX_ASSERT(index>=0 && index<=1); return (&x)[index]; }
00098 
00102     PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator==(const PxVec2&v) const  { return x == v.x && y == v.y; }
00103 
00107     PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator!=(const PxVec2&v) const  { return x != v.x || y != v.y; }
00108 
00112     PX_CUDA_CALLABLE PX_FORCE_INLINE bool isZero()  const                   { return x==0.0f && y==0.0f;            }
00113 
00117     PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
00118     {
00119         return PxIsFinite(x) && PxIsFinite(y);
00120     }
00121 
00125     PX_CUDA_CALLABLE PX_FORCE_INLINE bool isNormalized() const
00126     {
00127         const float unitTolerance = PxReal(1e-4);
00128         return isFinite() && PxAbs(magnitude()-1)<unitTolerance;
00129     }
00130 
00136     PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal magnitudeSquared() const        {   return x * x + y * y;                   }
00137 
00141     PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal magnitude() const               {   return PxSqrt(magnitudeSquared());      }
00142 
00146     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 operator -() const
00147     {
00148         return PxVec2(-x, -y);
00149     }
00150 
00154     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 operator +(const PxVec2& v) const       {   return PxVec2(x + v.x, y + v.y);    }
00155 
00159     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 operator -(const PxVec2& v) const       {   return PxVec2(x - v.x, y - v.y);    }
00160 
00164     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 operator *(PxReal f) const              {   return PxVec2(x * f, y * f);            }
00165 
00169     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 operator /(PxReal f) const
00170     {
00171         f = PxReal(1) / f;  // PT: inconsistent notation with operator /=
00172         return PxVec2(x * f, y * f);
00173     }
00174 
00178     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2& operator +=(const PxVec2& v)
00179     {
00180         x += v.x;
00181         y += v.y;
00182         return *this;
00183     }
00184     
00188     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2& operator -=(const PxVec2& v)
00189     {
00190         x -= v.x;
00191         y -= v.y;
00192         return *this;
00193     }
00194 
00198     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2& operator *=(PxReal f)
00199     {
00200         x *= f;
00201         y *= f;
00202         return *this;
00203     }
00207     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2& operator /=(PxReal f)
00208     {
00209         f = 1.0f/f; // PT: inconsistent notation with operator /
00210         x *= f;
00211         y *= f;
00212         return *this;
00213     }
00214 
00218     PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal dot(const PxVec2& v) const      
00219     {   
00220         return x * v.x + y * v.y;               
00221     }
00222 
00225     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 getNormalized() const
00226     {
00227         const PxReal m = magnitudeSquared();
00228         return m>0 ? *this * PxRecipSqrt(m) : PxVec2(0,0);
00229     }
00230 
00234     PX_CUDA_CALLABLE PX_FORCE_INLINE PxReal normalize()
00235     {
00236         const PxReal m = magnitude();
00237         if (m>0) 
00238             *this /= m;
00239         return m;
00240     }
00241 
00245     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 multiply(const PxVec2& a) const
00246     {
00247         return PxVec2(x*a.x, y*a.y);
00248     }
00249 
00253     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 minimum(const PxVec2& v) const
00254     { 
00255         return PxVec2(PxMin(x, v.x), PxMin(y,v.y)); 
00256     }
00257 
00261     PX_CUDA_CALLABLE PX_FORCE_INLINE float minElement() const
00262     {
00263         return PxMin(x, y);
00264     }
00265     
00269     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 maximum(const PxVec2& v) const
00270     { 
00271         return PxVec2(PxMax(x, v.x), PxMax(y,v.y)); 
00272     } 
00273 
00277     PX_CUDA_CALLABLE PX_FORCE_INLINE float maxElement() const
00278     {
00279         return PxMax(x, y);
00280     }
00281 
00282     PxReal x,y;
00283 };
00284 
00285 PX_CUDA_CALLABLE static PX_FORCE_INLINE PxVec2 operator *(PxReal f, const PxVec2& v)
00286 {
00287     return PxVec2(f * v.x, f * v.y);
00288 }
00289 
00290 #ifndef PX_DOXYGEN
00291 } // namespace physx
00292 #endif
00293 
00295 #endif // PX_FOUNDATION_PX_VEC2_H


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