C# function to convert screen-space coordinates to worldspace coordinates, at specific Z position?

痴心易碎 提交于 2020-01-06 02:38:28

问题


I am making a 2D game, rendered as 3D.

When clicking on my game, I want it to convert those screen space pixel coordinates into worldspace coordinates, knowing the Z axis point (0) that the point should hit.

How can I do this with a function?

I am using XNA with C#.


回答1:


Converting from 2d to 3d is unprojecting. there is a built in method within xna for this:

 Vector3 3dWorldPosition = GraphicsDevice.Viewport.Unproject(2DscreenVector & desired Z comp, viewMatrix, projectionMatrix);


来源:https://stackoverflow.com/questions/5692700/c-sharp-function-to-convert-screen-space-coordinates-to-worldspace-coordinates

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!