Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void SetupTestVertices(ID3D11Device *pd3dDevice) {
- SimpleVertex *ptrV;
- int i;
- float *ptrToPoints;
- float scaleFactor = 1.f / (MAX_RAND * 0.5f); // the test points are from 0 to MAX_RAND, so scale to 0 to 1.0
- int xyOffset = (MAX_RAND / 2);
- float brightness; // to make the triangles visually different from one another
- std::vector<R3> pts, pts2;
- // to make the triangles visually different from one another
- // create a random set of points to test the triangulation fuction
- if (g_numTestPoints > MAX_TEST_POINTS) g_numTestPoints = MAX_TEST_POINTS;
- if (g_numTestPoints < 4) g_numTestPoints = 4;
- ptrToPoints = testPointsXY;
- for (i = (g_numTestPoints * NUM_DIMENSIONS); i> 0; i--) {
- *ptrToPoints++ = ((rand() % MAX_RAND) - xyOffset) * scaleFactor;
- }
- for (int i = 0; i < g_numTestPoints* NUM_DIMENSIONS; i++)
- {
- R3 pt;
- pt.c = testPointsXY[i];
- pt.r = testPointsXY[(i*3)+1];
- pt.z = testPointsXY[(i*3)+2];
- pts.push_back(pt);
- }
- std::vector<Tri> tris;
- //
- int ts = NewtonApple_Delaunay(pts, tris);
- // put those random points into a buffer for display
- ptrV = testvertexes;
- ptrToPoints = testPointsXY;
- for (i = 0; i < 30; i++) {
- // scale to between -1 and +1 since that all that this tutorial program was designed to show
- ptrV->Pos.x = pts[i].r;
- ptrV->Pos.y = pts[i].c;
- if (NUM_DIMENSIONS == 3) ptrV->Pos.z = pts[i].z;
- else ptrV->Pos.z = 0;
- // give the nodes different colors to make it easier to distinguish between the triangles, especially when they are filled
- brightness = (float)i / (float)30;
- ptrV->Color.x = brightness;
- ptrV->Color.y = brightness * 0.2f;
- ptrV->Color.z = brightness * 0.6f;
- ptrV->Color.w = 1.f;
- ptrV++;
- }
- std::vector<WORD> triangeList;
- triangeList.resize(tris.size() * 3);
- for (int i = 0; i < tris.size(); i++)
- {
- triangeList[i*3] = tris[i].a;
- triangeList[(i*3)+1] = tris[i].b;
- triangeList[(i*3)+2] = tris[i].c;
- }
- std::vector<WORD> lineIndex;
- lineIndex.resize(tris.size()*3*sizeof(WORD));
- int l, t;
- for (l = 0, t = 0; t<tris.size()*3; t += 3) {
- // Each triangle has 3 lines, so D3D_PRIMITIVE_TOPOLOGY_LINELIST needs 6 vertices
- // Each vertex has to be listed twice
- lineIndex[l] = triangeList[t]; l++;
- lineIndex[l] = triangeList[t + 1]; l++;
- lineIndex[l] = triangeList[t + 1]; l++;
- lineIndex[l] = triangeList[t + 2]; l++;
- lineIndex[l] = triangeList[t + 2]; l++;
- lineIndex[l] = triangeList[t]; l++;
- }
- ReleaseD3D_Buffers(); // from the previous cycle
- // Fill in a buffer description for the triangle vertices
- D3D11_BUFFER_DESC bd;
- ZeroMemory(&bd, sizeof(bd));
- bd.Usage = D3D11_USAGE_DEFAULT;
- bd.ByteWidth = sizeof(SimpleVertex) * g_numTestPoints;
- bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
- // Fill in the subresource data
- D3D11_SUBRESOURCE_DATA InitData;
- ZeroMemory(&InitData, sizeof(InitData));
- InitData.pSysMem = testvertexes;
- pd3dDevice->CreateBuffer(&bd, &InitData, &g_pTestVector);
- // Fill in a buffer description for filled triangles
- ZeroMemory(&bd, sizeof(bd));
- bd.Usage = D3D11_USAGE_DEFAULT;
- bd.ByteWidth = tris.size()*sizeof(WORD); // <---- numTriangleVertices comes from the function
- bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
- bd.CPUAccessFlags = 0;
- ZeroMemory(&InitData, sizeof(InitData));
- InitData.pSysMem = static_cast<void *>(triangeList.data()); // <---- triangleIndexList is from the function also
- pd3dDevice->CreateBuffer(&bd, &InitData, &g_pTestVectorIndexBuffer);
- // Fill in a buffer description for drawing only the triangle outlines
- ZeroMemory(&bd, sizeof(bd));
- bd.Usage = D3D11_USAGE_DEFAULT;
- bd.ByteWidth = lineIndex.size(); // <---- from the function
- bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
- bd.CPUAccessFlags = 0;
- ZeroMemory(&InitData, sizeof(InitData));
- InitData.pSysMem = static_cast<void *>(lineIndex.data());
- pd3dDevice->CreateBuffer(&bd, &InitData, &g_pTriOutlineIndexBuffer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement