Programing
[iPhone] 만보기 로직
npre
2011. 6. 27. 17:41
반응형
-(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
x = acceleration.x;
y = acceleration.y;
z = acceleration.z;
float dot = (x1 * x) + (py * y) + (z1 * z);
float a = ABS(sqrt(x1 * x1 + py * py + z1 * z1));
float b = ABS(sqrt(x * x + y * y + z * z));
dot /= (a * b);
if (dot<0.8) // bounce
{
if (!isChange)
{
isChange = YES;
_walkCnt = _walkCnt+1;
// count increases and all work done here
} else {
isChange = NO;
}
}
x1 = x;
py = y;
z1 = z;
}