Setting ARKit Orientation via Swift

萝らか妹 提交于 2019-12-05 02:54:18

问题


I am developing an ARKit app with OpenGL, so working directly with ARKit and not using SceneKit.

By default, ARKit is set to landscape orientation, but I have been unable to track down any documentation or examples to rotate to portrait. SceneKit example works in portrait but the Metal example only works in landscape.

Is it possible to change the ARKit tracking orientation?


回答1:


I was able to solve this in the application logic by multiplying the camera matrix by a quaternion that is rotated based on device orientation.




回答2:


sorry on objective-c.

find and rewrite this

uniforms->viewMatrix = [frame.camera viewMatrixForOrientation:UIInterfaceOrientationLandscapeRight];
uniforms->projectionMatrix = [frame.camera projectionMatrixForOrientation:UIInterfaceOrientationLandscapeRight viewportSize:_viewportSize zNear:0.001 zFar:1000];

to

uniforms->viewMatrix = [frame.camera viewMatrixForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
uniforms->projectionMatrix = [frame.camera projectionMatrixForOrientation:[[UIApplication sharedApplication] statusBarOrientation] viewportSize:_viewportSize zNear:0.001 zFar:1000];

and

CGAffineTransform displayToCameraTransform = CGAffineTransformInvert([frame displayTransformForOrientation:UIInterfaceOrientationLandscapeRight viewportSize:_viewportSize]);

to

CGAffineTransform displayToCameraTransform = CGAffineTransformInvert([frame displayTransformForOrientation:[[UIApplication sharedApplication] statusBarOrientation] viewportSize:_viewportSize]);



回答3:


Currently in iOS 11 Beta, there's only horizontal surfaces tracking for plane detection.

By default, plane detection is off. If you enable horizontal plane detection, the session adds ARPlaneAnchor objects and notifies your ARSessionDelegate , ARSCNViewDelegate , or ARSKViewDelegate object whenever its analysis of captured video images detects an area that appears to be a flat surface.

If you need vertical tracking, do it yourself with hitTest(_:types:) function. It allows you to check surfaces or objects in real world.

Hit testing searches for real-world objects or surfaces detected through the AR session's processing of the camera image. A 2D point in the image coordinates can refer to any point along a 3D line that starts at the device camera and extends in a direction determined by the device orientation and camera projection. This method searches along that line, returning all objects that intersect it in order of distance from the camera.



来源:https://stackoverflow.com/questions/45125709/setting-arkit-orientation-via-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!