如何在 iPhone 上为 openGL 动画计时?
我想知道apples SDK中是否有一个保证单调递增的时间函数?我听说过 [NSDate timeIntervalSinceReferenceDate]
(这不准确)和 c 函数 mach_absolute_time
。
所有这些人如何在 openGL ES 中计时他们的动画(是否有独立于帧的解决方案)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅此问题: 如何获得精确的时间,例如 Objective-c 中的毫秒数?
See this question: How can I get a precise time, for example in milliseconds in objective-c?
我使用 CADisplayLink 来计时我的动画。当您在 xCode 上创建一个新的 opengl-es 项目时,它会给您一个示例 opengl-es 代码,并通过 CADisplayLink 控制动画。
编辑:
我发现我误解了这个问题。
我检查此 apple在线doc,里面说该方法可能不是单调递增的。我更喜欢通过 mach_absolute_time() 导出值的方法 CACurrentMediaTime() 。关于 CACurrentMediaTime() 的文档是 此链接。
I use CADisplayLink to timing my animation. When you create a new opengl-es project on xCode, it will give you an sample opengl-es codes, and it control animation by CADisplayLink.
EDIT:
I found I misunderstand this problem.
I check the CFAbsoluteTimeGetCurrent() method on this apple on-line doc, and it said the method may be not monotonically increasing. And the method CACurrentMediaTime() which I prefered derived value by mach_absolute_time(). The document about CACurrentMediaTime() is on this link.
对于与帧速率无关的时间,我通常使用 CFAbsoluteTimeGetCurrent() 函数。它返回一个
CFAbsoluteTime
(我相信它的类型定义为double
),因为某个日期是任意遥远的过去。For frame-rate-independent time, I generally use the
CFAbsoluteTimeGetCurrent()
function. It returns aCFAbsoluteTime
(which I believe is typedef'd todouble
) since some date arbitrarily far in the past.