SCNVector4:在X轴上旋转
问题描述:
我有一个球体并设法旋转它。但不幸的是沿着错误的轴线。SCNVector4:在X轴上旋转
我的目标是旋转像地球沿x轴。你能帮我申请吗?
这里是我现有的代码:
let spin = CABasicAnimation(keyPath: "rotation")
// Use from-to to explicitly make a full rotation around z
spin.fromValue = NSValue(scnVector4: SCNVector4(x: 1, y: 0, z: 0, w: 0))
spin.toValue = NSValue(scnVector4: SCNVector4(x: 1, y: 0, z: 0, w: Float(CGFloat(-2 * Double.pi))))
spin.duration = 30
spin.repeatCount = .infinity
sphereNode.addAnimation(spin, forKey: "spin around")
答
它会是这样的
self.imageView.layer.transform = CATransform3DConcat(self.imageView.layer.transform, CATransform3DMakeRotation(M_PI,1.0,0.0,0.0));
答
你已经工作液:
spin.fromValue = NSValue(scnVector4: SCNVector4(x: 1, y: 0, z: 0, w: 0))
spin.toValue = NSValue(scnVector4: SCNVector4(x: 1, y: 0, z: 0, w: CGFloat.pi * 2))
如果你想改变方向,只是改变载体:)
spin.fromValue = NSValue(scnVector4: SCNVector4(x: 1, y: 0, z: 0, w: CGFloat.pi * 2))
spin.toValue = NSValue(scnVector4: SCNVector4(x: 1, y: 0, z: 0, w: 0))
+0
是的,它正在旋转。但沿着错误的轴线。我不明白w是什么。 – netshark1000
+0
@ netshark1000哦,改变轴 - 改变x,y,z:旋转by'x' ='SCNVector4(x:1,y:0,z:0,w:CGFloat.pi * 2)', y'='SCNVector4(x:0,y:1,z:0,w:CGFloat.pi * 2)',通过'z' ='SCNVector4(x:0,y:0,z:1,w :CGFloat.pi * 2)' –
映射在球体上的图像已经在旋转。只是在错误的方向。我没有看到imageView在你的代码中? – netshark1000
这是一个球形图像 –
可以将它应用于我的代码吗? – netshark1000