第一人称3D游戏的数学公式

发布于 2024-10-08 21:33:06 字数 185 浏览 0 评论 0原文

我想做一个第一人称 3D 游戏,但我无法正确设置相机公式。

所以我有一个旋转:0 到 359。接下来的 x,y 坐标,z 保持不变。

相机旋转:0-前、90-左、180-后、270-右,但我可以调整它

相机的公式是什么?

平台:Panda3d、python、opengl

谢谢

I want to make a first person 3d game but I can't set the camera formula right.

So I have a rotation: 0 to 359. Next the x,y coordinates, z remains the same.

Camera rotation : 0 - front, 90 - left, 180 - back, 270 - right but I can adapt it

What is the formula for the camera ?

Platform: Panda3d, python, opengl

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乜一 2024-10-15 21:33:07

好的,看来您需要《毁灭战士》风格的摄像机移动,即没有上下转动。考虑一下:

  1. 您需要渲染通过相机看到的“世界”。
  2. 假设正 x 位于右侧,正 y 位于前方,则当相机向右移动时,世界图像将向左移动。
  3. 当相机向左正转时,世界图像向右转。

现在,让我们尝试构建方程:

1.首先,将世界坐标平移到相机的位置:

Xwt = Xw - Xc;
Ywt = Yw - Yc;
Zwt = Zw;

(Xc,Yc,Zc) = camera position
(Xw,Yw,Zw) = world coordinates of object in the scene
(Xwt,Ywt,Zwt) = world coordinates of object translated to camera position

2.现在,将平移后的坐标旋转与相机旋转相反的角度:

Xwc =  Xwt * Cos(psi) + Ywt * Sin(psi);
Ywc = -Xwt * Sin(psi) + Ywt * Cos(psi);
Zwc =  Zwt

Psi = angle of camera rotation
(Xwc,Ywc,Zwc) = world coordinates of object transformed to camera orientation

您可以将这两个步骤结合起来,并将其转换为矩阵形式。

OK, it looks like you need a Doom style camera movement, i.e., no up-down turns. Consider this:

  1. You need to render the "world" as seen through the camera.
  2. Assuming positive x is to the right and positive y is to your front, when the camera moves to the right the world's image moves to the left.
  3. When the camera turns positively to the left, the world's image turns to the right.

Now, let's try to construct the equations:

1.First, translate the world coordinates to the camera's position:

Xwt = Xw - Xc;
Ywt = Yw - Yc;
Zwt = Zw;

(Xc,Yc,Zc) = camera position
(Xw,Yw,Zw) = world coordinates of object in the scene
(Xwt,Ywt,Zwt) = world coordinates of object translated to camera position

2.Now, rotate the translated coordinates by an angle opposite to the camera's rotation:

Xwc =  Xwt * Cos(psi) + Ywt * Sin(psi);
Ywc = -Xwt * Sin(psi) + Ywt * Cos(psi);
Zwc =  Zwt

Psi = angle of camera rotation
(Xwc,Ywc,Zwc) = world coordinates of object transformed to camera orientation

You can combine the two steps and transform it to a matrix form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文