XMMATRIX ViewProj = _view() * _projection();
XMVECTOR pointInWorld = XMVector3Transform(worldPoint, ViewProj);
float x = ((XMVectorGetX(pointInWorld) + 1.0f) / 2.0f) *_width;
float y = ((-XMVectorGetY(pointInWorld) + 1.0f) / 2.0f) *_height;
XMVECTOR pointInScreen = DirectX::XMVectorSet(x, y, 0.0f, 0.0f); // works fine
float xx = (((2.0f * x) / _width) - 1.0f);
float yy = -(((2.0f * y) / _height) - 1.0f);
float zz = DirectX::XMVectorGetZ(pointInWorld);
XMMATRIX invView = XMMatrixInverse(NULL, ViewProj);
XMVECTOR mousePos = XMVectorSet(xx, yy, zz, 1.0f);
mousePos = XMVector3Transform(mousePosition, invView); // incorrect
Hi, i am trying to figure out why i cannot accurately convert between world and screen coordinates. The code above takes a point in world space and converts it into a screen position (). This seems to work fine, but when i do the opposite to get the original world coordinate, the result is wrong. The x coordinate is usually close but the y and z are tottaly off. Anyone care to explain this to me?