NVIDIA(R) PhysX(R) SDK 3.4 API Reference: PxVec4.h Source File

NVIDIA PhysX 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-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_PXVEC4_H
00031 #define PXFOUNDATION_PXVEC4_H
00032 
00035 #include "foundation/PxMath.h"
00036 #include "foundation/PxVec3.h"
00037 #include "foundation/PxAssert.h"
00038 
00044 #if !PX_DOXYGEN
00045 namespace physx
00046 {
00047 #endif
00048 
00049 class PxVec4
00050 {
00051   public:
00055     PX_CUDA_CALLABLE PX_INLINE PxVec4()
00056     {
00057     }
00058 
00062     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec4(PxZERO r) : x(0.0f), y(0.0f), z(0.0f), w(0.0f)
00063     {
00064         PX_UNUSED(r);
00065     }
00066 
00074     explicit PX_CUDA_CALLABLE PX_INLINE PxVec4(float a) : x(a), y(a), z(a), w(a)
00075     {
00076     }
00077 
00086     PX_CUDA_CALLABLE PX_INLINE PxVec4(float nx, float ny, float nz, float nw) : x(nx), y(ny), z(nz), w(nw)
00087     {
00088     }
00089 
00096     PX_CUDA_CALLABLE PX_INLINE PxVec4(const PxVec3& v, float nw) : x(v.x), y(v.y), z(v.z), w(nw)
00097     {
00098     }
00099 
00105     explicit PX_CUDA_CALLABLE PX_INLINE PxVec4(const float v[]) : x(v[0]), y(v[1]), z(v[2]), w(v[3])
00106     {
00107     }
00108 
00112     PX_CUDA_CALLABLE PX_INLINE PxVec4(const PxVec4& v) : x(v.x), y(v.y), z(v.z), w(v.w)
00113     {
00114     }
00115 
00116     // Operators
00117 
00121     PX_CUDA_CALLABLE PX_INLINE PxVec4& operator=(const PxVec4& p)
00122     {
00123         x = p.x;
00124         y = p.y;
00125         z = p.z;
00126         w = p.w;
00127         return *this;
00128     }
00129 
00133     PX_DEPRECATED PX_CUDA_CALLABLE PX_INLINE float& operator[](unsigned int index)
00134     {
00135         PX_ASSERT(index <= 3);
00136 
00137         return reinterpret_cast<float*>(this)[index];
00138     }
00139 
00143     PX_DEPRECATED PX_CUDA_CALLABLE PX_INLINE const float& operator[](unsigned int index) const
00144     {
00145         PX_ASSERT(index <= 3);
00146 
00147         return reinterpret_cast<const float*>(this)[index];
00148     }
00149 
00153     PX_CUDA_CALLABLE PX_INLINE bool operator==(const PxVec4& v) const
00154     {
00155         return x == v.x && y == v.y && z == v.z && w == v.w;
00156     }
00157 
00161     PX_CUDA_CALLABLE PX_INLINE bool operator!=(const PxVec4& v) const
00162     {
00163         return x != v.x || y != v.y || z != v.z || w != v.w;
00164     }
00165 
00169     PX_CUDA_CALLABLE PX_INLINE bool isZero() const
00170     {
00171         return x == 0 && y == 0 && z == 0 && w == 0;
00172     }
00173 
00177     PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
00178     {
00179         return PxIsFinite(x) && PxIsFinite(y) && PxIsFinite(z) && PxIsFinite(w);
00180     }
00181 
00185     PX_CUDA_CALLABLE PX_INLINE bool isNormalized() const
00186     {
00187         const float unitTolerance = 1e-4f;
00188         return isFinite() && PxAbs(magnitude() - 1) < unitTolerance;
00189     }
00190 
00196     PX_CUDA_CALLABLE PX_INLINE float magnitudeSquared() const
00197     {
00198         return x * x + y * y + z * z + w * w;
00199     }
00200 
00204     PX_CUDA_CALLABLE PX_INLINE float magnitude() const
00205     {
00206         return PxSqrt(magnitudeSquared());
00207     }
00208 
00212     PX_CUDA_CALLABLE PX_INLINE PxVec4 operator-() const
00213     {
00214         return PxVec4(-x, -y, -z, -w);
00215     }
00216 
00220     PX_CUDA_CALLABLE PX_INLINE PxVec4 operator+(const PxVec4& v) const
00221     {
00222         return PxVec4(x + v.x, y + v.y, z + v.z, w + v.w);
00223     }
00224 
00228     PX_CUDA_CALLABLE PX_INLINE PxVec4 operator-(const PxVec4& v) const
00229     {
00230         return PxVec4(x - v.x, y - v.y, z - v.z, w - v.w);
00231     }
00232 
00237     PX_CUDA_CALLABLE PX_INLINE PxVec4 operator*(float f) const
00238     {
00239         return PxVec4(x * f, y * f, z * f, w * f);
00240     }
00241 
00245     PX_CUDA_CALLABLE PX_INLINE PxVec4 operator/(float f) const
00246     {
00247         f = 1.0f / f;
00248         return PxVec4(x * f, y * f, z * f, w * f);
00249     }
00250 
00254     PX_CUDA_CALLABLE PX_INLINE PxVec4& operator+=(const PxVec4& v)
00255     {
00256         x += v.x;
00257         y += v.y;
00258         z += v.z;
00259         w += v.w;
00260         return *this;
00261     }
00262 
00266     PX_CUDA_CALLABLE PX_INLINE PxVec4& operator-=(const PxVec4& v)
00267     {
00268         x -= v.x;
00269         y -= v.y;
00270         z -= v.z;
00271         w -= v.w;
00272         return *this;
00273     }
00274 
00278     PX_CUDA_CALLABLE PX_INLINE PxVec4& operator*=(float f)
00279     {
00280         x *= f;
00281         y *= f;
00282         z *= f;
00283         w *= f;
00284         return *this;
00285     }
00289     PX_CUDA_CALLABLE PX_INLINE PxVec4& operator/=(float f)
00290     {
00291         f = 1.0f / f;
00292         x *= f;
00293         y *= f;
00294         z *= f;
00295         w *= f;
00296         return *this;
00297     }
00298 
00302     PX_CUDA_CALLABLE PX_INLINE float dot(const PxVec4& v) const
00303     {
00304         return x * v.x + y * v.y + z * v.z + w * v.w;
00305     }
00306 
00309     PX_CUDA_CALLABLE PX_INLINE PxVec4 getNormalized() const
00310     {
00311         float m = magnitudeSquared();
00312         return m > 0.0f ? *this * PxRecipSqrt(m) : PxVec4(0, 0, 0, 0);
00313     }
00314 
00318     PX_CUDA_CALLABLE PX_INLINE float normalize()
00319     {
00320         float m = magnitude();
00321         if(m > 0.0f)
00322             *this /= m;
00323         return m;
00324     }
00325 
00329     PX_CUDA_CALLABLE PX_INLINE PxVec4 multiply(const PxVec4& a) const
00330     {
00331         return PxVec4(x * a.x, y * a.y, z * a.z, w * a.w);
00332     }
00333 
00337     PX_CUDA_CALLABLE PX_INLINE PxVec4 minimum(const PxVec4& v) const
00338     {
00339         return PxVec4(PxMin(x, v.x), PxMin(y, v.y), PxMin(z, v.z), PxMin(w, v.w));
00340     }
00341 
00345     PX_CUDA_CALLABLE PX_INLINE PxVec4 maximum(const PxVec4& v) const
00346     {
00347         return PxVec4(PxMax(x, v.x), PxMax(y, v.y), PxMax(z, v.z), PxMax(w, v.w));
00348     }
00349 
00350     PX_CUDA_CALLABLE PX_INLINE PxVec3 getXYZ() const
00351     {
00352         return PxVec3(x, y, z);
00353     }
00354 
00358     PX_CUDA_CALLABLE PX_INLINE void setZero()
00359     {
00360         x = y = z = w = 0.0f;
00361     }
00362 
00363     float x, y, z, w;
00364 };
00365 
00366 PX_CUDA_CALLABLE static PX_INLINE PxVec4 operator*(float f, const PxVec4& v)
00367 {
00368     return PxVec4(f * v.x, f * v.y, f * v.z, f * v.w);
00369 }
00370 
00371 #if !PX_DOXYGEN
00372 } // namespace physx
00373 #endif
00374 
00376 #endif // #ifndef PXFOUNDATION_PXVEC4_H


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