PxCoreUtilityTypes.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3  *
4  * NVIDIA CORPORATION and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA CORPORATION is strictly prohibited.
9  */
10 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12 
13 
14 #ifndef PX_CORE_UTILTY_TYPES_H
15 #define PX_CORE_UTILTY_TYPES_H
16 
20 #include "foundation/PxAssert.h"
21 
22 #ifndef PX_DOXYGEN
23 namespace physx
24 {
25 #endif
26 
27 
29 {
36  const void* data;
37 
38  PxStridedData() : stride( 0 ), data( NULL ) {}
39 
40  template<typename TDataType>
41  PX_INLINE const TDataType& at( PxU32 idx ) const
42  {
43  PxU32 theStride( stride );
44  if ( theStride == 0 )
45  theStride = sizeof( TDataType );
46  PxU32 offset( theStride * idx );
47  return *(reinterpret_cast<const TDataType*>( reinterpret_cast< const PxU8* >( data ) + offset ));
48  }
49 };
50 
51 template<typename TDataType>
53 {
55  const TDataType* data;
56 
58  : stride( 0 )
59  , data( NULL )
60  {
61  }
62 
63 };
64 
66 {
68  PxBoundedData() : count( 0 ) {}
69 };
70 
71 template<PxU8 TNumBytes>
72 struct PxPadding
73 {
74  PxU8 mPadding[TNumBytes];
76  {
77  for ( PxU8 idx =0; idx < TNumBytes; ++idx )
78  mPadding[idx] = 0;
79  }
80 };
81 
82 template <PxU32 NB_ELEMENTS> class PxFixedSizeLookupTable
83 {
84 //= ATTENTION! =====================================================================================
85 // Changing the data layout of this class breaks the binary serialization format. See comments for
86 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
87 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
88 // accordingly.
89 //==================================================================================================
90 public:
91 
93  : mNbDataPairs(0)
94  {
95  }
96 
98 
99  PxFixedSizeLookupTable(const PxReal* dataPairs, const PxU32 numDataPairs)
100  {
101  memcpy(mDataPairs,dataPairs,sizeof(PxReal)*2*numDataPairs);
102  mNbDataPairs=numDataPairs;
103  }
104 
106  {
107  memcpy(mDataPairs,src.mDataPairs,sizeof(PxReal)*2*src.mNbDataPairs);
108  mNbDataPairs=src.mNbDataPairs;
109  }
110 
112  {
113  }
114 
116  {
117  memcpy(mDataPairs,src.mDataPairs,sizeof(PxReal)*2*src.mNbDataPairs);
118  mNbDataPairs=src.mNbDataPairs;
119  return *this;
120  }
121 
122  PX_FORCE_INLINE void addPair(const PxReal x, const PxReal y)
123  {
124  PX_ASSERT(mNbDataPairs<NB_ELEMENTS);
125  mDataPairs[2*mNbDataPairs+0]=x;
126  mDataPairs[2*mNbDataPairs+1]=y;
127  mNbDataPairs++;
128  }
129 
130  PX_FORCE_INLINE PxReal getYVal(const PxReal x) const
131  {
132  if(0==mNbDataPairs)
133  {
134  PX_ASSERT(false);
135  return 0;
136  }
137 
138  if(1==mNbDataPairs || x<getX(0))
139  {
140  return getY(0);
141  }
142 
143  PxReal x0=getX(0);
144  PxReal y0=getY(0);
145 
146  for(PxU32 i=1;i<mNbDataPairs;i++)
147  {
148  const PxReal x1=getX(i);
149  const PxReal y1=getY(i);
150 
151  if((x>=x0)&&(x<x1))
152  {
153  return (y0+(y1-y0)*(x-x0)/(x1-x0));
154  }
155 
156  x0=x1;
157  y0=y1;
158  }
159 
160  PX_ASSERT(x>=getX(mNbDataPairs-1));
161  return getY(mNbDataPairs-1);
162  }
163 
164  PxU32 getNbDataPairs() const {return mNbDataPairs;}
165 
166  void clear()
167  {
168  memset(mDataPairs, 0, NB_ELEMENTS*2*sizeof(PxReal));
169  mNbDataPairs = 0;
170  }
171 
172  PX_FORCE_INLINE PxReal getX(const PxU32 i) const
173  {
174  return mDataPairs[2*i];
175  }
176  PX_FORCE_INLINE PxReal getY(const PxU32 i) const
177  {
178  return mDataPairs[2*i+1];
179  }
180 
181  PxReal mDataPairs[2*NB_ELEMENTS];
183  PxU32 mPad[3];
184 
185 
186 };
187 
188 #ifndef PX_DOXYGEN
189 } // namespace physx
190 #endif
191 
193 #endif


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