I begin to learn graphic programming on directx12. I try to make a camera wich can move dans rotate around the world.
I take this code as a basis: https://www.braynzarsoft.net/viewtutorial/q16390-transformations-and-world-view-projection-space-matrices
I try lot of method, but every time I finish on the same problem, my camera move and can rotate (on Y only for the moment). But when I move after the control still relative to my basis orientation than my new one.
I dunno if it come from how I handle movement (During waiting answer I will try to make my movement base on a target vector) Or how I multiply martix.
This is the actual point of my code. I use this source to not use LookAtLH(): https://www.3dgep.com/understanding-the-view-matrix/
void UpdateCamera() {
XMVECTOR cUp = XMLoadFloat4(&cameraUp);
if (GetAsyncKeyState('Z')) {
cameraPosition.y += 0.001f;
}
else if (GetAsyncKeyState('S')) {
cameraPosition.y -= 0.001f;
}
if (GetAsyncKeyState('Q')) {
cameraPosition.x -= 0.001f;
}
else if (GetAsyncKeyState('D')) {
cameraPosition.x += 0.001f;
}
if (GetAsyncKeyState('A')) {
rotation += 0.0001f;
}
else if (GetAsyncKeyState('E')) {
rotation -= 0.0001f;
}
if (GetAsyncKeyState('P')) {
cameraPosition.z += 0.001f;
}
else if (GetAsyncKeyState('M')) {
cameraPosition.z -= 0.001f;
}
XMMATRIX translationMat = XMMatrixTranslationFromVector(XMLoadFloat4(&cameraPosition));
/* XMMATRIX rotYMat = XMMatrixRotationAxis(cUp, rotation);*/
float cosPitch = cos(0.0f);
float sinPitch = sin(0.0f);
float cosYaw = cos(rotation);
float sinYaw = sin(rotation);
XMFLOAT3 xaxis = { cosYaw, 0, -sinYaw };
XMFLOAT3 yaxis = { sinYaw * sinPitch, cosPitch, cosYaw * sinPitch };
XMFLOAT3 zaxis = { sinYaw * cosPitch, -sinPitch, cosPitch * cosYaw };
XMVECTOR eye = XMLoadFloat4(&cameraPosition);
// Create a 4x4 view matrix from the right, up, forward and eye position vectors
XMMATRIX viewMatrix = {
xaxis.x,yaxis.x,zaxis.x,0.0f,
xaxis.y,yaxis.y,zaxis.y,0.0f,
xaxis.z,yaxis.z,zaxis.z,00.0f,
-XMVectorGetX(XMVector3Dot(XMLoadFloat3(&xaxis), eye)), -XMVectorGetX(XMVector3Dot(XMLoadFloat3(&yaxis), eye)), -XMVectorGetX(XMVector3Dot(XMLoadFloat3(&zaxis), eye)), 1.0f
};
XMStoreFloat4x4(&cameraViewMat, viewMatrix);// XMMatrixInverse(nullptr, translationMat * rotXMat));
}
void Update()
{
UpdateCamera();
///....
}