00001 #ifndef CONVEX_DECOMPOSITION_H
00002
00003 #define CONVEX_DECOMPOSITION_H
00004
00005 namespace ConvexDecomposition
00006 {
00007
00064 class ConvexResult
00065 {
00066 public:
00067 ConvexResult(void)
00068 {
00069 mHullVcount = 0;
00070 mHullVertices = 0;
00071 mHullTcount = 0;
00072 mHullIndices = 0;
00073 }
00074
00075 ConvexResult(unsigned int hvcount,const double *hvertices,unsigned int htcount,const unsigned int *hindices)
00076 {
00077 mHullVcount = hvcount;
00078 if ( mHullVcount )
00079 {
00080 mHullVertices = new double[mHullVcount*sizeof(double)*3];
00081 memcpy(mHullVertices, hvertices, sizeof(double)*3*mHullVcount );
00082 }
00083 else
00084 {
00085 mHullVertices = 0;
00086 }
00087
00088 mHullTcount = htcount;
00089
00090 if ( mHullTcount )
00091 {
00092 mHullIndices = new unsigned int[sizeof(unsigned int)*mHullTcount*3];
00093 memcpy(mHullIndices,hindices, sizeof(unsigned int)*mHullTcount*3 );
00094 }
00095 else
00096 {
00097 mHullIndices = 0;
00098 }
00099
00100 }
00101
00102 ConvexResult(const ConvexResult &r)
00103 {
00104 mHullVcount = r.mHullVcount;
00105 if ( mHullVcount )
00106 {
00107 mHullVertices = new double[mHullVcount*sizeof(double)*3];
00108 memcpy(mHullVertices, r.mHullVertices, sizeof(double)*3*mHullVcount );
00109 }
00110 else
00111 {
00112 mHullVertices = 0;
00113 }
00114 mHullTcount = r.mHullTcount;
00115 if ( mHullTcount )
00116 {
00117 mHullIndices = new unsigned int[sizeof(unsigned int)*mHullTcount*3];
00118 memcpy(mHullIndices, r.mHullIndices, sizeof(unsigned int)*mHullTcount*3 );
00119 }
00120 else
00121 {
00122 mHullIndices = 0;
00123 }
00124 }
00125
00126 ~ConvexResult(void)
00127 {
00128 delete mHullVertices;
00129 delete mHullIndices;
00130 }
00131
00132
00133 unsigned int mHullVcount;
00134 double * mHullVertices;
00135 unsigned int mHullTcount;
00136 unsigned int *mHullIndices;
00137
00138 double mHullVolume;
00139
00140 };
00141
00142
00143 class FConvexResult
00144 {
00145 public:
00146 FConvexResult(const ConvexResult &r)
00147 {
00148 mHullVcount = r.mHullVcount;
00149 mHullVertices = 0;
00150 if ( mHullVcount )
00151 {
00152 mHullVertices = new float[mHullVcount*3];
00153
00154 const double *src = r.mHullVertices;
00155 float * dest = mHullVertices;
00156 for (unsigned int i=0; i<mHullVcount; i++)
00157 {
00158 dest[0] = (float) src[0];
00159 dest[1] = (float) src[1];
00160 dest[2] = (float) src[2];
00161 src+=3;
00162 dest+=3;
00163 }
00164 }
00165 mHullTcount = r.mHullTcount;
00166 if ( mHullTcount )
00167 {
00168 mHullIndices = new unsigned int[mHullTcount*3];
00169 memcpy(mHullIndices,r.mHullIndices,sizeof(unsigned int)*mHullTcount*3);
00170 }
00171 else
00172 {
00173 mHullIndices = 0;
00174 }
00175 mHullVolume = (float)r.mHullVolume;
00176 }
00177
00178 ~FConvexResult(void)
00179 {
00180 delete mHullVertices;
00181 delete mHullIndices;
00182 }
00183
00184 unsigned int mHullVcount;
00185 float * mHullVertices;
00186 unsigned int mHullTcount;
00187 unsigned int *mHullIndices;
00188 float mHullVolume;
00189 };
00190
00191 class ConvexDecompInterface
00192 {
00193 public:
00194
00195 virtual void ConvexDebugTri(const double *p1,const double *p2,const double *p3,unsigned int color) { };
00196 virtual void ConvexDebugPoint(const double *p,double dist,unsigned int color) { };
00197 virtual void ConvexDebugBound(const double *bmin,const double *bmax,unsigned int color) { };
00198 virtual void ConvexDebugOBB(const double *sides, const double *matrix,unsigned int color) { };
00199
00200 virtual void ConvexDecompResult(ConvexResult &result) = 0;
00201
00202
00203
00204 };
00205
00206
00207
00208 class DecompDesc
00209 {
00210 public:
00211 DecompDesc(void)
00212 {
00213 mVcount = 0;
00214 mVertices = 0;
00215 mTcount = 0;
00216 mIndices = 0;
00217 mDepth = 5;
00218 mCpercent = 5;
00219 mPpercent = 5;
00220 mMaxVertices = 32;
00221 mSkinWidth = 0;
00222 mCallback = 0;
00223 }
00224
00225
00226 unsigned int mVcount;
00227 const double *mVertices;
00228 unsigned int mTcount;
00229 unsigned int *mIndices;
00230
00231
00232 unsigned int mDepth;
00233 double mCpercent;
00234 double mPpercent;
00235
00236
00237 unsigned int mMaxVertices;
00238 double mSkinWidth;
00239
00240 ConvexDecompInterface *mCallback;
00241
00242 };
00243
00244
00245 unsigned int performConvexDecomposition(const DecompDesc &desc);
00246
00247 };
00248
00249 #endif