我怎么能转换成三维空间坐标到二维空间坐标?坐标、空间、转换成、我怎么能

2023-09-07 12:58:49 作者:会呼吸Dē痛

我使用Lua的API。我想将三维空间坐标的二维空间坐标。我问谷歌,但我找不到从使用OpenGL函数片断什么分开。我不需要源$ C ​​$ C或任何东西就怎么做,它只是一个简单的方法?我可以获取摄像机的角度来看,原来的位置进行改造,窗口尺寸和纵横比,如果这是任何帮助?在此先感谢您的任何建议:)

I'm using a Lua API. I'm trying to transform 3D space coordinates to 2D space coordinates. I've asked google but I can't find anything apart from snippets using OpenGL function. I don't need source code or anything just a simple way on how to do it? I can acquire the Camera's perspective, the original position to be transformed, window size and aspect ratio if that's any help? Thanks in advance for any suggestions :)

推荐答案

如果你谈论的是改造世界的空间(X,Y,Z)坐标,以屏幕空间(U,V)坐标,那么基本方法是:

If you're talking about transforming world-space (x,y,z) coordinates to screen-space (u,v) coordinates, then the basic approach is:

u = x / z;
v = y / z;

如果相机不在原点,变换(的x,y,z)除以视图矩阵投影矩阵之前。您可能还需要调整摄像头的角度,长宽比等,在这种情况下我会参阅这维基百科的文章。

If the camera is not at the origin, transform (x,y,z) by the view matrix before the projection matrix. You may also want to adjust for the camera perspective, aspect ratio etc., in which case I'd refer to this Wikipedia article.

我的道歉,如果你正在寻找一些具体的事情到Lua的API,这我不熟悉。

My apologies if you're looking for something specific to the Lua API, which I am not familiar with.