Ios SCNNode方向而不是eulerAngles
我正在尝试使用Ios SCNNode方向而不是eulerAngles,ios,swift,scenekit,augmented-reality,arkit,Ios,Swift,Scenekit,Augmented Reality,Arkit,我正在尝试使用ui旋转手势识别器旋转SCNNode并更改eulerAngles。我在绕y和绕z轴旋转之间切换。当我只旋转其中一个时,一切都很好。但当我旋转两者时,问题就出现了。它不再绕轴本身旋转,而是随机旋转 我读过很多答案,尤其是ARGeo的答案,比如这样一个:,我理解eulerAngles和万向节锁的问题 但是我不明白如何正确使用orientationant的w组件。这里有人成功地使用了UIRotationGestureRecognizer和orientation而不是eulerAngles
ui旋转手势识别器旋转SCNNode
并更改eulerAngles
。我在绕y
和绕z
轴旋转之间切换。当我只旋转其中一个时,一切都很好。但当我旋转两者时,问题就出现了。它不再绕轴本身旋转,而是随机旋转
我读过很多答案,尤其是ARGeo的答案,比如这样一个:,我理解eulerAngles
和万向节锁的问题
但是我不明白如何正确使用orientation
ant的w
组件。这里有人成功地使用了UIRotationGestureRecognizer
和orientation
而不是eulerAngles
?下面是一个如何实现UIRotationGestureRecognizer
的示例
我是从SO post上抄的
希望这有帮助。找到了。感谢您的快速回答,因为我用按钮切换旋转轴对我来说至关重要是您链接中的问题,我从未从文档中意识到,在z轴上旋转它可以像在SCNqueternion(0,0,1,newRotation)上旋转它一样简单,在y轴上旋转它也可以像在SCNqueternion(0,1,0,newOrientation)上旋转它一样简单。。。非常感谢。
private var startingOrientation = GLKQuaternion.identity
private var rotationAxis = GLKVector3Make(0, 0, 0)
@objc private func handleRotation(_ rotation: UIRotationGestureRecognizer) {
guard let node = sceneView.hitTest(rotation.location(in: sceneView), options: nil).first?.node else {
return
}
if rotation.state == .began {
startingOrientation = GLKQuaternion(boxNode.orientation)
let cameraLookingDirection = sceneView.pointOfView!.parentFront
let cameraLookingDirectionInTargetNodesReference = boxNode.convertVector(cameraLookingDirection,
from: sceneView.pointOfView!.parent!)
rotationAxis = GLKVector3(cameraLookingDirectionInTargetNodesReference)
} else if rotation.state == .ended {
startingOrientation = GLKQuaternionIdentity
rotationAxis = GLKVector3Make(0, 0, 0)
} else if rotation.state == .changed {
let quaternion = GLKQuaternion(angle: Float(rotation.rotation), axis: rotationAxis)
node.orientation = SCNQuaternion((startingOrientation * quaternion).normalized())
}
}