Game Development Reference
In-Depth Information
::MessageBox(0, "D3DXGeneratePMesh() - FAILED", 0, 0);
return false;
}
Note that while we request to simplify the mesh down to one face, this
will usually not occur due to vertex/attribute weights; however, speci-
fying 1 will reduce the mesh to its lowest resolution.
At this point, the progressive mesh has been generated but if we
render it now, it will be rendered at its lowest resolution. Because we
want to initially render the mesh at full resolution, we set it to:
// set to original (full) detail
DWORD maxFaces = PMesh->GetMaxFaces();
PMesh->SetNumFaces(maxFaces);
In the Display function, we test for an A keypress and an S keypress
and handle the input accordingly:
bool Display(float timeDelta)
{
if( Device )
{
//
// Update: Mesh resolution.
//
// Get the current number of faces the pmesh has.
int numFaces = PMesh->GetNumFaces();
// Add a face, note the SetNumFaces() will automatically
// clamp the specified value if it goes out of bounds.
if( ::GetAsyncKeyState('A') & 0x8000f )
{
// Sometimes we must add more than one face to invert
// an edge collapse transformation because of the internal
// implementation details of the ID3DXPMesh interface. In
// other words, adding one face may possibly result in a
// mesh with the same number of faces as before. Thus to
// increase the face count we may sometimes have to add
// two faces at once.
PMesh->SetNumFaces(numFaces + 1);
if(PMesh->GetNumFaces() == numFaces)
PMesh->SetNumFaces(numFaces + 2);
}
// Remove a face, note the SetNumFaces() will automatically
// clamp the specified value if it goes out of bounds.
if(::GetAsyncKeyState('S') & 0x8000f)
PMesh->SetNumFaces(numFaces - 1);
This is straightforward, but notice that when adding a face we must
sometimes add two faces in order to invert an edge collapse
transformation.
Search WWH ::




Custom Search