0

我正在尝试计算相机正在查看的点。相机绕 X 轴和 Y 轴旋转。我想计算与我的相机相距 1 厘米且在同一条线上的点。

我知道如何在 2D 中计算这样的东西,但是当我进入 3D 时,我遇到了麻烦。

这适用于 2D(仅 x 和 z 轴):

float c = 1f;
float a = c * Math.cos(Math.toRadians(rotationY));
float b = (Math.sin(Math.toRadians(rotationY)) * c);
newPosition.z -= a;
newPosition.x += b;

但是对于 3D,我需要帮助。

我希望这里有人知道遮阳篷。

4

1 回答 1

0

One way would be to take the inverse of the camera's view matrix, and then transform a point 1cm in front of the camera by this matrix.

If your camera first is rotated by X degrees around the X axis, and Y degrees around the y axis, then in pseudocode it might look like this:

Matrix4D camMM = Matrix4D.Identity(); //camera model matrix
camMM.Rotate(X, 1, 0, 0);
camMM.Rotate(Y, 0, 1, 0);
Vector4D focusPoint = camMM * vector4D(-1cm, 0, 0, 1);
于 2012-06-02T17:41:19.747 回答