PhysX SDK 3.2 API Reference: PxCoreUtilityTypes.h Source File

PhysX SDK 3.2 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-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_CORE_UTILTY_TYPES_H
00032 #define PX_CORE_UTILTY_TYPES_H
00033 
00037 #include "foundation/PxAssert.h"
00038 
00039 #ifndef PX_DOXYGEN
00040 namespace physx
00041 {
00042 #endif
00043 
00048 template<typename TDataType>
00049 class PxPtrArray
00050 {
00051     PxU32 count;
00052     TDataType*const* items;
00053     TDataType* singleItem;
00054 public:
00055 
00056     PX_INLINE PxPtrArray()
00057         : count ( 0 )
00058         , items ( NULL )
00059         , singleItem ( NULL )
00060     {
00061     }
00062     PX_INLINE PxPtrArray( const PxPtrArray<TDataType>& inOther )
00063     {
00064         (*this) = inOther;
00065     }
00066 
00067     PX_INLINE PxPtrArray<TDataType>& operator=( const PxPtrArray<TDataType>& inOther )
00068     {
00069         //This is harder to get right than it would seem
00070         //The problem is if you have a vector of these items
00071         //and they are being copied around.  Then the pointer to
00072         //a previous item's single item is probably bad.  Thus
00073         //you need to reconstruct the single item chain.
00074         //CN
00075         count = inOther.count;
00076         if ( count == 1 )
00077         {
00078             singleItem = inOther.items[0];
00079             items = &singleItem;
00080         }
00081         else
00082         {
00083             singleItem = NULL;
00084             items = inOther.items;
00085         }
00086         return *this;
00087     }
00088 
00092     PX_INLINE void set(TDataType*const* items_, PxU32 count_)
00093     {
00094         items = items_;
00095         count = count_;
00096     }
00097 
00101     PX_INLINE void setSingle(TDataType* item_)
00102     {
00103         singleItem = item_;
00104         items = &singleItem;
00105         count = 1;
00106     }
00107 
00108     PX_INLINE bool isValid() const 
00109     { 
00110         if ( count ) 
00111             return items != NULL; 
00112         return items == NULL;
00113     }
00114     
00115     PX_INLINE PxU32 getCount() const { return count; }
00116     PX_INLINE TDataType*const* getItems() const { return items; }
00117 
00118     PX_INLINE TDataType* operator[]( PxU32 idx ) const { return items[idx]; }
00119 };
00120 
00121 struct PxStridedData
00122 {
00128     PxU32 stride;
00129     const void* data;
00130 
00131     PxStridedData() : stride( 0 ), data( NULL ) {}
00132 
00133     template<typename TDataType>
00134     PX_INLINE const TDataType& at( PxU32 idx ) const
00135     {
00136         PxU32 theStride( stride );
00137         if ( theStride == 0 )
00138             theStride = sizeof( TDataType );
00139         PxU32 offset( theStride * idx );
00140         return *(reinterpret_cast<const TDataType*>( reinterpret_cast< const PxU8* >( data ) + offset ));
00141     }
00142 };
00143 
00144 template<typename TDataType>
00145 struct PxTypedStridedData
00146 {
00147     PxU32 stride;
00148     const TDataType* data;
00149 
00150     PxTypedStridedData()
00151         : stride( 0 )
00152         , data( NULL )
00153     {
00154     }
00155 
00156 };
00157 
00158 struct PxBoundedData : public PxStridedData
00159 {
00160     PxU32 count;
00161     PxBoundedData() : count( 0 ) {}
00162 };
00163 
00164 template<PxU8 TNumBytes>
00165 struct PxPadding
00166 {
00167     PxU8 mPadding[TNumBytes];
00168     PxPadding()
00169     {
00170         for ( PxU8 idx =0; idx < TNumBytes; ++idx )
00171             mPadding[idx] = 0;
00172     }
00173 };
00174 
00175 
00176 template <PxU32 NUM_ELEMENTS> class PxFixedSizeLookupTable
00177 {
00178 public:
00179     
00180     PxFixedSizeLookupTable() 
00181         : mNumDataPairs(0)
00182     {
00183     }
00184 
00185     PxFixedSizeLookupTable(const PxReal* dataPairs, const PxU32 numDataPairs)
00186     {
00187         memcpy(mDataPairs,dataPairs,sizeof(PxReal)*2*numDataPairs);
00188         mNumDataPairs=numDataPairs;
00189     }
00190 
00191     PxFixedSizeLookupTable(const PxFixedSizeLookupTable& src)
00192     {
00193         memcpy(mDataPairs,src.mDataPairs,sizeof(PxReal)*2*src.mNumDataPairs);
00194         mNumDataPairs=src.mNumDataPairs;
00195     }
00196 
00197     ~PxFixedSizeLookupTable()
00198     {
00199     }
00200 
00201     PxFixedSizeLookupTable& operator=(const PxFixedSizeLookupTable& src)
00202     {
00203         memcpy(mDataPairs,src.mDataPairs,sizeof(PxReal)*2*src.mNumDataPairs);
00204         mNumDataPairs=src.mNumDataPairs;
00205         return *this;
00206     }
00207 
00208     PX_FORCE_INLINE void addPair(const PxReal x, const PxReal y)
00209     {
00210         PX_ASSERT(mNumDataPairs<NUM_ELEMENTS);
00211         mDataPairs[2*mNumDataPairs+0]=x;
00212         mDataPairs[2*mNumDataPairs+1]=y;
00213         mNumDataPairs++;
00214     }
00215 
00216     PX_FORCE_INLINE PxReal getYVal(const PxReal x) const
00217     {
00218         if(0==mNumDataPairs)
00219         {
00220             PX_ASSERT(false);
00221             return 0;
00222         }
00223 
00224         if(1==mNumDataPairs || x<getX(0))
00225         {
00226             return getY(0);
00227         }
00228 
00229         PxReal x0=getX(0);
00230         PxReal y0=getY(0);
00231 
00232         for(PxU32 i=1;i<mNumDataPairs;i++)
00233         {
00234             const PxReal x1=getX(i);
00235             const PxReal y1=getY(i);
00236 
00237             if((x>=x0)&&(x<x1))
00238             {
00239                 return (y0+(y1-y0)*(x-x0)/(x1-x0));
00240             }
00241 
00242             x0=x1;
00243             y0=y1;
00244         }
00245 
00246         PX_ASSERT(x>=getX(mNumDataPairs-1));
00247         return getY(mNumDataPairs-1);
00248     }
00249 
00250     PxU32 getNumDataPairs() const {return mNumDataPairs;}
00251 
00252 private:
00253 
00254     PxReal mDataPairs[2*NUM_ELEMENTS];
00255     PxU32 mNumDataPairs;
00256     PxU32 mPad[3];
00257 
00258     PX_FORCE_INLINE PxReal getX(const PxU32 i) const
00259     {
00260         return mDataPairs[2*i];
00261     }
00262     PX_FORCE_INLINE PxReal getY(const PxU32 i) const
00263     {
00264         return mDataPairs[2*i+1];
00265     }
00266 };
00267 
00268 #ifndef PX_DOXYGEN
00269 } // namespace physx
00270 #endif
00271 
00273 #endif


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