私はd3d開発の初心者であり、最初の問題で立ち往生しています。各頂点にランダムな高さの地形と、左から右に移動するライト(および基本的なキーボード管理)を描画する小さなプログラムを作成しました。問題は、アニメーション化されたライトが非常にスキップされ、入力認識がかなり頻繁に失敗し、CPU使用率が50%一定であるということです(私はデュアルコアCPUを使用しています)。この問題の原因はスロットリングの誤りだと思いましたが、コードを修正した後でも問題が発生します。私のメインループは
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
HWND wndHandle;
int width = 640;
int height = 480;
wndHandle = InitWindow(hInstance, width, height);
InitDirect3D(wndHandle, width, height);
DInputInit(hInstance, wndHandle);
SceneSetUp();
MSG msg = {0};
QueryPerformanceFrequency((LARGE_INTEGER *) &perf_cnt);
time_count = perf_cnt / fixedtic;
QueryPerformanceCounter((LARGE_INTEGER *) &next_time);
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
continue;
}
HandleInput();
QueryPerformanceCounter((LARGE_INTEGER *) &cur_time);
if (cur_time>next_time) {
Render();
next_time += time_count;
if (next_time < cur_time)
next_time = cur_time + time_count;
}
}
ShutdownDirect3D();
return (int)msg.wParam;
}
レンダリング機能は
void Render()
{
QueryPerformanceCounter((LARGE_INTEGER *) &curtime);
timespan = (curtime - last_time) * time_factor;
last_time = curtime;
model.pD3DDevice->ClearRenderTargetView(model.pRenderTargetView, D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f));
lightpos.x = (float)cos(ang) * 256.0f;
ang += timespan * 0.5;
lpvar->SetFloatVector((float *) lightpos);
D3DXMatrixLookAtLH(&V, &model.campos, new D3DXVECTOR3(0.0f, 0.0f, 0.0f), new D3DXVECTOR3(0.0f, 1.0f, 0.0f));
D3DXMATRIX VP = V*P;
camvar->SetFloatVector((float *)model.campos);
ViewProjection->SetMatrix((float *) &VP);
for(UINT p=0; p < techniqueDescription.Passes; ++p)
{
pTechnique->GetPassByIndex(p)->Apply(0);
model.pD3DDevice->DrawIndexed(numIndices, 0, 0);
}
model.pSwapChain->Present(0, 0);
}
どんな助けでも大歓迎です