OpenGL中的动画 [英] Animation in OpenGL

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

问题描述

我想请您分享一些有关如何在OpenGL应用程序中实现动画支持的想法. 例如,如果我们希望在用户输入触发某个事件的情况下,在屏幕上设置Ball粒子的动画,我们如何组织代码? :

I would like to ask to you to share some ideas about how do you implement an animation support in your OpenGL application. For example, if we would like in case of the some event fired from the user input, animate a Ball particle on the screen, how do we need organize our code? :

  1. 将动画"属性设置为球形"粒子对象的成员吗? (其中包含一组要应用于所有者模型的矩阵,它们之间的延迟,是否播放动画等等.)
  2. 需要具有一些中央存储库,其中包含一个Ball粒子和对其应用的动画之间的关系(老实说,我更喜欢这一点). ?
  3. 还有其他...吗?

那渲染之后呢?如何使它流畅而快速? (我知道这是非常上下文相关的,但这只是一个想法.)

And after what about a rendering ? How to do it fluid and fast ? (I know this is very context sensitive, but just to give an idea..)

推荐答案

我将定义一个 Animation 类,该类可以实现以下动画:

I would define an Animation class, which can implement the following animations:

  • 旋转/翻译/缩放动画
  • 关键帧动画
  • 蒙皮动画

当然,上面列出的一种动画技术需要对 Object 类的某种通用访问.

Of course, one of the animation techniques listed above need some generic access to the Object class.

RotoTranslation 动画需要访问 Object 模型视图矩阵; KeyFrame 动画需要访问模型顶点缓冲区; 蒙皮动画需要访问 Object 的渲染状态(着色器属性和程序,或使用扩展名的顶点属性).

RotoTranslation animation requires access to the Object model view matrix; KeyFrame animation requires access to the model vertices buffers; Skinning animation requires access to the rendering state of the Object (shader attributes and programs, or vertex attributes using extensions).

除蒙皮外,还应执行通用值(浮点数,向量或矩阵)的插值,以便使用插值公式(通过genpfault链接的那些值更好)更改值.因此, Interpolator 类应能够简化新的插值方程的引入.

Apart skinning, the interpolation of generic values (floats, vector or matrices) shall be implemented, in order to change the values using an interpolation formula (nice those linked by genpfault). So an Interpolator class shall be able to ease the introduction of new interpolation equations.

Animation类使用一组 Interpolator 实例执行动画(更改要插入的值).值的选择,访问和修改方式(范围)应在 Object 类中定义.

An Animation class uses a set of Interpolator instances to execute the animation (changing the values to be interpolated). How the values are choosed, accessed and modified (ranges) shall be defined at Object class.

这时必须有一个 TimeLine 类,该类定义经过的时间(可能不是真正的时间),并触发 Animation 实例(或者可能是单个实例) Interpolator 实例)使内插值超前于中间值.

At this point there must be a TimeLine class which defines the time elapsed (which could not be the real one), which trigger Animation instances (or perhaps the single Interpolator instances) making the interpolated values advance the intermediate value.

Animation 实例在 TimeLine 类上排队,因此它知道哪些 Animation 实例处于活动状态.激活可能是由用户输入引起的,也可能是通过使用内部生成的事件以编程方式引起的.要终止 Animation 执行, Animation 类可以定义一个 IsTerminated 方法,以便从 TimeLine 中出队.实例(也许 Animation 可以使动画循环播放以具有连续动画).

The Animation instances are queued on the TimeLine class, so it knows which Animation instances are active. The activation could be caused by user input or programmatically using internally generated events. To terminate the Animation execution, the Animation class could define a IsTerminated method is order to be dequeued from the TimeLine instance (perhaps the Animation could loop back the animation to have a continuous animation).

当然,一切取决于您的实际需求.

Of course everything depending on your real needs.

如果动画的计算可能需要很长时间,则可以缓存整个模型数据,并在单独的线程中运行动画.一旦终止,就可以更新模型,从而阻止渲染循环.

In the case the computation of the animation could take long time, you could cache the entire model data and run the animation in a separated thread. Once terminated, the model could be updated blocking the rendering loop.

但是,我会考虑通过向着色器程序发布适当的数据来内联动画处理,从而加快计算速度,从而提高系统性能.

However, I would consider to inline the animation processing by issuing proper data to shader programs allowing a faster computation, which could enhances system performances.

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

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