以固定帧率更新画面的C语言编程方法 |
您所在的位置:网站首页 › td,tr,tf › 以固定帧率更新画面的C语言编程方法 |
龙源期刊网 http://www.qikan.com.cn 以固定帧率更新画面的 C 语言编程方法
作者:耿植
来源:《电脑知识与技术》 2017 年第 01 期
摘要:用 C 语言实现计算机动画时,往往使用一个大概时长作为画面之间的延时。该做法 会使得不同画面的帧时长不相等,从而无法实现对动画速度的准确控制。针对该问题,对延时 函数进行了改进,能按指定的帧时长进行自适应延时。以该理论为基础,进一步提出一种以固 定帧率更新画面的编程方法,适用于编写需要按时更新画面的动画、游戏和应用程序。最后, 以 C 语言编写控制台窗口文本界面下的 “ 英文对话动态演示 ” 应用程序为例,展示了该方法的应 用。
关键词:计算机动画;帧率;延时; C 语言;编程方法
中图分类号: TP311 文献标识码: A 文章编号: 1009-3044 ( 2017 ) 01-0046-03 Abstract : To implement computer animation with C language , often use approximate duration as the delay between the frames. This will make the different time length between different frames ,
making it impossible to achieve accurate control over the speed of the animation. To solve this problem , the sleep function is improved and the adaptive delay can be carried out according to the specified frame time length. On this basis , further proposed a programming method to update frames with fixed frame rate , suitable for animation , games and applications. Finally , the application of this method is demonstrated by the example of "English Dialogue Dynamic Demonstration" under textual interface of the windows console in C language. Key words : computer animation ; frame rate ; delay ; C language ; programming method 1 背景
利用人类视觉系统的视觉残留特性 [1] ,计算机动画中采用: “ 绘制一帧画面 ” 、 “ 延时 ” 、 “ 绘制下一帧画面 ” 、 “ 延时 ” 的方式,在短时间内快速切换画面,能使人产生 “ 画面是连续变化 ” 的感觉。有大量的文章探讨了使用 C 语言在图形界面下进行画面绘制、擦除与切换的技术手 段,如:屏幕重画、双缓冲、异或、调色板 [2] 、图形页面、掩膜 [3] 等。但却都只是简单地使 用如 delay ( 10 ) [3] 、 delay ( 200 ) [4] 等大概延时作为控制动画速度的手段。这仅能实现
“ 按某 个大概速度动起来 ” ,而无法实现 “ 按一个指定的速度动起来 ” 和 “ 从某时开始动起来,一直到某 时为止 ” ;也没有讨论一个画面中若同时存在多个不同速度变化的画面元素如何处理。以下提 出一种以固定帧率更新画面的编程方法,可用于实现图形界面和文本界面下的各种类型的动画 [6] 、游戏和应用程序。下文中的 C 源代码均在 Windows 系统中 Visual C++ 编译环境调试通 过。
|
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |