请教:一个游戏中旋转移动摄像机位置的问题
pdiy 2005-06-16 08:09:29 注:这个代码摘自([Introduction to 3D Game Programming with DirectX 9.0][EN])
这段代码的作用是改变摄像机的位置,但请问下面代码中的
这些
static float angle = (3.0f * D3DX_PI) / 2.0f; //这是什么意思?
D3DXVECTOR3 position( cosf(angle) * 3.0f, height, sinf(angle) * 3.0f ); //这个呢
对应的是什么公式?
bool Display(float timeDelta)
{
if( Device )
{
//
// Update the scene: update camera position.
//
static float angle = (3.0f * D3DX_PI) / 2.0f;
static float height = 2.0f;
if( ::GetAsyncKeyState(VK_LEFT) & 0x8000f )
angle -= 0.5f * timeDelta;
if( ::GetAsyncKeyState(VK_RIGHT) & 0x8000f )
angle += 0.5f * timeDelta;
D3DXVECTOR3 position( cosf(angle) * 3.0f, height, sinf(angle) * 3.0f );
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, 0xffffffff, 1.0f, 0);
Device->BeginScene();
Device->SetMaterial(&d3d::WHITE_MTRL);
Device->SetTexture(0, Tex);
Box->draw(0, 0, 0);
Device->EndScene();
Device->Present(0, 0, 0, 0);
}
return true;
}