Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SCNNode方向而不是eulerAngles_Ios_Swift_Scenekit_Augmented Reality_Arkit - Fatal编程技术网

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())
    }
}