如何将 3D 空间坐标转换为 2D 空间坐标? [英] How can I convert 3D space coordinates to 2D space coordinates?

查看:42
本文介绍了如何将 3D 空间坐标转换为 2D 空间坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Lua API.我正在尝试将 3D 空间坐标转换为 2D 空间坐标.我问过谷歌,但除了使用 OpenGL 函数的片段之外,我找不到任何东西.我不需要源代码或任何简单的方法来实现它?如果有帮助,我可以获得相机的视角,要转换的原始位置,窗口大小和纵横比吗?预先感谢您的任何建议:)

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).您可能还想调整相机视角、纵横比等,在这种情况下,我会参考 this维基百科文章.

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.

这篇关于如何将 3D 空间坐标转换为 2D 空间坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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