|
void CDocView:isplayEnumBodiesTessellation (CComPtr <IEnumBodies2> pEnumBody)
{
try
{
HRESULT hr = S_OK;
CComPtr <IBody2> pBody;
CComPtr <IEnumFaces2> pEnumFaces;
CComPtr <IFace2> pFace;
long nFetchedBodies = -1;
long nFetchedFaces = -1;
long nNumTessTriang = -1;
float* pTessTriang = NULL;
long i = 0;
hr = pEnumBody->Reset();
hr = pEnumBody->Next(1, &pBody, &nFetchedBodies);
while (nFetchedBodies > 0)
{
hr = pBody->EnumFaces(&pEnumFaces);
_ASSERT(pEnumFaces);
// set colour to blue
AutoColor Color(0, 0, 128);
// set line width to 1 pixel
AutoLineWidth LineWidth(1.0);
// get the first face
hr = pEnumFaces->Reset();
hr = pEnumFaces->Next(1, &pFace, &nFetchedFaces);
while (nFetchedFaces > 0)
{
// get display tessellation for this face
hr = pFace->GetTessTriangleCount(&nNumTessTriang);
_ASSERT(nNumTessTriang > 0);
pTessTriang = new float[9 * sizeof(float) * nNumTessTriang];
_ASSERT(pTessTriang);
ZeroMemory(pTessTriang, 9 * sizeof(float) * nNumTessTriang);
hr = pFace->IGetTessTriangles(VARIANT_TRUE, pTessTriang);
_ASSERT(pTessTriang);
// draw display tessellation
glBegin(GL_LINE_STRIP);
{
for (i = 0; i < nNumTessTriang; i++)
{
glVertex3f
(
pTessTriang[9 * i + 0],
pTessTriang[9 * i + 1],
pTessTriang[9 * i + 2]
);
glVertex3f
(
pTessTriang[9 * i + 3],
pTessTriang[9 * i + 4],
pTessTriang[9 * i + 5]
);
glVertex3f
(
pTessTriang[9 * i + 6],
pTessTriang[9 * i + 7],
pTessTriang[9 * i + 8]
);
}
}
glEnd();
delete [] pTessTriang;
// reset current face and get the next face
pFace = NULL;
hr = pEnumFaces->Next(1, &pFace, &nFetchedFaces);
}
// reset face enumerator
pEnumFaces = NULL;
// reset current body and get the next body
pBody = NULL;
hr = pEnumBody->Next(1, &pBody, &nFetchedBodies);
}
}
catch (...)
{
DebugBreak();
}
} |
|