gpt4 book ai didi

ios - SCNNode 方向而不是 eulerAngles

转载 作者:行者123 更新时间:2023-11-28 05:43:23 25 4
gpt4 key购买 nike

我正在尝试使用 UIRotationGestureRecognizer 旋转 SCNNode 并更改 eulerAngles。我在围绕 y 和围绕 z 轴的旋转之间切换。当我只旋转其中一个时,一切都很好。但是当我旋转两者时出现问题。它不再绕轴旋转,而是随机旋转。

我已经阅读了很多答案,尤其是来自 ARGeo 的答案,例如:SCNNode Z-rotation axis stays constant, while X and Y axes change when node is rotated , 并且我了解eulerAngles 和 gimbal lock 的问题。

但我不明白如何正确使用orientation ant w 组件。这里有人成功使用 UIRotationGestureRecognizerorientation 而不是 eulerAngles 吗?

最佳答案

下面是如何实现 UIRotationGestureRecognizer 的示例之一。

我从How can I rotate an SCNNode....复制过来的所以发帖。

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

希望这对您有所帮助。

关于ios - SCNNode 方向而不是 eulerAngles,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55762144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com