1
\$\begingroup\$

I'm trying to achieve something like netent's roulette (which is a great product in my opinion). It's going to be implemented in html5.

I wonder which path should I take to have such a great animation for spinning ball. My problem is that the random number is generated on the server, thus using any of currently available physics engines means loose control of the ball, I mean that it will be hard to apply forces in such a manner that ball hits the right slot. Another option is to make my own a pseudo physics. "Pseudo" because it should always keep track of destination point. It is pretty much like playing animation generated backwards.

\$\endgroup\$
3

1 Answer 1

1
\$\begingroup\$

Here's a trick to simplify things, based on the fact that all slots are the same size and shape:

  1. Run a physics simulation with random input parameters but instead of rendering it just store the ball position and wheel rotation for each frame so you can replay it later.

  2. Work out which slot the ball has landed in.

  3. Calculate the angle between that slot and the one you actually want it to land in. This will be one of 37 values if there's a single zero on the wheel {0, 360/37 ..., (360*36)/37}.

  4. Render the animation sequence you recorded, but with the wheel rotated by that angle from step 3. The ball will now land in the correct slot.

\$\endgroup\$
3
  • \$\begingroup\$ Interesting, I'm going to check that. But I'm afraid that any physics engine adds some randomness, tiny deviations. Run this animation jiglibjs.org/demos_official/collisions_similar.htm a few times and you'll see that it's different every time. Thus it wont be possible to "replay" same animations. \$\endgroup\$
    – harabara
    May 22, 2013 at 6:55
  • \$\begingroup\$ You can replay it in this case very simply - store off the position of the ball and rotation of the wheel every frame during the simulation. The replay uses those stored values rather than re-running the physics simulation. \$\endgroup\$
    – Adam
    May 22, 2013 at 23:15
  • \$\begingroup\$ ok, i get your point, thank you. i will post here my solution once i have it. \$\endgroup\$
    – harabara
    May 23, 2013 at 12:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .