【发布时间】:2019-01-13 18:31:01
【问题描述】:
在 ARKit 中,如果我有一个 ARSCNView,我如何获得当前场景的真实世界中心坐标?我使用 Swift 作为编程语言。
【问题讨论】:
-
想象 AR 世界的原点简化为 ARSCNView 的中心位置。
在 ARKit 中,如果我有一个 ARSCNView,我如何获得当前场景的真实世界中心坐标?我使用 Swift 作为编程语言。
【问题讨论】:
你可以通过这样的手势来获得触摸点
// 1.
@objc func tapped(recognizer :UIGestureRecognizer) {
// Get exact position where touch happened on screen of iPhone (2D coordinate)
let touchPosition = recognizer.location(in: sceneView)
// 2.
// Conduct a hit test based on a feature point that ARKit detected to find out what 3D point this 2D coordinate relates to
let hitTestResult = sceneView.hitTest(touchPosition, types: .featurePoint)
// 3.
if !hitTestResult.isEmpty {
guard let hitResult = hitTestResult.first else {
return
}
print(hitResult.worldTransform.columns.3)
}
}
你可以得到点位置
让 positionOfObjectToAdd=SCNVector3(hitResult.worldTransform.columns.3.x,hitResult.wor
ldTransform.columns.3.y, hitResult.worldTransform.columns.3.z)
【讨论】:
阮东,
希望你有愉快的一天:-)
我会尽力提供帮助(只是不确定您在寻找什么)...但我想我有一些线索 ;-)
我会给你一些提示,看看我能不能帮忙:
问题: “如何在 arkit 中获得真实世界中心坐标?”
1) 如果您询问的是真实世界坐标系的中心: 这是你的看法:
https://developer.apple.com/documentation/scenekit/scndebugoptions/2882039-showworldorigin
如何在代码中使用: 在 viewDidLoad 函数中
sceneView.debugOptions = [ARSCNDebugOptions.showWorldOrigin]
如何获取世界原点位置? 如果我理解您的要求,ARKit 的真实世界中心是首次运行会话配置时设备的位置和方向。坐标为 (0,0,0)。 [如果这对你没有意义,请告诉我(我知道我跳过了很多但在 iPad 上打字)。]
这是在现实世界中心定位某物的方法(我们知道世界中心位于坐标 (0,0,0))
如何在代码中使用;
func addBox() {
// create a SceneKit box shape
let box = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)
// create a SceneKit node
let boxNode = SCNNode()
// attach the shape to the node
boxNode.geometry = box
// give node a position ( this will be the real world center!
boxNode.position = SCNVector3(0, 0, 0)
// SCNVector3 you can think of for now as SCNVector3(x,y,z)
//https://developer.apple.com/documentation/scenekit/scnvector3
// create a SceneKit scene
let scene = SCNScene()
// add the node as a child of the rootNode
// the root node defines the origin of the world coordinate systems for SceneKit.
//Apple Documentation states:"The world coordinate system of the view's
//SceneKit scene directly responds to the AR world coordinate system
//established by the session configuration."
// so ARKit and SceneKit world coordinate systems match :-)
scene.rootNode.addChildNode(boxNode)
//add the SceneKit scene to sceneView
sceneView.scene = scene
}
所以我给你的第一个答案是保持定位变量。 如何在代码中使用:
let ARWorldOrigin = SCNVector3(0, 0, 0)
使用它来进行所有测量
1)您是指物理屏幕的中心吗?
2) 你的意思是摄像头视锥体的中心吗 (试试这个stackflow页面的提示: Get All ARAnchors of focused Camera in ARKIT
3) 关注此 stackoverflow 问题的所有链接: Which measuring unit is used in SCNVector3 position for x, y and z in ARKit
我希望我能以某种方式帮助并理解您的问题:
祝你有美好的一天! 并希望ARkit编程
我们都通过确定我们所知道的来学习。
智能狗
【讨论】: