2014-03-26 4 views
0

그래서 나는 내 프로그램에서 가지고있는 자동차의 움직임을 프로그래밍하고 있었다.DirectX11 카메라 움직임

카메라의 Z positionXMVECTOR pos으로 늘리면됩니까? 나는 이것을 더 일찍했고 앞으로 나아 갔고 모두 카메라를 땅쪽으로 향하기 시작했습니다.

XMVECTOR pos = XMVectorSet(x, y, z + mCarTranslation.z, 1.0f);

은 어쨌든 여기 내 코드의 일부입니다.

/ Convert Spherical to Cartesian coordinates. 
float x = mRadius*sinf(mPhi)*cosf(mTheta); 
float z = mRadius*sinf(mPhi)*sinf(mTheta); 
float y = mRadius*cosf(mPhi); 

mEyePosW = XMFLOAT3(x, y, z); 

// Build the view matrix. 
XMVECTOR pos = XMVectorSet(x, y, z, 1.0f); 
XMVECTOR target = XMVectorZero(); 
XMVECTOR up  = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); 

XMMATRIX V = XMMatrixLookAtLH(pos, target, up); 
XMStoreFloat4x4(&mView, V); 

// Button down event. 
if (GetAsyncKeyState('W') & 0x8000) 
{ 
    mCarTranslation.z += -4.0f*dt; 
} 
if(GetAsyncKeyState('S') & 0x8000) 
{ 
    mCarTranslation.z += 2.0f*dt; 
} 
if(GetAsyncKeyState('A') & 0x8000) 
{ 
    mCarTranslation.x += 1.0f*dt; 
} 
if(GetAsyncKeyState('D') & 0x8000) 
{ 
    mCarTranslation.x += -1.0f*dt; 
} 

XMMATRIX carScale = XMMatrixScaling(0.5f, 0.5f, 0.5f); 
XMMATRIX carOffset = XMMatrixTranslation(mCarTranslation.x, mCarTranslation.y, mCarTranslation.z); 
XMStoreFloat4x4(&mCarWorld, XMMatrixMultiply(carScale, carOffset)); 

답변

0

카메라는 매트릭스에 동일한 목표 위치 (0,0,0)와 모든 프레임을 재생성하고 있기 때문에 지상을 향해 회전 끝난다. 동일한 방향을 유지하려면 목표 위치를 눈 위치에 상대적으로 설정해야합니다 (예 : target = XMVectorSet(x - xInitial, y - yInitial, z - zInitial, 1.0f)).

+0

내게 intial을 고려해 주셔서 감사합니다. 'XMVECTOR pos = XMVectorSet (x + mCarTranslation.x, y + mCarTranslation.y, z + mCarTranslation.z, 1.0f); \t XMVECTOR target = XMVectorSet (mCarTranslation.x, mCarTranslation.y, mCarTranslation.z, 1.0f);' –