Time-Based Animation

mdavis1982
Unregistered
 
Post: #1
Hi all...

Using Alex Diener's Time-Based Animation Tutorial, I have tried implementing time-based animation. However, it doesn't appear to be working at all!

Here is my code for MDOpenGLController.h:

Code:
#define            kMaxFrameRate            600.0
#define            kMinFrameRate            15.0
#define            kUpdateInterval            (1.0 / kMaxFrameRate)
#define            kMaxCyclesPerFrame        (kMaxFrameRate / kMinFrameRate)

And MDOpenGLController.m:

Code:
- (void)mainTimerFires
{
    NSTimeInterval currentTime;
    NSTimeInterval updateIterations;

    currentTime = [NSDate timeIntervalSinceReferenceDate];
    updateIterations = ((currentTime - [self lastFrameTime]) + [self cyclesLeftOver]);
    
    if (updateIterations > (kMaxCyclesPerFrame / kUpdateInterval))
    {
        updateIterations = (kMaxCyclesPerFrame / kUpdateInterval);
    }
    
    while (updateIterations > kUpdateInterval)
    {
        updateIterations -= kUpdateInterval;
        
        [[self rotatingPyramid] update];
        [[self rotatingCube] update];
    }
    
    [self setCyclesLeftOver:updateIterations];
    [self setLastFrameTime:currentTime];

    [[self openGLView] drawFrame];
}

Any help would be really useful! Thanks!

Matt
Quote this message in a reply
Member
Posts: 102
Joined: 2005.01
Post: #2
Make the code exist.
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #3
Coin Wrote:Make the code exist.
that might work. Rolleyes

It's not magic, it's Ruby.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
ryan, he's referring to the fact that the code is invisible in the OP... perhaps just in the aqua style?
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #5
Silly. Its time based. You have to wait for the code to appear on the page.

Come on. Wait for it.

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
Member
Posts: 102
Joined: 2005.01
Post: #6
mdavis1982 Wrote:Hi all...

Using Alex Diener's Time-Based Animation Tutorial, I have tried implementing time-based animation. However, it doesn't appear to be working at all!

Here is my code for MDOpenGLController.h:

Code:
#define            kMaxFrameRate            600.0
#define            kMinFrameRate            15.0
#define            kUpdateInterval            (1.0 / kMaxFrameRate)
#define            kMaxCyclesPerFrame        (kMaxFrameRate / kMinFrameRate)

And MDOpenGLController.m:

Code:
- (void)mainTimerFires
{
    NSTimeInterval currentTime;
    NSTimeInterval updateIterations;

    currentTime = [NSDate timeIntervalSinceReferenceDate];
    updateIterations = ((currentTime - [self lastFrameTime]) + [self cyclesLeftOver]);
    
    if (updateIterations > (kMaxCyclesPerFrame / kUpdateInterval))
    {
        updateIterations = (kMaxCyclesPerFrame / kUpdateInterval);
    }
    
    while (updateIterations > kUpdateInterval)
    {
        updateIterations -= kUpdateInterval;
        
        [[self rotatingPyramid] update];
        [[self rotatingCube] update];
    }
    
    [self setCyclesLeftOver:updateIterations];
    [self setLastFrameTime:currentTime];

    [[self openGLView] drawFrame];
}

Any help would be really useful! Thanks!

Matt

DID IT WORK?!?!?!


i quoted him...... sooo yea..... SLEEPY TIME IS NOW!
Quote this message in a reply
Member
Posts: 40
Joined: 2004.12
Post: #7
Here is a quick little demo that clearly shows that the supposed time-based animation code on this page is not working. I was using this method for time based animation, but increasing the MINIMUM_FRAME_RATE causes the animation time to render slower. Go figure. I am working on a solution to this right now. Cheers.

Demo

Press 's' to start. Press the space bar to make the ball jump, and right and left arrow keys to move it. Watch as the background object is not rendered, the framerate, and velocity of the ball increase. To quit, close the window.

I'm running on a 12" TIPowerbook with 256 MiB RAM, stock 32 MBVRAM card.

Jericho
Quote this message in a reply
Member
Posts: 41
Joined: 2005.02
Post: #8
12-inch PowerBook G4, 640 Ram, no idea VRAM, whatever comes on my machine. I don't notice any problems other than the background isn't painted to the left and the right. Everything else seems to work smoothly. The background object appears just fine in the middle. There's no frame rate lag and the timing appears to be uniform.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Frame Based Animation Nick 6 3,785 Jan 27, 2007 06:25 AM
Last Post: 007gamer
  problem with time based animation ferum 5 3,062 Aug 4, 2006 01:45 PM
Last Post: ferum