游戏动画的最佳方法? [英] Best approach for game animation?

查看:33
本文介绍了游戏动画的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 OpenGL 课程练习,用几个对象的简单动画编写游戏

I have a course exercise in OpenGL to write a game with simple animation of a few objects

在与我的合作伙伴讨论我们的设计选项时,我们意识到对于动画的工作方式,我们有两个主要选择,要么

While discussing with my partner our design options we've realized we have two major choices for how the animation is going to work, Either

  • 设置一个固定间隔的计时器,比如 30 毫秒,当计时器到达时,计算对象应该在哪里并绘制框架.或 -
  • 不要使用计时器,只是一个一直运行的普通循环,并在每次迭代中检查经过了多少时间,根据间隔计算对象应该在哪里并绘制框架.

通常首选的方法是什么?有没有人对这两种方法有具体经验?

What should generally be the preferred approach? Does anyone have concrete experience with either approach?

推荐答案

尽可能快地渲染和计算以获得最大帧速率(受垂直同步限制)

Render and compute as fast as you can to get the maximum frame rate (as capped by the vertical sync)

不要使用计时器,它们不可靠<在 Windows 上为 50-100 毫秒.检查已经过去了多少时间.(通常,您需要 delta t 和绝对值,具体取决于您的动画是基于物理还是关键帧.)

Don't use a timer, they're not reliable < 50-100 ms on Windows. Check how much time has passed. (Usually, you need both delta t and an absolute value, depending on if your animation is physics or keyframe based.)

此外,如果您想保持稳定,请在您的时间步长上使用上限/下限,如果一帧需要几秒钟来渲染(另一个进程访问磁盘?)如果您在 10 毫秒内获得其中两个,请更新.

Also, if you want to be stable, use an upper/lower bound on your time-step, to go into slow-motion if a frame takes a few secs to render (disc access by another process?) or skip an update if you get two of them within say 10 ms.

更新(因为这是一个相当受欢迎的答案)

我通常更喜欢有一个固定的时间步长,因为它使一切都更加稳定.大多数物理引擎对于变化的时间都非常稳健,但其他东西,如粒子系统或各种更简单的动画,甚至游戏逻辑,如果让一切都在固定的时间步长内运行,则更容易调整.

I usually prefer having a fixed time-step, as it makes everything more stable. Most physics engines are pretty robust against varying time, but other things, like particle systems or various simpler animations or even game logic, are easier to tune when having everything run in a fixed time step.

更新 2(因为我得到了 10 个赞;)

为了在长时间运行(> 4 小时)后进一步保持稳定性,您可能希望确保不使用浮点数/双精度数来计算大的时间差,因为这样做会失去精度,并且游戏的动画/物理会遭受.改用定点(或基于 64 位微秒的)整数.

For further stability over long periods of running (>4 hours), you probably want to make sure you're not using floats/doubles to compute large time differences, since you lose precision doing so and your game's animations/physics will suffer. Use fixed point (or 64-bit microsecond-based) integers instead.

关于毛茸茸的细节,我建议阅读Tom Forsyth 的精确问题.

For the hairy details, I recommend reading A matter of precision by Tom Forsyth.

这篇关于游戏动画的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆