繁体   English   中英

如何将3D位置转换为屏幕上的2D点?

[英]How do you convert a 3D position to a 2D point on screen?

我试图在3D环境中渲染2D文本,但为此我需要能够将一组3D坐标转换为屏幕上的2D点。 我的相机具有视图投影矩阵,视野和3D空间中的位置。 我试图渲染的文本在屏幕上有一个2D点。

这是我到目前为止:

public final Vector2f get2DPointFrom3DPosition(Vector3f position) {//position is the point in 3D space that I'm trying to render the text at
    final Vector3f camPos = this.getTransform().getPos();//where Vector3f == (x, y, z), and is a 3D position in space
    final Matrix4f viewProjection = this.getViewProjection();//where Matrix4f == float[][]
    final double fov = this.getFieldOfView();//usually 70.0f
    float X;
    float Y;
    //complicated math that I can't find with google or figure out
    return new Vector2f(X, Y);//where vector2f is a pixel position on the screen
}

如果我错过了类似的问题,或者我不清楚任何事情,我会提前道歉。 我确实找到了这个问题,但它不是在java中,我找不到基础数学: 将3D点投影到2D屏幕位置问题

2D_X = 3D_X / Z
2D_Y = 3D_Y / Z

这个计算至少应该以正确的方向指导你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM