Hi. I've recently started learning graphics programming using DirectX. I'm trying to implement a free camera and struggling with building the View matrix.
I'm using the left-hand coordinate system. The “up” vector is Z+, the “forward” vector is Y+, and if I'm not mistaken my X+ axis will be the left vector.
I'm initializing my "up", "forward" and "left" vectors accordingly. Then, I'm trying to build a view matrix with them but getting wrong results (I should see a cube in front of me and a floor under me, XMMatrixLookToLH solves the problems but I want to do it myself), I think I'm missing something in the cross product part. Could somebody help a noob? :)
DirectX::XMVECTOR L = DirectX::XMLoadFloat3(&vLeftVector);
DirectX::XMVECTOR U = DirectX::XMLoadFloat3(&vUpVector);
DirectX::XMVECTOR F = DirectX::XMLoadFloat3(&vForwardVector);
DirectX::XMVECTOR P = DirectX::XMLoadFloat3(&vLocation);
F = DirectX::XMVector3Normalize(F);
U = DirectX::XMVector3Normalize(DirectX::XMVector3Cross(L, F));
L = DirectX::XMVector3Cross(F, U);
float x = -DirectX::XMVectorGetX(DirectX::XMVector3Dot(P, L));
float y = -DirectX::XMVectorGetX(DirectX::XMVector3Dot(P, F));
float z = -DirectX::XMVectorGetX(DirectX::XMVector3Dot(P, U));
DirectX::XMStoreFloat3(&vLeftVector, L);
DirectX::XMStoreFloat3(&vUpVector, U);
DirectX::XMStoreFloat3(&vForwardVector, F);
mView(0, 0) = vLeftVector.x;
mView(1, 0) = vLeftVector.y;
mView(2, 0) = vLeftVector.z;
mView(3, 0) = x;
mView(0, 1) = vForwardVector.x;
mView(1, 1) = vForwardVector.y;
mView(2, 1) = vForwardVector.z;
mView(3, 1) = y;
mView(0, 2) = vUpVector.x;
mView(1, 2) = vUpVector.y;
mView(2, 2) = vUpVector.z;
mView(3, 2) = z;
mView(0, 3) = 0.0f;
mView(1, 3) = 0.0f;
mView(2, 3) = 0.0f;
mView(3, 3) = 1.0f;