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

NVIDIA PhysX 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-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_PXVEC3_H
00031 #define PXFOUNDATION_PXVEC3_H
00032 
00037 #include "foundation/PxMath.h"
00038 
00039 #if !PX_DOXYGEN
00040 namespace physx
00041 {
00042 #endif
00043 
00049 class PxVec3
00050 {
00051   public:
00055     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3()
00056     {
00057     }
00058 
00062     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3(PxZERO r) : x(0.0f), y(0.0f), z(0.0f)
00063     {
00064         PX_UNUSED(r);
00065     }
00066 
00074     explicit PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3(float a) : x(a), y(a), z(a)
00075     {
00076     }
00077 
00085     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3(float nx, float ny, float nz) : x(nx), y(ny), z(nz)
00086     {
00087     }
00088 
00092     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3(const PxVec3& v) : x(v.x), y(v.y), z(v.z)
00093     {
00094     }
00095 
00096     // Operators
00097 
00101     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3& operator=(const PxVec3& p)
00102     {
00103         x = p.x;
00104         y = p.y;
00105         z = p.z;
00106         return *this;
00107     }
00108 
00112     PX_DEPRECATED PX_CUDA_CALLABLE PX_FORCE_INLINE float& operator[](unsigned int index)
00113     {
00114         PX_ASSERT(index <= 2);
00115 
00116         return reinterpret_cast<float*>(this)[index];
00117     }
00118 
00122     PX_DEPRECATED PX_CUDA_CALLABLE PX_FORCE_INLINE const float& operator[](unsigned int index) const
00123     {
00124         PX_ASSERT(index <= 2);
00125 
00126         return reinterpret_cast<const float*>(this)[index];
00127     }
00131     PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator==(const PxVec3& v) const
00132     {
00133         return x == v.x && y == v.y && z == v.z;
00134     }
00135 
00139     PX_CUDA_CALLABLE PX_FORCE_INLINE bool operator!=(const PxVec3& v) const
00140     {
00141         return x != v.x || y != v.y || z != v.z;
00142     }
00143 
00147     PX_CUDA_CALLABLE PX_FORCE_INLINE bool isZero() const
00148     {
00149         return x == 0.0f && y == 0.0f && z == 0.0f;
00150     }
00151 
00155     PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
00156     {
00157         return PxIsFinite(x) && PxIsFinite(y) && PxIsFinite(z);
00158     }
00159 
00163     PX_CUDA_CALLABLE PX_FORCE_INLINE bool isNormalized() const
00164     {
00165         const float unitTolerance = 1e-4f;
00166         return isFinite() && PxAbs(magnitude() - 1) < unitTolerance;
00167     }
00168 
00174     PX_CUDA_CALLABLE PX_FORCE_INLINE float magnitudeSquared() const
00175     {
00176         return x * x + y * y + z * z;
00177     }
00178 
00182     PX_CUDA_CALLABLE PX_FORCE_INLINE float magnitude() const
00183     {
00184         return PxSqrt(magnitudeSquared());
00185     }
00186 
00190     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 operator-() const
00191     {
00192         return PxVec3(-x, -y, -z);
00193     }
00194 
00198     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 operator+(const PxVec3& v) const
00199     {
00200         return PxVec3(x + v.x, y + v.y, z + v.z);
00201     }
00202 
00206     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 operator-(const PxVec3& v) const
00207     {
00208         return PxVec3(x - v.x, y - v.y, z - v.z);
00209     }
00210 
00214     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 operator*(float f) const
00215     {
00216         return PxVec3(x * f, y * f, z * f);
00217     }
00218 
00222     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 operator/(float f) const
00223     {
00224         f = 1.0f / f;
00225         return PxVec3(x * f, y * f, z * f);
00226     }
00227 
00231     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3& operator+=(const PxVec3& v)
00232     {
00233         x += v.x;
00234         y += v.y;
00235         z += v.z;
00236         return *this;
00237     }
00238 
00242     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3& operator-=(const PxVec3& v)
00243     {
00244         x -= v.x;
00245         y -= v.y;
00246         z -= v.z;
00247         return *this;
00248     }
00249 
00253     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3& operator*=(float f)
00254     {
00255         x *= f;
00256         y *= f;
00257         z *= f;
00258         return *this;
00259     }
00263     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3& operator/=(float f)
00264     {
00265         f = 1.0f / f;
00266         x *= f;
00267         y *= f;
00268         z *= f;
00269         return *this;
00270     }
00271 
00275     PX_CUDA_CALLABLE PX_FORCE_INLINE float dot(const PxVec3& v) const
00276     {
00277         return x * v.x + y * v.y + z * v.z;
00278     }
00279 
00283     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 cross(const PxVec3& v) const
00284     {
00285         return PxVec3(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
00286     }
00287 
00290     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getNormalized() const
00291     {
00292         const float m = magnitudeSquared();
00293         return m > 0.0f ? *this * PxRecipSqrt(m) : PxVec3(0, 0, 0);
00294     }
00295 
00299     PX_CUDA_CALLABLE PX_FORCE_INLINE float normalize()
00300     {
00301         const float m = magnitude();
00302         if(m > 0.0f)
00303             *this /= m;
00304         return m;
00305     }
00306 
00311     PX_CUDA_CALLABLE PX_FORCE_INLINE float normalizeSafe()
00312     {
00313         const float mag = magnitude();
00314         if(mag < PX_NORMALIZATION_EPSILON)
00315             return 0.0f;
00316         *this *= 1.0f / mag;
00317         return mag;
00318     }
00319 
00324     PX_CUDA_CALLABLE PX_FORCE_INLINE float normalizeFast()
00325     {
00326         const float mag = magnitude();
00327         PX_ASSERT(mag >= PX_NORMALIZATION_EPSILON);
00328         *this *= 1.0f / mag;
00329         return mag;
00330     }
00331 
00335     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 multiply(const PxVec3& a) const
00336     {
00337         return PxVec3(x * a.x, y * a.y, z * a.z);
00338     }
00339 
00343     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 minimum(const PxVec3& v) const
00344     {
00345         return PxVec3(PxMin(x, v.x), PxMin(y, v.y), PxMin(z, v.z));
00346     }
00347 
00351     PX_CUDA_CALLABLE PX_FORCE_INLINE float minElement() const
00352     {
00353         return PxMin(x, PxMin(y, z));
00354     }
00355 
00359     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 maximum(const PxVec3& v) const
00360     {
00361         return PxVec3(PxMax(x, v.x), PxMax(y, v.y), PxMax(z, v.z));
00362     }
00363 
00367     PX_CUDA_CALLABLE PX_FORCE_INLINE float maxElement() const
00368     {
00369         return PxMax(x, PxMax(y, z));
00370     }
00371 
00375     PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 abs() const
00376     {
00377         return PxVec3(PxAbs(x), PxAbs(y), PxAbs(z));
00378     }
00379 
00380     float x, y, z;
00381 };
00382 
00383 PX_CUDA_CALLABLE static PX_FORCE_INLINE PxVec3 operator*(float f, const PxVec3& v)
00384 {
00385     return PxVec3(f * v.x, f * v.y, f * v.z);
00386 }
00387 
00388 #if !PX_DOXYGEN
00389 } // namespace physx
00390 #endif
00391 
00393 #endif // #ifndef PXFOUNDATION_PXVEC3_H


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