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

NVIDIA PhysX SDK 3.4 API

PxCoreUtilityTypes.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 
00031 #ifndef PX_CORE_UTILTY_TYPES_H
00032 #define PX_CORE_UTILTY_TYPES_H
00033 
00037 #include "foundation/PxAssert.h"
00038 #include "foundation/PxMemory.h"
00039 
00040 #if !PX_DOXYGEN
00041 namespace physx
00042 {
00043 #endif
00044 
00045 
00046 struct PxStridedData
00047 {
00053     PxU32 stride;
00054     const void* data;
00055 
00056     PxStridedData() : stride( 0 ), data( NULL ) {}
00057 
00058     template<typename TDataType>
00059     PX_INLINE const TDataType& at( PxU32 idx ) const
00060     {
00061         PxU32 theStride( stride );
00062         if ( theStride == 0 )
00063             theStride = sizeof( TDataType );
00064         PxU32 offset( theStride * idx );
00065         return *(reinterpret_cast<const TDataType*>( reinterpret_cast< const PxU8* >( data ) + offset ));
00066     }
00067 };
00068 
00069 template<typename TDataType>
00070 struct PxTypedStridedData
00071 {
00072     PxU32 stride;
00073     const TDataType* data;
00074 
00075     PxTypedStridedData()
00076         : stride( 0 )
00077         , data( NULL )
00078     {
00079     }
00080 
00081 };
00082 
00083 struct PxBoundedData : public PxStridedData
00084 {
00085     PxU32 count;
00086     PxBoundedData() : count( 0 ) {}
00087 };
00088 
00089 template<PxU8 TNumBytes>
00090 struct PxPadding
00091 {
00092     PxU8 mPadding[TNumBytes];
00093     PxPadding()
00094     {
00095         for ( PxU8 idx =0; idx < TNumBytes; ++idx )
00096             mPadding[idx] = 0;
00097     }
00098 };
00099 
00100 template <PxU32 NB_ELEMENTS> class PxFixedSizeLookupTable
00101 {
00102 //= ATTENTION! =====================================================================================
00103 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00104 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00105 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00106 // accordingly.
00107 //==================================================================================================
00108 public:
00109     
00110     PxFixedSizeLookupTable() 
00111         : mNbDataPairs(0)
00112     {
00113     }
00114 
00115     PxFixedSizeLookupTable(const PxEMPTY) {}
00116 
00117     PxFixedSizeLookupTable(const PxReal* dataPairs, const PxU32 numDataPairs)
00118     {
00119         PxMemCopy(mDataPairs,dataPairs,sizeof(PxReal)*2*numDataPairs);
00120         mNbDataPairs=numDataPairs;
00121     }
00122 
00123     PxFixedSizeLookupTable(const PxFixedSizeLookupTable& src)
00124     {
00125         PxMemCopy(mDataPairs,src.mDataPairs,sizeof(PxReal)*2*src.mNbDataPairs);
00126         mNbDataPairs=src.mNbDataPairs;
00127     }
00128 
00129     ~PxFixedSizeLookupTable()
00130     {
00131     }
00132 
00133     PxFixedSizeLookupTable& operator=(const PxFixedSizeLookupTable& src)
00134     {
00135         PxMemCopy(mDataPairs,src.mDataPairs,sizeof(PxReal)*2*src.mNbDataPairs);
00136         mNbDataPairs=src.mNbDataPairs;
00137         return *this;
00138     }
00139 
00140     PX_FORCE_INLINE void addPair(const PxReal x, const PxReal y)
00141     {
00142         PX_ASSERT(mNbDataPairs<NB_ELEMENTS);
00143         mDataPairs[2*mNbDataPairs+0]=x;
00144         mDataPairs[2*mNbDataPairs+1]=y;
00145         mNbDataPairs++;
00146     }
00147 
00148     PX_FORCE_INLINE PxReal getYVal(const PxReal x) const
00149     {
00150         if(0==mNbDataPairs)
00151         {
00152             PX_ASSERT(false);
00153             return 0;
00154         }
00155 
00156         if(1==mNbDataPairs || x<getX(0))
00157         {
00158             return getY(0);
00159         }
00160 
00161         PxReal x0=getX(0);
00162         PxReal y0=getY(0);
00163 
00164         for(PxU32 i=1;i<mNbDataPairs;i++)
00165         {
00166             const PxReal x1=getX(i);
00167             const PxReal y1=getY(i);
00168 
00169             if((x>=x0)&&(x<x1))
00170             {
00171                 return (y0+(y1-y0)*(x-x0)/(x1-x0));
00172             }
00173 
00174             x0=x1;
00175             y0=y1;
00176         }
00177 
00178         PX_ASSERT(x>=getX(mNbDataPairs-1));
00179         return getY(mNbDataPairs-1);
00180     }
00181 
00182     PxU32 getNbDataPairs() const {return mNbDataPairs;}
00183     
00184     void clear()
00185     {
00186         memset(mDataPairs, 0, NB_ELEMENTS*2*sizeof(PxReal));
00187         mNbDataPairs = 0;
00188     }
00189 
00190     PX_FORCE_INLINE PxReal getX(const PxU32 i) const
00191     {
00192         return mDataPairs[2*i];
00193     }
00194     PX_FORCE_INLINE PxReal getY(const PxU32 i) const
00195     {
00196         return mDataPairs[2*i+1];
00197     }
00198 
00199     PxReal mDataPairs[2*NB_ELEMENTS];
00200     PxU32 mNbDataPairs;
00201     PxU32 mPad[3];
00202 
00203     
00204 };
00205 
00206 #if !PX_DOXYGEN
00207 } // namespace physx
00208 #endif
00209 
00211 #endif


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