static void RenderDebugPolygon(void* userData, int alVertexCount, const dFloat* apFaceVertex, int alId) { int i; i = alVertexCount - 1; cVector3f vP0(apFaceVertex[i * 3 + 0], apFaceVertex[i * 3 + 1], apFaceVertex[i * 3 + 2]); for (i = 0; i < alVertexCount; ++i) { cVector3f vP1 (apFaceVertex[i * 3 + 0], apFaceVertex[i * 3 + 1], apFaceVertex[i * 3 + 2]); gpLowLevelGraphics->DrawLine(vP0, vP1,gDebugColor); vP0 = vP1; } }
static void RenderDebugPolygon(void *a_pVoid, int a_lVertexCount, const dFloat *a_pFaceVertex, int a_lId) { int i; i = a_lVertexCount - 1; cVector3f vP0(a_pFaceVertex[i * 3 + 0], a_pFaceVertex[i * 3 + 1], a_pFaceVertex[i * 3 + 2]); for (int i = 0; i < a_lVertexCount; ++i) { cVector3f vP1(a_pFaceVertex[i * 3 + 0], a_pFaceVertex[i * 3 + 1], a_pFaceVertex[i * 3 + 2]); g_pLowLevelGraphics->DrawLine(vP0, vP1, g_DebugColor); vP0 = vP1; } }
void cCollideShapeNewton::CreateFromVertices(const unsigned int* apIndexArray, int alIndexNum, const float *apVertexArray, int alVtxStride, int alVtxNum) { float vTriVec[9]; bool bOptimize = false; bool bCreatedPlane = false; cPlanef plane; mpNewtonCollision = NewtonCreateTreeCollision(mpNewtonWorld, NULL); //Log("-- Creating mesh collision.:\n"); NewtonTreeCollisionBeginBuild(mpNewtonCollision); for(int tri = 0; tri < alIndexNum; tri+=3) { //Log("tri: %d:\n", tri/3); for(int idx =0; idx < 3; idx++) { int lVtx = apIndexArray[tri + 2-idx]*alVtxStride; vTriVec[idx*3 + 0] = apVertexArray[lVtx + 0]; vTriVec[idx*3 + 1] = apVertexArray[lVtx + 1]; vTriVec[idx*3 + 2] = apVertexArray[lVtx + 2]; } if(bOptimize==false) { cPlanef tempPlane; cVector3f vP1(vTriVec[0+0],vTriVec[0+1],vTriVec[0+2]); cVector3f vP2(vTriVec[1*3+0],vTriVec[1*3+1],vTriVec[1*3+2]); cVector3f vP3(vTriVec[2*3+0],vTriVec[2*3+1],vTriVec[2*3+2]); tempPlane.FromPoints(vP1, vP2, vP3); //Log("P1: %s P2: %s P3: %s\n",vP1.ToString().c_str(),vP2.ToString().c_str(),vP3.ToString().c_str()); //Log("Plane: a: %f b: %f c: %f d: %f\n",tempPlane.a,tempPlane.b,tempPlane.c,tempPlane.d); if(bCreatedPlane==false){ plane = tempPlane; bCreatedPlane = true; } else { if( std::abs(plane.a - tempPlane.a) > 0.001f || std::abs(plane.b - tempPlane.b) > 0.001f || std::abs(plane.c - tempPlane.c) > 0.001f || std::abs(plane.d - tempPlane.d) > 0.001f ) { bOptimize = true; } } } NewtonTreeCollisionAddFace(mpNewtonCollision,3,vTriVec,sizeof(float)*3,1); } NewtonTreeCollisionEndBuild(mpNewtonCollision, bOptimize ? 1: 0); //Set bounding box size mBoundingVolume.AddArrayPoints(apVertexArray, alVtxNum); mBoundingVolume.CreateFromPoints(alVtxStride); }