Hello,
I have an behaviour that wakes up on WakeupOnElapsedFrames(0)
!I calculate the fps with the J3DTIMER. So I divide my Transform per second with fps. But this way my animation is stuttering.
I tried out to animate without the fps argument. So I had a look at my overall Frames per second and diveded the Transform with this constant. There was no stuttering anymore! But this only works on my machine,because the Framerate on my machine would not be the same like on a slower or faster one. Furthermore a more complex scene would change the Framerate, too. So this isn’t a solution!
How can I fix this problem?
Here is some example code:
In my Behavior:
import javax.media.j3d.Behavior;
import javax.media.j3d.WakeupOnElapsedFrames;
import com.sun.j3d.utils.timer.J3DTimer;
import java.util.Enumeration;
public class GameUpdaterBehavior extends Behavior {
private GameUpdater updater;
private WakeupOnElapsedFrames wakeupCondition = new WakeupOnElapsedFrames(0, false);
private long oldTime = 0;
private long newTime = 0;
private long timeDiff = 0;
private float fps = 0.0f;
public GameUpdaterBehavior(GameUpdater updater) {
this.updater = updater;
}
public void initialize() {
oldTime = J3DTimer.getValue();
newTime = J3DTimer.getValue();
wakeupOn(wakeupCondition);
}
public void processStimulus(Enumeration criteria) {
newTime = J3DTimer.getValue();
timeDiff = newTime - oldTime;
oldTime = newTime;
fps = 1000000000.0f/timeDiff;
//System.out.println("fps: " + fps);
updater.update(fps);
//fürs nächste mal!
wakeupOn(wakeupCondition);
}
}
in the Updater class:
public void update(float fps) {
xChangePerSecond = xChangePerSecond/fps;
yChangePerSecond = yChangePerSecond/fps;
zChangePerSecond = zChangePerSecond/fps;
}
If using this in Updater class there’s no stuttering, but this way I don’t use the Timer:
public void update() {
final float FPS = 50.0f;
xChangePerSecond = xChangePerSecond/FPS;
yChangePerSecond = yChangePerSecond/FPS;
zChangePerSecond = zChangePerSecond/FPS;
}
Greets,
Juan