7

I want to make rolling cube like dice that reacts on accelerometer. So accelerometer gives parameters for cube moving. I think that small physic should be used here. My question is what formulas, techniques should I use to accomplish this without any physics engine.

DJClayworth
  • 25,586
  • 8
  • 51
  • 74
userbb
  • 2,088
  • 3
  • 28
  • 52

1 Answers1

8

You will need probably to use OpenGL for that. There a good physics tutorial for OGL here

Specifically for dice, take a look at this nokia demo. It's written in cpp (source here)

On the physics side, you can take a look at this site.

Anyhow, I do not think you need real physics for the app, but just an approximation:

  • I would start getting a velocity that depends on the accelerometer (plus or minus, let's say, 20%) and random angular speeds for the dice.
  • Then, find the trajectory for each and when touching a border.
  • Bounce them to one direction or another depending on the rotation at that particular moment.
  • Change the sign of the angular speed if the dice bounce back.
  • Reduce the speed about 50% each bounce, until a threshold.
  • Below that threshold, leave them in the floor and stop movement.
Aleadam
  • 39,843
  • 9
  • 85
  • 108