问题
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