Game Development Reference
In-Depth Information
In the Display function we rotate the mesh slightly every frame so
that it spins. The mesh can be rendered trivially using a simple loop
since the subsets are labeled in the order 0, 1, 2, …, n-1 , where n is
the number of subsets:
bool Display(float timeDelta)
{
if( Device )
{
//
// Update: Rotate the mesh.
//
static float y = 0.0f;
D3DXMATRIX yRot;
D3DXMatrixRotationY(&yRot, y);
y += timeDelta;
if( y >= 6.28f )
y = 0.0f;
D3DXMATRIX World = yRot;
Device->SetTransform(D3DTS_WORLD, &World);
//
// Render
//
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
0xffffffff, 1.0f, 0);
Device->BeginScene();
for(inti=0;i<Mtrls.size(); i++)
{
Device->SetMaterial( &Mtrls[i] );
Device->SetTexture(0, Textures[i]);
Mesh->DrawSubset(i);
}
Device->EndScene();
Device->Present(0, 0, 0, 0);
}
return true;
}
11.2.4 Generating Vertex Normals
It is possible that an XFile does not contain vertex normal data. If this
is the case, it may be necessary to compute the vertex normals manu-
ally so that we can use lighting. We briefly outlined how to do this way
back in Chapter 5. However, now that we know about the ID3DXMesh
Team-Fly ®
Search WWH ::




Custom Search