Motion sensor

Asked

Viewed 103 times

2

How do I identify the rotational motion of the iPhone on its own axis (same rotation as a spinning top)? I was able to identify practically all possible rotations and I couldn’t identify this one, which is exactly what I need for a game I’m developing. The iPhone will be in portrait position.

More precisely I need to take the Y rotation

  • I think that this here can help you using the framework CoreMotion.

  • Unfortunately it was following that I got the others but I could not implement the Y, what I need to do is something similar to the example of Quizzer

  • So you need to rotate the shaft itself?

1 answer

1

To get the values, you can use 3 shapes, and here they are:

Declare

let motionKit = MotionKit()

And so get the data in the following ways:

Data from the accelerometer:

motionKit.getAccelerometerValues(interval: 1.0){
        (x, y, z) in
        //Do whatever you want with the x, y and z values
        println("X: \(x) Y: \(y) Z \(z)")
      }

Data from the gyroscope:

motionKit.getGyroValues(interval: 1.0){
        (x, y, z) in
        //Do whatever you want with the x, y and z values
        println("X: \(x) Y: \(y) Z \(z)")
     }

magnetic field around your device:

motionKit.getMagnetometerValues(interval: 1.0){
        (x, y, z) in
        //Do whatever you want with the x, y and z values
        println("X: \(x) Y: \(y) Z \(z)")
     }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.