I have a 3D cube that can be rotated with the mouse to show any side of the sphere.I want to be able to click a point on the cube and draw a circle around that point at a fixed height(so i dont need depth information), however i run into a problem where i cant translate the screen coridiantes to the worldspace coordinates. What i have attempted:
get mouse click
normalise the screen position(-1 to 1)
create a vector with the z coordinate as 1
multiply the vector by (inverseProjection x inverseView)
However, this does not give me the world coordinates as i would have expected. Where am i going wrong?
The depth information is not needed form this, i only need to map the mouse click point (x,y) to the world point (x,y,z) where z is fixed.
DirectX::XMMATRIX projection = projectionmatrix(); DirectX::XMMATRIX view = viewmatrix(); DirectX::XMMATRIX invProjectionView = DirectX::XMMatrixInverse(&DirectX::XMMatrixDeterminant(view * projection), (view * projection)); //invViewProjection = invView * invProjection; float x = (((2.0f * mouseX) / _viewport.Width) - 1); float y = -(((2.0f * mouseY) / _viewport.Height) - 1); DirectX::XMVECTOR mousePosition = DirectX::XMVectorSet(x, y, 1.0f, 0.0f); mouseInWorldSpace = DirectX::XMVector3Transform(mousePosition, invProjectionView);
Edit: The fixed axis is the y-axis, the z and x axis are the changing axis
Edit: I have revised the question after realising my mistakes in the initial question.
The x, y, and z are positioned as shown above. I want to be able to click the cube surface and drwaw the shape at a point with a fixed y-offset from the click point.
I am not able to draw a plane on the surface of the cube due to the nature in which the cube is generated hence the need for the screen to world coords.