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

时间:2015-07-02 16:41:04

标签: java 3d 2d lwjgl

我正在尝试在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中,我找不到基础数学:Projecting a 3D point to a 2D screen position issue

1 个答案:

答案 0 :(得分:0)

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

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