Here is my perspective projection and camera code
Code: Select all
//Perspective
gfx.SetProjection(DirectX::XMMatrixPerspectiveLH(1.0f, 1.0f / Graphics::AspectRatio, 1.0f, 1000.0f));
//camera
//every parameter is 0.0f except range
const auto position =
DX::XMVector3Transform(
DX::XMVectorSet(0.0f, 0.0f, -range, 0.0f),
DX::XMMatrixRotationRollPitchYaw(aroundX, -aroundY, 0.0f));
return
DX::XMMatrixLookAtLH(position, DX::XMVectorZero(),
DX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f)) *
DX::XMMatrixRotationRollPitchYaw(pitch, -yaw, roll);
However, when I set nearZ = 0.5f, the range need to set 400.0f (half of ScreenWidth) to fill the height. (see nearZ_05.png)
Why? I can't figure out the relationship between nearZ and the screen width
Also the square disappears when I set range = 1000.0f. Why? 1000.0f is not greater than the farZ.