我正在使用以下代码使用平移手势旋转节点。我喜欢只在 y 轴上旋转我的节点。
let translation = gestureRecognize.translation(in: gestureRecognize.view!)
let x = Float(translation.x)
let y = Float(-translation.y)
let anglePan = (sqrt(pow(x,2)+pow(y,2)))*(Float)(Double.pi)/180.0
var rotationVector = SCNVector4()
rotationVector.x = 0.0
rotationVector.y = x
rotationVector.z = 0.0
rotationVector.w = anglePan
node.rotation = rotationVector
if(gestureRecognize.state == UIGestureRecognizerState.ended) {
let currentPivot = node.pivot
let changePivot = SCNMatrix4Invert( node.transform)
node.pivot = SCNMatrix4Mult(changePivot, currentPivot)
node.transform = SCNMatrix4Identity
}
Run Code Online (Sandbox Code Playgroud)
这适用于 Euler 设置为 (x: 0, y: 0, z: 0) 的节点。但是我的节点有 Euler (x: -90, y: 0, z: 0)。对于我的欧拉值,上面的代码以错误的角度旋转对象。如何使用我的/不同的 Euler 值旋转节点?