Animation and frame-rate

Any regulars on this forum will probably be aware I’ve been working on getting stuff animated and moving about. The trouble I’m having now is that I can’t work out how much to transform the animated TransformGroup by to ensure standard speed. My little dude walks about quite happily - an AWTEvent starts the movement, which runs every frame while the key is down, a morphbehaviour animates the figure and the transformGroup is transformed slightly every frame. The trouble comes with either changing the environment complexity or running the code on a different machine which seems to make the movement stupidly slow (the morph animation keeps going at about the same rate, I’m guessing cos it is based on an Alpha) - I’m assuming that the FPS is falling so that I am getting fewer Transforms per second.

Does anyone know a good way to calculate how large a step needs to be depending on the framerate, or a good alternative way of moving the character about that doesn’t depend on the framerate?

Not sure wether I got your problem…

dx = v * dt?

But if frametimes vary unexpectedly (a common problem of java games), there’s no way to keep animation smooth.

I’m afraid it was the second of those that was bothering me- I was wondering whether therre was a good way of basing the transform change on time rather than on framerate- would that work? If so what would be the best way to do it?

I’d change transformation over time:

do a call to deltaTime every frame:


private boolean init = false;
private long lastTime = 0;

private long deltaTime() {
      if(!init) {
            this.lastTime = J3DTimer.getValue();
            this.init = true;
       }
       long actualTime = J3DTimer.getValue();
       long deltaTime   = actualTime - this.lastTime;
       this.lastTime      = actualTime;
       return deltaTime
}

Speaking of FrameRate, how is that determined in Java? Is there an method that you can call to get the current frame rate, ect?

Doesn’t help anything bc. this measures the time of the LAST frame but give you no idea how long the next frame will take. And that is the frame you calculate the motion for.

For many environments, there is a good coherence between frames so that the deltaT of the last frame is a very good approximation for the coming frame. If that coeherence is not given - as it is for Java - animations are no longer smooth, regardless how exact you can measure time.

  • J

If you need to tie an animation to time explicitly, regardless of the framerate, and regardless of skips, pauses, etc, then you could use an Alpha and base your transformation (either morph weights or key frame index) on the Alpha value. This would be the case for physics-based animations that are tied to elapsed time in the physics model. Or if you don’t need to animate every frame.

Or you could roll your own Alpha-like behavior and keep track of the timing yourself if you need hi-res timing – plenty of threads on this!

Depends on your needs. I’ve been using Alphas and been pretty happy with them in general. But the game I’m not working on is not an action game. YRMV…

–Brad

I’m using alphas to animate the character, so it moves it’s limbs at a perfectly regular rate, I was just transforming it every frame to do the movement so when the framerate dropped so did the speed of the character moving across the environment. I think zero’s solution will work best- I’ll look at this tonight.