在特定 Z 位置将屏幕空间坐标转换为世界空间坐标的 C# 函数? [英] C# function to convert screen-space coordinates to worldspace coordinates, at specific Z position?

查看:26
本文介绍了在特定 Z 位置将屏幕空间坐标转换为世界空间坐标的 C# 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个 2D 游戏,渲染为 3D.

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

当点击我的游戏时,我希望它将这些屏幕空间像素坐标转换为世界空间坐标,知道该点应该击中的 Z 轴点 (0).

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?

我在 C# 中使用 XNA.

I am using XNA with C#.

推荐答案

从 2d 到 3d 的转换是非投影的.为此,xna 中有一个内置方法:

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);

这篇关于在特定 Z 位置将屏幕空间坐标转换为世界空间坐标的 C# 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆