I am using this logic to project a point in world space into screen space.
const FVector Location = FVector(1, 2, 3);
FIntRect Rect;
Rect.Max.X = ViewportSize.X;
Rect.Max.Y = ViewportSize.Y;
FVector2D CurrentScreenSpaceCoords;
const FMatrix ViewProjectionMatrix = SceneView->ViewMatrices.GetViewProjectionMatrix();
SceneView->ProjectWorldToScreen(Location, Rect, ViewProjectionMatrix, CurrentScreenSpaceCoords);
I am using this code to get the initial value back
FMatrix const InvViewProjMatrix = ViewProjectionMatrix.Inverse();
FVector WorldPosition;
FVector WorldDirection;
FSceneView::DeprojectScreenToWorld(CurrentScreenSpaceCoords, Rect, InvViewProjMatrix, WorldPosition, WorldDirection);
However the result of DeprojectScreenToWorld does not produce the initial input (Location).
Instead of giving me the expected vector of [1, 2, 3], it gives me X = [69.8139954,3840.00073, 250.49826]
Somebody knows:
- Why this happens?
- How to get the initial value back from it
Thanks in advance