Hi guys,
I have created a simple 3D perspective camera for my project. Which is rendering a simple triangle correctly as anticipated.
I am wondering how to go about setting the 'look at' position.
This is my main code:
// CAMERA
XMMATRIX viewMatrix = XMMatrixIdentity();
XMMATRIX projMatrix = XMMatrixPerspectiveFovLH(60.0f * 0.0174533f, float((float)nWidth) / ((float)nHeight), 1.0f, 1000.0f);
viewMatrix = XMMatrixTranspose(viewMatrix);
projMatrix = XMMatrixTranspose(projMatrix);
// position the camera
XMMATRIX rotationMatrix = XMMatrixRotationZ(0.0f);
XMMATRIX translationMatrix = XMMatrixTranslation(0.0f, 0.0f, 0.0f);
XMMATRIX worldMat = rotationMatrix*translationMatrix;
worldMat = XMMatrixTranspose(worldMat);
d3dContext->UpdateSubresource(worldCB, 0, 0, &worldMat, 0, 0);
d3dContext->UpdateSubresource(viewCB, 0, 0, &viewMatrix, 0, 0);
d3dContext->UpdateSubresource(projCB, 0, 0, &projMatrix, 0, 0);
d3dContext->VSSetConstantBuffers(0, 1, &worldCB);
d3dContext->VSSetConstantBuffers(1, 1, &viewCB);
d3dContext->VSSetConstantBuffers(2, 1, &projCB);
This is the vertex part of my shader:
struct VS_Input
{
float4 pos : POSITION;
};
struct VS_Output
{
float4 pos : SV_POSITION;
};
VS_Output VShader(VS_Input IN)
{
VS_Output OUT;
matrix mvp = mul(projectionMatrix, mul(viewMatrix, worldMatrix));
OUT.pos = mul(mvp, IN.pos);
return OUT;
}
A nudge in the right direction would be greatly appreciated.
Thanks in advance