Hi everybody,
I want to detect the motion of the device to move a cocos2d::Layer. At the end, it should work like a window to the “digital world” the user can look through. For example, the user is sitting on a rotatable chair and he holds the device in front of his eyes and starts turning the chair, the layer should start move in the opposite direction.
So, what i have to track is not tilting the device but moving it. I think the accelerometer is the right point to hook at. I tried the hardware compass on iPhone, but its updates are to rough.
I played around with the cocos2d-x accelerometer wrapper but I recognized that it only detects tilting, not moving. So I went one step back and wrote a wrapper for the iOS specific CMMotionManager. The accelerometer of the MotionManager detects what i want, the acceleration of the device in space.
But now comes the tricky part. The MotionManager detects acceleration (acc). That means if you start moving the device for example horizontal to the left it gives you a positive value for the acc. But if you slowly stops your movement, the MotionManager gives you a negative acc. If you move to the right its first a negative acc and at stopping the movement a positive acc.
i.E. Moving device horizontal from right to left
LEFT RIGHT (Position)
finished <- stop moving <- <- <- start moving <- origin (Motion)
0.00xx -0.aaaa +0.bbbb 0.00xx (acc)
I tried a lot of hacks to map this behavior to x axis movement of the layer. But I can’t get it work. The result is always the same. At the beginning of the movement the layer moves nice and sweet like i want. But at the stopping phase of the movement, the layer returns to the almost origin position.
And here I need your help guys. Do you have an idea how it could work. Or do you have a totally different solution for this scenario?
I am very curious about your comments.
Thanks a lot!