我需要找出相机正在查看的方向,例如如果它朝向Z,Z-,X或X-.
我尝试过使用eulerAngles,但是偏航的范围是0 – > 90 – > 0 – > -90 – > 0这意味着我只能检测相机是朝向Z还是X,而不是朝向那些轴的正方向或负方向.
解决方法
您可以创建一个SCNNode,将其放在worldFront属性中以获取具有x,y和z方向的向量.
你能做到的另一种方式就是这个项目是如何做到的:
// Credit to https://github.com/farice/ARShooter func getUserVector() -> (SCNVector3,SCNVector3) { // (direction,position) if let frame = self.sceneView.session.currentFrame { let mat = SCNMatrix4(frame.camera.transform) // 4x4 transform matrix describing camera in world space let dir = SCNVector3(-1 * mat.m31,-1 * mat.m32,-1 * mat.m33) // orientation of camera in world space let pos = SCNVector3(mat.m41,mat.m42,mat.m43) // location of camera in world space return (dir,pos) } return (SCNVector3(0,-1),SCNVector3(0,-0.2)) }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。