获取屏幕位置从世界排名 [英] Get Screen Position From World Position
问题描述
我想从世界排名在DirectX屏幕位置。
I want to get Screen Position from World Position in DirectX.
我可以让我的球的世界上的地位。但我不知道我怎样才能将其转换为屏幕上的位置。
I can get my ball's world position. But I can't know how can I convert it to screen position.
推荐答案
您有一个观点/眼变换V(就是那个地方你的相机)和投影变换P上。
You have a view/eye transform V (the one that "places" your "camera") and a projection transform P.
裁剪空间坐标由
clip_position = P * V * world_space_position
从剪辑的空间,您通过将夹子空间达到NDC空间在第四次剪裁空间坐标W,即坐标。
From clip space you reach NDC space by dividing the clip space coordinates by the 4th clip space coordinate w, i.e.
ndc_x = clip_x / clip_w
ndc_y = clip_y / clip_w
ndc_z = clip_z / clip_w
ndc_w = clip_w / clip_w = 1
视口XY坐标,然后通过映射的范围为[-1,1]视口的尺寸达到了。 OpenGL和DirectX之间的差别是,在OpenGL深度范围[-1,1]映射到[0,DEPTH_BUFFER_RESOLUTION],而在DirectX它的深度范围[0,1]映射到深度缓冲器值范围。
The viewport XY coordinates are then reached by mapping the range [-1,1] to the viewport dimensions. The difference between OpenGL and DirectX is, that in OpenGL the depth range [-1,1] is mapped to [0, DEPTH_BUFFER_RESOLUTION], while in DirectX it's the depth range [0, 1] that maps to the depth buffer value range.
这篇关于获取屏幕位置从世界排名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!