I'm interested in using Core Animation to drive custom animations in my OpenGL scene on the iPhone. I was hoping to find a mechanism that allowed you to generically animate a keypath of an NSObject or a delegate method for each animation tick. What I have come up with is to animate an arbitrary property of a CALayer and poll them from OpenGL to determine the progression of the animation. However, I'm convinced there's a better way to do it. What is the cleanest, safest way to tap into this great animation engine ?
If you want to animate view itself try to read http://stackoverflow.com/questions/630265/iphone-uiview-animation-best-practice. For animation inside OpenGL view it's better to use animated models or custom code but not Core Animation.
This is possible, to use Core Animation to drive whatever you wish. I am sure it can be used for sound, too! (Given a little subclassing of CALayer). UIKit and Core Animation can be mixed quite freely, with a little care, as there is CAEAGLLayer for us to play with as well.
The key here is -(id)presentationLayer and -(id)modelLayer for using pure/only OpenGL; of course even the hierarchy can be used for your OpenGL scene too. But, using CALayer for rendering as well gets even more "for free", if this is possible for your circumstances (but also see CATransformLayer), if this is what you seek! =)
I suspect what you really want are just the easing functions used by core animation. These are easy enough to find with a little googling. Here's one example:
GLfloat bounceEaseOut(GLfloat ratio) {
if (ratio < 1.0f/2.75f) {
return 7.5625f*ratio*ratio;
} else if (ratio < 2.0f/2.75f) {
return 7.5625f*(ratio-=1.5f/2.75f)*ratio+0.75f;
} else if (ratio < 2.5f/2.75f) {
return 7.5625f*(ratio-=2.25f/2.75f)*ratio+0.9375f;
} else {
return 7.5625f*(ratio-=2.625f/2.75f)*ratio+0.984375f;
}
}
You pass in how far into your tween you are (elapsedTime/tweenDuration) and it tells you what percent of the way through the tween's "timeline" you should be.