我正在尝试在三维环境中呈现二维文本,但为此我需要能够将一组三维坐标转换为屏幕上的二维点。我的相机具有视图投影矩阵、视野和三维空间中的位置。我要呈现的文本在屏幕上有一个二维点。
以下是我的进展:
以下是我的进展:
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屏幕位置的问题
viewProjection
可能包含视图和投影矩阵。是否需要进行透视除法取决于你使用的数学库。然后将其转换为视口空间应该很容易。 - javac