Search code examples
directxcoordinate-transformation

How to calculate view-space vertex coord from screen-space vertex coord given FOV and screen resolution?


I am writing a hook for a very old game that used DX 6.1 and doesn't have L&T.

I am intercepting calls to DX with float x, y, z, rhw vertex position and I want to reconstruct x y z in view-space coordinates. I know FOV and screen resolution, but I have problem with finding formula for back transform. Could someone give me such formula, or point me to relevant Internet sources?

And one more thing - Sometimes I am receiving very strange coordinates, for example I've manage to capture in the debugger:

float x = 105.96786.0f;
float y = 1963.8353.0f;
float z = -2343.6121.0f;
float rhw = 0.0f;

How should I handle such cases in reverting formula?


Solution

  • @Nico Schertler pointed out in comment above that I should use inverted matrix - this works