2017-09-06 213 views
0

我有一個球體並設法旋轉它。但不幸的是沿着錯誤的軸線。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") 

回答

-1

它會是這樣的

self.imageView.layer.transform = CATransform3DConcat(self.imageView.layer.transform, CATransform3DMakeRotation(M_PI,1.0,0.0,0.0)); 
+0

映射在球體上的圖像已經在旋轉。只是在錯誤的方向。我沒有看到imageView在你的代碼中? – netshark1000

+0

這是一個球形圖像 –

+0

可以將它應用於我的代碼嗎? – netshark1000

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)' –