【发布时间】:2018-05-19 05:48:36
【问题描述】:
我的相机根节点前面有一个带有 SCNPlane 几何的 SCNNode 的 SCNView。
在 SCNView 上,在 UIView 中,我添加了 UIImages(标记) - 橙色圆圈。
在 Motion 监听器中,我试图以某种方式定位标记,以便它们会粘在平面每个边缘的中心。
我正在使用从 SceneKit 对象到 UIView 的投影来执行此操作:
//world coordinates
let v1w = sm.node.convertPosition(sm.node.boundingBox.min,
to: self.sceneView.scene?.rootNode)
let v2w = sm.node.convertPosition(sm.node.boundingBox.max,
to: self.sceneView.scene?.rootNode)
//projected coordinates
let v1p = self.sceneView.projectPoint(v1w)
let v2p = self.sceneView.projectPoint(v2w)
//frame rectangle
let rect = CGRect.init(x: CGFloat(v1p.x), y: CGFloat(v2p.y),
width: CGFloat(v2p.x - v1p.x), height: CGFloat(v1p.y - v2p.y))
var frameOld = sm.marker.frame
switch sm.position
{
case .Top:
frameOld.origin.y = rect.minY - frameOld.size.height/2
frameOld.origin.x = rect.midX - frameOld.size.width/2
case .Bottom:
frameOld.origin.y = rect.maxY - frameOld.size.height/2
frameOld.origin.x = rect.midX - frameOld.size.width/2
case .Left:
frameOld.origin.y = rect.midY - frameOld.size.height/2
frameOld.origin.x = rect.minX - frameOld.size.width/2
case .Right:
frameOld.origin.y = rect.midY - frameOld.size.height/2
frameOld.origin.x = rect.maxX - frameOld.size.width/2
}
sm.marker.frame = frameOld
self.view.layoutSubviews()
您可以在这里找到类似的方法:Scene Kit: projectPoint calculated is displaced
所以我希望这些标记在设备运动期间粘在平面的边缘。但是有一个问题:旋转设备时 - 标记从平面边缘漂移
查看问题视频:https://youtu.be/XBgNDDX5ZI8
我在 github 上创建了一个基本项目来重现一个问题:https://github.com/mgontar/SceneKitProjectionIssue
【问题讨论】:
标签: ios swift opengl-es scenekit core-motion