0
因此,我正在爲我的程序中的汽車編程一些動作。DirectX11相機機芯
我只是增加了XMVECTOR pos
上相機的Z position
?我早些時候做了這個,它向前走,只是開始把相機轉向地面。
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));
感謝這工作對我來說考慮intial只是0? '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);' –