0
我正在使用下面的代码来使用平移手势旋转节点。我只想在y轴上旋转我的节点。在SceneKit中使用平移手势旋转节点iOS
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
}
这适用于Euler设置为(x:0,y:0,z:0)的节点。但是我的节点有Euler(x:-90,y:0,z:0)。对于我上面的欧拉值,代码以错误的角度旋转对象。如何使用我的/不同的欧拉值来旋转节点?
因此,当您设置欧拉角度时,您希望旋转轴与节点一起旋转吗? – orangenkopf
我想是的。我是新来的现场套件,所以我不确定旋转会影响欧拉。但我需要的是将我的节点水平旋转(y轴),其中欧拉x值设置为-90 – prabhu