马里奥赛车“镜像模式” - OpenGL

发布于 2025-01-02 18:03:04 字数 252 浏览 3 评论 0原文

我想知道像《马里奥赛车》这样的游戏的开发者是如何改变他们的关卡方向的。有没有一种简单的方法可以在 OpenGL 中做到这一点?对于那些不知道的人来说,如果您要在“镜像”模式下玩关卡,通常位于左侧的门将位于右侧。

这是一个小例子,

具有这四个顶点的多边形

X      Y


Z      W

将是

Y      X


W      Z

I am wondering about how the developers of games like Mario Kart go about switching the orientation of their levels. Is there an easy way to do this in OpenGL. For those who aren't aware, if you were to play a level in "mirror" mode, a door that is usually on the left would then be on the right.

Here is a small example

A polygon with these four verticies

X      Y


Z      W

Would be

Y      X


W      Z

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

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

发布评论

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

评论(1

寂寞笑我太脆弱 2025-01-09 18:03:04

具有这四个顶点的多边形

您不需要它。

  1. 设置镜像变换矩阵。镜像矩阵是按负值缩放的矩阵。 glScalef(-1.0f, 1.0f, 1.0f),例如是x轴镜像。
  2. 使用 GL_CW 调用 glFrontFace。即,将正面更改为“相反”值。
  3. 渲染场景。

相同的原理可以用于 3.0 着色器,即使您必须使用其他东西来构建

-1 0 0 0 
 0 1 0 0
 0 0 1 0
 0 0 0 1

比例矩阵

虽然,是的,在视频游戏的情况下,只需在关卡编辑器中翻转整个地图并保存可能会更容易(碰撞检测)它作为新的水平,而不是即时翻转它。

A polygon with these four verticies

You don't need that.

  1. Set mirror transform matrix. Mirror matrix is the one that scales by negative value. glScalef(-1.0f, 1.0f, 1.0f), for example is x-axis mirror.
  2. Call glFrontFace with GL_CW. I.e. change front face to "opposite" value.
  3. Render scene.

Same principle can be used with 3.0 shaders, even if you'll have to use something else to build

-1 0 0 0 
 0 1 0 0
 0 0 1 0
 0 0 0 1

Scale matrix

Although, yes, in case of video game it might be easier (collision detection) just to flip entire map in level editor and save it as new level instead of flipping it on the fly.

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