Directx 9相机设置

时间:2015-04-02 08:53:42

标签: directx

我在directx9下配置我的相机设置,我所获得的是能够查看180度,但我无法达到360.这是代码:

float x = 0;
float y = 0;
float z = 10;
float dx = 0;
float dy = 0;
void FreeMotion()
{
    if(::GetAsyncKeyState('W') )
    {
        z -= 0.3;
    }
    if(::GetAsyncKeyState('S') )
    {
        z += 0.3;
    }
    if(::GetAsyncKeyState('A') )
    {
        x += 0.7;
    }
    if(::GetAsyncKeyState('D') )
    {
        x -= 0.1;
    }
    if(::GetAsyncKeyState('R') )
    {
        y += 0.1;
    }
    if(::GetAsyncKeyState('F') )
    {
        y -= 0.1;
    }
    if(::GetAsyncKeyState(VK_RIGHT) )
    {
        dx -= 0.1;
    }
    if(::GetAsyncKeyState(VK_LEFT) )
    {
        dx += 0.1;
    }
    if(::GetAsyncKeyState(VK_UP) )
    {
        dy += 0.1;
    }
    if(::GetAsyncKeyState(VK_DOWN) )
    {
        dy -= 0.1;
    }
}
void render()
{

    d3ddev->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRBG(0,0,0),1.0,0);
    d3ddev->BeginScene();
FreeMotion();
        D3DXMATRIX View;
        D3DXMatrixLookAtLH(&View,&D3DXVECTOR3(x,y,z),&D3DXVECTOR3(x+dx,y+dy,z-10),&D3DXVECTOR3(0,1,0));
        d3ddev->SetTransform(D3DTS_VIEW,&View);

...

所以这段代码让我有能力四处走动而不是向后看! 有人可以告诉我如何让它看起来整整360度?

1 个答案:

答案 0 :(得分:0)

我认为将dxdy解释为旋转角度更有意义。然后,您将计算视图目标:

target = (x, y, z) + (sin(dx) * cos(dy), sin(dy), -cos(dx) * cos(dy))

D3DXMatrixLookAtLH来电中更新此计算,您应该获得360°。