Thursday, April 14, 2016

Accelerometer and Gyro path mapping iOS | Cardboard

Leave a Comment

We need to draw 2D path of accelerometer and device orientation for case when user have iPhone in a Google Cardboard and wearing the same, we are able to draw the path in straight cases of forward and backward movement but path get disturbed when user changes the direction to left or right. PFB- code to draw device path with recorded CMDeviceMotion

    override func viewWillAppear(animated: Bool) {      let fWL = recordedMotion.first?.location      var y = (canvas.center.x / 2) + CGFloat((fWL!.userAcceleration.y + fWL!.gravity.y))     var z = (canvas.center.y / 2) + CGFloat((fWL!.userAcceleration.z + fWL!.gravity.z))       for wall in recordedMotion {           canvas.addSubview(iPhoneView(withYaw: wall.location.attitude.yaw, Y: y, Z: z, Shadow: false, Label: wall.wallName))           if wall != recordedMotion.last{              for motion in wall.recordedMotion {                  y = y + CGFloat((motion.userAcceleration.y + motion.gravity.y) * 100)                 z = z + CGFloat((motion.userAcceleration.z + motion.gravity.z) * 100)                  canvas.addSubview(iPhoneView(withYaw: motion.attitude.yaw, Y: y, Z: z, Shadow: true, Label: nil))              }          }      }  } 

I know that’s a lot to take in, so let me know if anything I’ve said doesn’t make sense. I would appreciate any help in this matter.

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment