ios - SCNNode 方向而不是 eulerAngles
问题描述
我正在尝试旋转SCNNode
和UIRotationGestureRecognizer
更改eulerAngles
. y
我在绕轴和绕轴旋转之间切换z
。当我只旋转其中一个时,一切都很好。但是当我旋转两者时出现问题。它不再围绕轴本身旋转,而是随机旋转。
我已经阅读了很多答案,尤其是来自 ARGeo 的答案:SCNNode Z 旋转轴保持不变,而 X 和 Y 轴在节点旋转时发生变化,并且我了解eulerAngles
云台锁定的问题。
但我不明白如何正确使用orientation
ant 那个w
组件。这里有成功使用UIRotationGestureRecognizer
andorientation
而不是的人eulerAngles
吗?
解决方案
这是如何实现的示例之一UIRotationGestureRecognizer
。
我从How can I rotate an SCNNode.... SO post 复制了它。
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())
}
}
希望这可以帮助。
推荐阅读
- git - Git取消应用存储?
- algorithm - 二分查找中值逻辑
- mysql - 当 MySQL 不优化它们时,我应该避免 JOIN 吗?
- angularjs - 如何从本地服务器绑定来自 Kendo Scheduler 中服务的数据
- javascript - 如何在ngSwitch中的Angular 2+中将事件从子组件绑定到父组件
- kubernetes - 无法通过 traefik 反向代理访问我的 Kubernetes 服务
- python - 为什么 list.sort() 不起作用,但 sorted() 在这种情况下对给定列表工作正常
- objective-c - 尝试在我的 macOS Sierra 10.12.6 中安装 Homebrew 时出现 ssh_exchange_identification 问题
- python - PySpark:从随机均匀分布创建数据帧
- date - 在 VueJS 中格式化日期。后端到前端