We had to create this during our intro to 3D Programming course while in college, this is a snippet of the code, featuring the one of the loops that I used to get everything going.
while( msg.message!=WM_QUIT )
{
// check for messages
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
// this is called when no messages are pending
else
{
// call our render function
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0f, 0 );
pd3dDevice->BeginScene();
D3DXMATRIX meshMat, meshScale, meshRotate;
// create the camera
createCamera(1.0f, 750.0f); // near clip plane, far clip plane
moveCamera(D3DXVECTOR3(0.0f, 0.0f, -5.0f));
pointCamera(D3DXVECTOR3(0.0f, 0.0f, 0.0f));
// set the rotation
D3DXMatrixRotationY(&meshRotate, timeGetTime()/1000.0f);
// set the scaling
D3DXMatrixScaling(&meshScale, 1.0f, 1.0f, 1.0f);
// multiple the scaling and rotation matrices to create the meshMat matrix
D3DXMatrixMultiply(&meshMat, &meshScale, &meshRotate);
// transform the object in world space
pd3dDevice->SetTransform(D3DTS_WORLD, &meshMat);
// set the material to use
pd3dDevice->SetMaterial(&mtrl);
// draw the teapot mesh
teapotMesh->DrawSubset(0);
pd3dDevice->EndScene();
pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
}
// shutdown the directx manager
shutdown();