I'm having great difficulty applying newtons laws of motion to my iPhone app in order to replicate the effect of a ball on a surface and when tilted the ball rolls due to gravity.
The app is in landscape hence the x and y being the wrong way round.
I've got
// Accelerometer Parameters
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
// X movement
float radianValueX = (3.14159265f*(acceleration.y*90))/180;
accX = (9.8f*sin(radianValueX));
// Y movement
float radianValueY = (3.14159265f*(acceleration.x*90))/180;
accY = (9.8f*sin(radianValueY));
}
and
-(void)gameLoop
{
// m/s/s to px/s/s
float newAccX = accX/0.000159125f;
float newAccY = accY/0.0001606875;
ball.position = ccp(ball.position.x+newAccX,ball.position.y+newAccY);
}
The pixel acceleration becomes absolutely massive.
The dimensions of the iPhone's screen are (in portrait) 51.42mm x 76.38mm and the pixels(points) are 320 x 480.
According to the math, I did 76.38 *10^-3 to get it in meters and then divide it by 480 pixels to get the size of a pixel in meters. This comes out to be 0.000159125 and vice versa for the other dimension.
I don't know if this obscenely high acceleration of about 1000px/s/s is even correct?
What do I do with the acceleration in order to apply it to the x and y coordinates of the ball on screen?