Hey there, guys.
I'm having trouble with implementing keyframe animation on iPhone.
I originally based it on Jeff LaMarche's sample. In the example below I have three keyframes, it goes from the first through the second one, but then keeps going between the second and the third.
Here's the code:
Code:
if (lastKeyframeTime == 0.0) lastKeyframeTime = [NSDate timeIntervalSinceReferenceDate];
NSTimeInterval timeSinceLastKeyFrame = [NSDate timeIntervalSinceReferenceDate] - lastKeyframeTime;
NSTimeInterval percentDone;
if (timeSinceLastKeyFrame > kAnimationDuration) {
++curFrame;
if (curFrame > numFrames-1)
curFrame = 0;
timeSinceLastKeyFrame = timeSinceLastKeyFrame - kAnimationDuration;
lastKeyframeTime = [NSDate timeIntervalSinceReferenceDate];
}
percentDone = timeSinceLastKeyFrame / kAnimationDuration;
source = animverts[curFrame];
dest = animverts[curFrame+1];
if ( curFrame == numFrames - 1)
dest = animverts[0];
for (int i = 0; i < (numIndices*3); i+=3) {
GLfloat diffX = dest[i] - source[i];
GLfloat diffY = dest[i+1] - source[i+1];
GLfloat diffZ = dest[i+2] - source[i+2];
curverts[i] = source[i] + (percentDone * diffX);
curverts[i+1] = source[i+1] + (percentDone * diffY);
curverts[i+2] = source[i+2] + (percentDone * diffZ);
}
then I update my VBO with curverts
What am I missing here?