bool Display(float timeDelta) { if( Device ) { // // Update the scene: // static float radius = 20.0f; if( ::GetAsyncKeyState(VK_LEFT) & 0x8000f ) TeapotPosition.x -= 3.0f * timeDelta; if( ::GetAsyncKeyState(VK_RIGHT) & 0x8000f ) TeapotPosition.x += 3.0f * timeDelta; if( ::GetAsyncKeyState(VK_UP) & 0x8000f ) radius -= 2.0f * timeDelta; if( ::GetAsyncKeyState(VK_DOWN) & 0x8000f ) radius += 2.0f * timeDelta; static float angle = (3.0f * D3DX_PI) / 2.0f; if( ::GetAsyncKeyState('A') & 0x8000f ) angle -= 0.5f * timeDelta; if( ::GetAsyncKeyState('S') & 0x8000f ) angle += 0.5f * timeDelta; D3DXVECTOR3 position( cosf(angle) * radius, 3.0f, sinf(angle) * radius ); D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMATRIX V; D3DXMatrixLookAtLH(&V, &position, &target, &up); Device->SetTransform(D3DTS_VIEW, &V); // // Draw the scene: // Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, 0xff000000, 1.0f, 0L); Device->BeginScene(); RenderScene(); RenderMirror(); Device->EndScene(); Device->Present(0, 0, 0, 0); } return true; }
void Render() { static float radius = 20.0f; float timeDelta = 0.1001; if (::GetAsyncKeyState(VK_LEFT) & 0x8000f) g_teapotPosition.x -= 3.0f * timeDelta; if (::GetAsyncKeyState(VK_RIGHT) & 0x8000f) g_teapotPosition.x += 3.0f * timeDelta; if (::GetAsyncKeyState(VK_UP) & 0x8000f) // radius -= 2.0f * timeDelta; g_teapotPosition.z += 3.0f * timeDelta; if (::GetAsyncKeyState(VK_DOWN) & 0x8000f) // radius += 2.0f * timeDelta; g_teapotPosition.z -= 3.0f * timeDelta; static float angle = (3.0f * D3DX_PI) / 2.0f; if (::GetAsyncKeyState('A') & 0x8000f) angle -= 0.5f * timeDelta; if (::GetAsyncKeyState('D') & 0x8000f) angle += 0.5f * timeDelta; D3DXVECTOR3 position(cosf(angle) * radius, 3.0f, sinf(angle) * radius); D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMATRIX V; D3DXMatrixLookAtLH(&V, &position, &target, &up); g_pDevice->SetTransform(D3DTS_VIEW, &V); g_pDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, 0xff000000, 1.0f, 0); g_pDevice->BeginScene(); g_pDevice->SetMaterial(&g_materalTeapot); g_pDevice->SetTexture(0, 0); D3DXMATRIX W; D3DXMatrixTranslation(&W, g_teapotPosition.x, g_teapotPosition.y, g_teapotPosition.z); g_pDevice->SetTransform(D3DTS_WORLD, &W); g_pMeshTeapot->DrawSubset(0); D3DXMATRIX I; D3DXMatrixIdentity(&I); g_pDevice->SetTransform(D3DTS_WORLD, &I); g_pDevice->SetStreamSource(0, g_pVertexBuffer, 0, sizeof(Vertex)); g_pDevice->SetFVF(Vertex::FVF); g_pDevice->SetTexture(0, g_pTextureFloor); g_pDevice->SetMaterial(&g_materialFloor); g_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); g_pDevice->SetTexture(0, g_pTextureWall); g_pDevice->SetMaterial(&g_materialWall); g_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 6, 4); g_pDevice->SetTexture(0, g_pTextureMirror); g_pDevice->SetMaterial(&g_materialMirror); g_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 18, 2); RenderMirror(); g_pDevice->EndScene(); g_pDevice->Present(0, 0, 0, 0); }