Hello!
The problem is that I ran into a problem in matrix transformations and just got confused, I can’t figure out how to do better.
I program in C ++ using the DirectX 11 (Direct3D) API. There is some video that should be displayed in full screen, the video is superimposed on the mesh's texture.
I have only one model (mesh / mesh), which is created procedurally, consists of four points, one can say, a rectangle. The screen resolution is 1920x1080, but sometimes it can be 1920x1200. Ideally, I need to calculate the values so that at any resolutions the mesh is stretched to full screen. That is, the first point in the upper left corner, the second point in the upper right, and so on. I’m not new to DirectX, but I still don’t have enough mathematical base, I’m confused in terms such as "perspective", "projection" and all that.
Now I’ve done it crookedly — I manually adjusted the camera coordinates and its parameters at the desired resolution in debug mode, but this is a very dirty decision.
Tell me how you can calculate the coordinates of the camera, its viewing angle, height and other values so that the pixel-by-pixel mesh covers the entire screen.
Here are the mesh vertices:
pVertices[0].Pos = XMFLOAT3(0.0f, 0.0f, 0.0f); pVertices[0].Tex = XMFLOAT2(0.0f, 0.0f); pVertices[1].Pos = XMFLOAT3(meshMaxX, 0.0f, 0.0f); pVertices[1].Tex = XMFLOAT2(0.0f, 0.0f); pVertices[2].Pos = XMFLOAT3(meshMaxX, 0.0f, meshMaxY); pVertices[2].Tex = XMFLOAT2(0.0f, 1.0f); pVertices[3].Pos = XMFLOAT3(0.0f, 0.0f, meshMaxY); pVertices[3].Tex = XMFLOAT2(0.0f, 1.0f); And this is how the camera is configured:
X = 19.215715f; Y = 14.345325f; Z = 4.789997f; viewAngleX = -(XM_PIDIV2 + XM_PI); viewAngleY = XM_PIDIV2; __width = 1920; __height = 1200; ConstantBuffer cb; const float ratio = static_cast<float>(__width) / static_cast<float>(__height); CB->p = XMMatrixPerspectiveFovLH(XM_PIDIV4, ratio, 0.01f, 100.0f); XMVECTOR eye = XMVectorSet(X, Y, Z, 0.0f); XMVECTOR at = XMVectorSet(X + 1.0f * cos(viewAngleX), Y + 1.0f * sin(viewAngleY) / cos(viewAngleY), Z + 1.0f * sin(viewAngleX), 0.0f); XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); CB->v = XMMatrixLookAtLH(eye, at, up); Thanks a lot in advance!