phetsims / color-vision

"Color Vision" is an educational simulation in HTML5, by PhET Interactive Simulations.
http://phet.colorado.edu/en/simulation/color-vision
GNU General Public License v3.0
1 stars 7 forks source link

dt not used in Photon? #8

Closed samreid closed 10 years ago

samreid commented 10 years ago

I was surprised to see that dt wasn't used in Photon.js. Shouldn't the velocity term be proportional to the dt, so that it will run the same speed on different computers?

  var updateAnimationFrame = function( dt ) {
    this.location.x = this.location.x + this.velocity.x;
    this.location.y = this.location.y + this.velocity.y;
  };
aaronsamuel137 commented 10 years ago

Let me know if this is what you expected. Scaling by dt made the photons move ridiculously slow, so I scaled by dt * 50.

Assigning to @samreid for review

samreid commented 10 years ago

A few thoughts. How about increasing the velocity of the photons instead of scaling up the dt? Also, since the sim is supposed to run at 60fps, perhaps that scale factor should have been 60 instead of 50 to match the previous behavior. Reassigned to @aaronsamuel137.

aaronsamuel137 commented 10 years ago

I suppose I'm a little fuzzy on how the animation stuff works.

Where do you tell what the frame rate is? Is it 60 fps for every sim, or just some?

So what is dt exactly? It seems like some scaling factor to use in each animation frame, but how is it being calculated and such?

samreid commented 10 years ago

dt is the elapsed number of milliseconds between each frame. We use requestAnimationFrame, which attempts 60fps on every platform if possible. More detail about requestAnimationFrame is available here: https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame

You can see how we calculate dt in Sim.js. Let me know if you have further questions.

aaronsamuel137 commented 10 years ago

Thanks for the explanations. I have now scaled the velocity of the photons instead of dt. It looks a little stutter-y now to me in the browser, but I'm not exactly sure why. Let me know what you think. Surprisingly, it looks fine on the ipad though.

assigning to @samreid for review

samreid commented 10 years ago

It is smooth on my Win8/Chrome34. What browser does it look stutter-y on?

aaronsamuel137 commented 10 years ago

I've tried it on Chrome, Safari and Firefox. It seems to vary quite a lot, sometimes it looks fine, other times it seems a little off. Maybe its just something with my computer. I'll show you tomorrow and see what you think.

samreid commented 10 years ago

Sounds good, thanks!

samreid commented 10 years ago

We looked at it together, and it seems smooth enough, and that the varying dt is not causing a problem. Closing.