많은 연구와 테스트를 거친 후. GLKit을 사용하여 계산을 마쳤습니다. 문제가 많아졌습니다. 이 질문에 이르면 누구 에게라도 남겨주세요.
먼저 CMAttitudeReferenceFrameXTrueNorthZVertical을 사용하여 CMMotionManager 장치 모션 업데이트를 시작했습니다. 내가 CoreMotion 회전을 사용하여 OpenGL을 세계를 그리고 3D 세계에 화면에서 점을 받고 그것을 혼합 웹에서 발견 된 일부 코드에서
self.hasMotion = NO;
CMMotionManager *cmmotionManager = [[CMMotionManager alloc] init];
[cmmotionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical
toQueue:[[NSOperationQueue alloc] init]
withHandler:^ (CMDeviceMotion *motion, NSError *error) {
self.hasMotion = YES;
}];
self.motionManager = cmmotionManager;
:
float aspect = fabsf(self.view.bounds.size.width/self.view.bounds.size.height);
GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(45.0f), aspect, 0.1f, 100.0f);
CMRotationMatrix r = self.motionManager.deviceMotion.attitude.rotationMatrix;
GLKMatrix4 camFromIMU = GLKMatrix4Make(r.m11, r.m12, r.m13, 0,
r.m21, r.m22, r.m23, 0,
r.m31, r.m32, r.m33, 0,
0, 0, 0, 1);
GLKMatrix4 viewFromCam = GLKMatrix4Translate(GLKMatrix4Identity, 0, 0, 0);
GLKMatrix4 imuFromModel = GLKMatrix4Identity;
GLKMatrix4 viewModel = GLKMatrix4Multiply(imuFromModel, GLKMatrix4Multiply(camFromIMU, viewFromCam));
bool isInvertible;
GLKMatrix4 modelView = GLKMatrix4Invert(viewModel, &isInvertible);
int viewport[4];
viewport[0] = 0.0f;
viewport[1] = 0.0f;
viewport[2] = self.view.frame.size.width;
viewport[3] = self.view.frame.size.height;
bool success;
//assume center of the view
GLKVector3 vector3 = GLKVector3Make(self.view.frame.size.width/2, self.view.frame.size.height/2, 1.0);
GLKVector3 calculatedPoint = GLKMathUnproject(vector3, modelView, projectionMatrix, viewport, &success);
if(success)
{
//CMAttitudeReferenceFrameXTrueNorthZVertical always point x to true north
//with that, -y become east in 3D world
float angleInRadian = atan2f(-calculatedPoint.y, calculatedPoint.x);
return angleInRadian;
}
감사합니다. user2629068, 모든 방법이 예상대로 작동합니다. – kokemomuke
좋습니다! 이 문제를 해결하려고하는 그물에 수많은 솔루션이 있습니다. 그러나 이것은 잘 작동하는 유일한 것입니다. –
내 카메라의 미세한 움직임을 아주 잘 지원하는이 코드를 보내 주셔서 감사합니다! 그러나 나는 대략 10 도의 표제의 정확도를 가지고있다. 이 정확성을 더 낮은 값으로 줄이는 방법이 있습니까? (따라서 제목의 정확성이 향상됩니까?) –