【发布时间】:2018-07-06 00:27:26
【问题描述】:
我正在尝试制作一个 ARKit 应用程序,其中 SCNNode(在本例中为一个盒子)放置在相机前面,面向相机。当用户四处移动相机时,当移动一定距离时放置对象。这会留下一系列面向相机的节点,等距排列。
我有这个工作在一定程度上,但我的问题是轮换。我目前正在采用所有旋转轴,因此当用户重新定位他们的手机时,节点的旋转匹配。我想将此限制为仅围绕 y 轴旋转。理想的结果是多米诺骨牌般的外观,所有对象都具有相同的 x 和 z 旋转,但可能具有不同的 y 旋转。
我希望我已经解释得足够清楚了!
这是我目前使用的代码:
func createNode(fromCameraTransform cameraTransform: matrix_float4x4) -> SCNNode {
let geometry = SCNBox(width: 0.02, height: 0.04, length: 0.01, chamferRadius: 0)
let physicsBody = SCNPhysicsBody(type: .dynamic, shape: SCNPhysicsShape(geometry: geometry))
physicsBody.mass = 1000
let node = SCNNode(geometry: geometry)
node.physicsBody = physicsBody
var translationMatrix = matrix_identity_float4x4
translationMatrix.columns.3.x = 0.05 // Moves the node down in world space
translationMatrix.columns.3.z = -0.1 // Moves the object away from the camera
node.simdTransform = simd_mul(cameraTransform, translationMatrix)
return node
}
我尝试了从cameraTransform 的第二列提取值并将它们设置为eulerAngles、rotation 和simdRotation 的不同组合,但无济于事。
我也尝试从当前sceneView 的pointOfView 中提取值并将它们分配给与上面列出的相同的值,但同样没有运气。
任何帮助将不胜感激!
我对此略知一二,但我真的只是从 SceneKit 和 3D 转换/矩阵开始,所以请对我温柔一点!
【问题讨论】:
标签: ios swift rotation scenekit arkit