Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ron.val

macrumors newbie
Original poster
Mar 24, 2011
6
0
hey i need some help ive been looking for some sample code on how to use CMdevicemotion but i havent found anything besides the references that apple has . what im trying to do is use the gyro and the accelerometer to have an arrow in the center of the screen pointing in the same direction that im facing as i (literally physically) turn left it would turn left on the screen as i turn right, it would turn right on the screen. i have seen this used in the jenga game that has come out on but that was in 3d which is way over my head i just want this for now so i can learn it for 3d later. I hope i explained it enough thanks in advanced for any help.
 
I think a big part of the problem is mapping all the data you have into a 2D arrow. You get something like 12 numbers from CMdevicemotion which ones of those correspond to what you want for your arrow?

I'd suggest just outputting all 12 to the console, and moving your device around to see what happens before you start drawing any arrows.

FWIW, the book "iPhone Programming, the BNR guide" has a simple example in Chapter 8 on using the accelerometer to do something simpler, but similar to what you describe. You might want to check it out.

BTW welcome to MR.

B
 
devicemotion

hey thanks for the reply. ya im not sure which numbers im gonna need. i read about it in stackflow.com but still have no clue. Im reading as much as possible but im still having trouble organizing it. im using opengl to render the image but now im not sure if i should start a new class for device motion or put in into the eagl file since things initialize there. im gonna get the book you recommend from the library thanks for the recommendation as you can see im new to this :). im trying to make a game. pretty much what im trying to do is be able to get the position of the phone relative to me i was reading today that you can also use the compass for games so now im not sure if its the gyro/accelerometer (devicemotion code) im supposed to use or the compass cause that would also kinda tell me the position/orientation of the iphone relative to me. i know it can be done cause they use that in the jenga game where if i turn its like im walking around the jenga tower.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.