core-motion

How to avoid roll in SceneKit camera controlled by Core Motion?

孤人 提交于 2019-12-04 07:29:24
I'm setting my SceneKit camera to the current CMDeviceMotion attitude using the CMDeviceMotion extension described in this answer : func deviceDidMove(motion: CMDeviceMotion?, error: NSError?) { if let motion = motion { let orientation = motion.gaze(atOrientation: UIApplication.sharedApplication().statusBarOrientation) cameraNode.orientation = orientation } } This works beautifully, however, I'd like to block the rotation (roll) and only allow the camera to turn around (yaw) and pitch. I tried to convert the quaternion back to Euler angles and simply leave roll at 0: cameraNode.eulerAngles =

CMSampleBuffer from OpenGL for video output with AVAssestWritter

孤者浪人 提交于 2019-12-04 07:00:47
I need to get a CMSampleBuffer for the OpenGL frame. I'm using this: int s = 1; UIScreen * screen = [UIScreen mainScreen]; if ([screen respondsToSelector:@selector(scale)]){ s = (int)[screen scale]; } const int w = viewController.view.frame.size.width/2; const int h = viewController.view.frame.size.height/2; const NSInteger my_data_length = 4*w*h*s*s; // allocate array and read pixels into it. GLubyte * buffer = malloc(my_data_length); glReadPixels(0, 0, w*s, h*s, GL_RGBA, GL_UNSIGNED_BYTE, buffer); // gl renders "upside down" so swap top to bottom into new array. GLubyte * buffer2 = malloc(my

iOS CoreMotion - Calculating Height Difference

╄→гoц情女王★ 提交于 2019-12-03 20:57:16
Is it possible to calculate the difference in height when an iPhone moves using the data from CoreMotion? For example, the initial position of the iPhone is saved, then the iPhone is moved which results in a new position. I am interested in detecting if the height of the iPhone moved from its initial position. I don't need absolute units, just a relative value indicating what percentage the height has changed from its original height. let manager = CMMotionManager() // Save initial attitude var initialAttitude = manager.deviceMotion.attitude if manager.deviceMotionAvailable { manager

explanation of iOS rotation matrix

纵饮孤独 提交于 2019-12-03 07:54:15
I am trying to work with 3D rotations but I don't seem to get the idea how the framework does the calculations. For example I get this data: yaw -1.010544 pitch 0.508249 roll 1.128918 Then I print the corresponding rotation matrix 0.599901 -0.128495 -0.789689 0.740043 0.464230 0.486649 0.304065 -0.876344 0.373584 After reading the API and the wiki, I am pretty sure there must be a general way to create a rotationmatrix out of euler angles. I tried all of these here , no results. Do I miss something, or how is this done? Well, iOS or CoreMotion provides both. RotationMatrix and Euler Angle

How to calculate correct velocity values from accerometer

ぃ、小莉子 提交于 2019-12-03 06:25:34
问题 I need to calculate iphone velocity in space, punch speed for example. My first question is: Are the acceleration values accelerometer:didAccelerate with this filtering actions: gravity_x = acceleration.x * kFilteringFactor + gravity_x * (1.0 - kFilteringFactor); gravity_y = acceleration.y * kFilteringFactor + gravity_y * (1.0 - kFilteringFactor); gravity_z = acceleration.z * kFilteringFactor + gravity_z * (1.0 - kFilteringFactor); float gravityNorm = sqrt(gravity_x * gravity_x + gravity_y *

CMMotionActivityManager ignores cycling

拜拜、爱过 提交于 2019-12-03 06:22:16
I've been researching the new M7 chip's CMMotionActivityManager , for determining whether the user of the device is walking, running, in a car, etc (see Apple Documentation ). This seemed like a great step forward over trying to determine this previous from using LocationManager and accelerometer data only. I notice however that CMMotionActivityManager does not have a cycling activity, which is disappointing, and almost a deal-breaker for complete usage as a new activity manager. Has anyone else found a convenient way to use CMMotionActivityManager with cycling also without having to

get pitch, yaw, roll from a CMRotationMatrix

隐身守侯 提交于 2019-12-03 04:38:35
问题 I have a CMRotationMatrix *rot and i would like to get the pitch, yaw, roll from the matrix. Any ideas how i could do that? Thanks 回答1: Its better to use the Quaternion than Euler angles.... The roll, pitch and yaw values can be derived from quaternion using these formulae: roll = atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z) pitch = atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z) yaw = asin(2*x*y + 2*z*w) It can be implemented as: CMQuaternion quat = self.motionManager.deviceMotion.attitude.quaternion;

How do I retrieve accelerometer data correctly with Swift in iOS?

自作多情 提交于 2019-12-03 04:18:29
I am trying to record the data from the iPhone's accelerometer (my own iPhone 5s) and set a label on the screen to that data using String(format: "%.2f", data) where data is the value for the specific axis I want to record. To do this I set up a CMMotionManager and began recording accelerometer data, and I have a timer that constantly updates the text in the label. However, I am getting an error from Xcode: "fatal error: unexpectedly found nil while unwrapping an Optional value". Here is the relevant code: override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after

CMMotionActivityManager - Receiving motion activity updates while app is suspended or in background

青春壹個敷衍的年華 提交于 2019-12-03 03:42:03
问题 I've been testing the new Motion Activity Manager APIs ( CMMotionActivityManager ). I want to create an app that can receive and process motion updates from startActivityUpdatesToQueue while the app is not running in the foreground. I correctly receive motion updates (stationary, walking, running, automotive, unknown) while the app is in the foreground but as soon as it goes into the background (and thus gets suspended), motion updates cease to be received by the app. CMMotionActivityManager

Getting accelerometer data in background using CoreMotion

馋奶兔 提交于 2019-12-03 00:38:15
I'm unable to receive accelerometer data in the background, despite the seemingly correct solution per this question How Nike+ GPS on iPhone receives accelerometer updates in the background? [_motionManager startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc] init] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"perform"); [(id) self setAcceleration:accelerometerData.acceleration]; [self performSelectorOnMainThread:@selector(update) withObject:nil waitUntilDone:NO]; });}]; perform is logged whenever the app is