CoreMotion漂移

时间:2016-08-10 08:57:50

标签: ios matrix core-motion

我在- (void)webViewDidFinishLoad:(UIWebView *)webView { NSString *userName = @"xyz"; NSString *password = @"abc"; if (userName.length != 0 && password.length != 0) { NSString *jsPassword = [NSString stringWithFormat:@"document.querySelectorAll(\"input[type='password']\").value ='%@'", password]; NSString *jsUsername = [NSString stringWithFormat:@"var inputFields = document.querySelectorAll(\"input[type='text']\"); \ for (var i = inputFields.length >>> 0; i--;) { inputFields[i].value = '%@';}", userName]; [self.mywebView stringByEvaluatingJavaScriptFromString: jsUsername]; [self.mywebView stringByEvaluatingJavaScriptFromString: jsPassword]; } 应用程序中使用CoreMotion来显示对象。经过一段时间的驾驶汽车运动经理开始漂移,我想有些错误积累。这会导致对象显示在错误的位置。关闭AR并重新打开后,它会返回正确的值。有什么我可以做的来解决这个问题吗?我正在使用deviceMotion以这种方式计算变换:

motionManager.deviceMotion?.attitude

我在某处读过使用let m = attitude.rotationMatrix let column1 = vector_double4(m.m11, m.m12, m.m13, 0.0) let column2 = vector_double4(m.m21, m.m22, m.m23, 0.0) let column3 = vector_double4(m.m31, m.m32, m.m33, 0.0) let column4 = vector_double4(0.0, 0.0, 0.0, 1.0) let cameraMatrix = matrix_double4x4(columns: (column1, column2, column3, column4)) let projectionCameraMatrix = matrix_multiply(cameraMatrix, projectionMatrix) 代替态度可能有所帮助。但我不知道如何从motionManager.deviceMotion?.rotationRate计算相机旋转矩阵。我曾尝试使用https://en.wikipedia.org/wiki/Rotation_matrix中的公式:

rotationRate

但结果是错误的。我需要得到与态度相似的旋转矩阵。

有人可以帮助我从guard let g = motionManager.deviceMotion?.rotationRate else { return } func rotationMatrix(x: Double, y: Double, z: Double) -> CMRotationMatrix { let rxc1 = vector_double3(1, 0, 0) let rxc2 = vector_double3(0, cos(x), sin(x)) let rxc3 = vector_double3(0, -sin(x), cos(x)) let ryc1 = vector_double3(cos(y), 0, -sin(y)) let ryc2 = vector_double3(0, 1, 0) let ryc3 = vector_double3(sin(y), 0, cos(y)) let rzc1 = vector_double3(cos(z), sin(z), 0) let rzc2 = vector_double3(-sin(z), cos(z), 0) let rzc3 = vector_double3(0, 0, 1) let rx = matrix_double3x3(columns: (rxc1, rxc2, rxc3)) let ry = matrix_double3x3(columns: (ryc1, ryc2, ryc3)) let rz = matrix_double3x3(columns: (rzc1, rzc2, rzc3)) let r = matrix_multiply(matrix_multiply(rx, ry), rz) return CMRotationMatrix(m11: r.columns.0.x, m12: r.columns.0.y, m13: r.columns.0.z, m21: r.columns.1.x, m22: r.columns.1.y, m23: r.columns.1.z, m31: r.columns.2.x, m32: r.columns.2.y, m33: r.columns.2.z) } let cameraRotationMatrix = rotationMatrix(g.x, y: g.y, z: g.z) 计算rotationMatrix吗?或者在驾驶一段时间之后还有其他方法可以纠正这种转变。

0 个答案:

没有答案