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-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 #ifndef PXFOUNDATION_PXVEC2_H 00031 #define PXFOUNDATION_PXVEC2_H 00032 00037 #include "foundation/PxMath.h" 00038 00039 #if !PX_DOXYGEN 00040 namespace physx 00041 { 00042 #endif 00043 00049 class PxVec2 00050 { 00051 public: 00055 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2() 00056 { 00057 } 00058 00062 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2(PxZERO r) : x(0.0f), y(0.0f) 00063 { 00064 PX_UNUSED(r); 00065 } 00066 00074 explicit PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2(float a) : x(a), y(a) 00075 { 00076 } 00077 00084 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2(float nx, float ny) : x(nx), y(ny) 00085 { 00086 } 00087 00091 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2(const PxVec2& v) : x(v.x), y(v.y) 00092 { 00093 } 00094 00095 // Operators 00096 00100 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2& operator=(const PxVec2& p) 00101 { 00102 x = p.x; 00103 y = p.y; 00104 return *this; 00105 } 00106 00110 PX_DEPRECATED PX_CUDA_CALLABLE PX_FORCE_INLINE float& operator[](int index) 00111 { 00112 PX_ASSERT(index >= 0 && index <= 1); 00113 00114 return reinterpret_cast<float*>(this)[index]; 00115 } 00116 00120 PX_DEPRECATED PX_CUDA_CALLABLE PX_FORCE_INLINE const float& operator[](int index) const 00121 { 00122 PX_ASSERT(index >= 0 && index <= 1); 00123 00124 return reinterpret_cast<const float*>(this)[index]; 00125 } 00126 00130 PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator==(const PxVec2& v) const 00131 { 00132 return x == v.x && y == v.y; 00133 } 00134 00138 PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator!=(const PxVec2& v) const 00139 { 00140 return x != v.x || y != v.y; 00141 } 00142 00146 PX_CUDA_CALLABLE PX_FORCE_INLINE bool isZero() const 00147 { 00148 return x == 0.0f && y == 0.0f; 00149 } 00150 00154 PX_CUDA_CALLABLE PX_INLINE bool isFinite() const 00155 { 00156 return PxIsFinite(x) && PxIsFinite(y); 00157 } 00158 00162 PX_CUDA_CALLABLE PX_FORCE_INLINE bool isNormalized() const 00163 { 00164 const float unitTolerance = 1e-4f; 00165 return isFinite() && PxAbs(magnitude() - 1) < unitTolerance; 00166 } 00167 00173 PX_CUDA_CALLABLE PX_FORCE_INLINE float magnitudeSquared() const 00174 { 00175 return x * x + y * y; 00176 } 00177 00181 PX_CUDA_CALLABLE PX_FORCE_INLINE float magnitude() const 00182 { 00183 return PxSqrt(magnitudeSquared()); 00184 } 00185 00189 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 operator-() const 00190 { 00191 return PxVec2(-x, -y); 00192 } 00193 00197 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 operator+(const PxVec2& v) const 00198 { 00199 return PxVec2(x + v.x, y + v.y); 00200 } 00201 00205 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 operator-(const PxVec2& v) const 00206 { 00207 return PxVec2(x - v.x, y - v.y); 00208 } 00209 00213 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 operator*(float f) const 00214 { 00215 return PxVec2(x * f, y * f); 00216 } 00217 00221 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 operator/(float f) const 00222 { 00223 f = 1.0f / f; // PT: inconsistent notation with operator /= 00224 return PxVec2(x * f, y * f); 00225 } 00226 00230 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2& operator+=(const PxVec2& v) 00231 { 00232 x += v.x; 00233 y += v.y; 00234 return *this; 00235 } 00236 00240 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2& operator-=(const PxVec2& v) 00241 { 00242 x -= v.x; 00243 y -= v.y; 00244 return *this; 00245 } 00246 00250 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2& operator*=(float f) 00251 { 00252 x *= f; 00253 y *= f; 00254 return *this; 00255 } 00259 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2& operator/=(float f) 00260 { 00261 f = 1.0f / f; // PT: inconsistent notation with operator / 00262 x *= f; 00263 y *= f; 00264 return *this; 00265 } 00266 00270 PX_CUDA_CALLABLE PX_FORCE_INLINE float dot(const PxVec2& v) const 00271 { 00272 return x * v.x + y * v.y; 00273 } 00274 00277 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 getNormalized() const 00278 { 00279 const float m = magnitudeSquared(); 00280 return m > 0.0f ? *this * PxRecipSqrt(m) : PxVec2(0, 0); 00281 } 00282 00286 PX_CUDA_CALLABLE PX_FORCE_INLINE float normalize() 00287 { 00288 const float m = magnitude(); 00289 if(m > 0.0f) 00290 *this /= m; 00291 return m; 00292 } 00293 00297 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 multiply(const PxVec2& a) const 00298 { 00299 return PxVec2(x * a.x, y * a.y); 00300 } 00301 00305 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 minimum(const PxVec2& v) const 00306 { 00307 return PxVec2(PxMin(x, v.x), PxMin(y, v.y)); 00308 } 00309 00313 PX_CUDA_CALLABLE PX_FORCE_INLINE float minElement() const 00314 { 00315 return PxMin(x, y); 00316 } 00317 00321 PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec2 maximum(const PxVec2& v) const 00322 { 00323 return PxVec2(PxMax(x, v.x), PxMax(y, v.y)); 00324 } 00325 00329 PX_CUDA_CALLABLE PX_FORCE_INLINE float maxElement() const 00330 { 00331 return PxMax(x, y); 00332 } 00333 00334 float x, y; 00335 }; 00336 00337 PX_CUDA_CALLABLE static PX_FORCE_INLINE PxVec2 operator*(float f, const PxVec2& v) 00338 { 00339 return PxVec2(f * v.x, f * v.y); 00340 } 00341 00342 #if !PX_DOXYGEN 00343 } // namespace physx 00344 #endif 00345 00347 #endif // #ifndef PXFOUNDATION_PXVEC2_H
Copyright © 2008-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com