【发布时间】:2016-05-13 16:54:29
【问题描述】:
我想用 Scene 工具包创建一个应用程序来解决 Rubix Cube。我有自己的多维数据集 dae 文件。 这是我在 viewDidLoad 中的设置代码
let myscene = SCNScene(named: "Rubik1.scnassets/Rubiks_Cube.dae")
scene.rootNode.addChildNode((myscene?.rootNode)!)
// retrieve the SCNView
let scnView = self.view as! SCNView
// set the scene to the view
scnView.scene = scene
geometryNode = (scnView.scene?.rootNode.childNodeWithName("Cube",recursively: true))!
let panRecognizer = UIPanGestureRecognizer(target: self, action: "panGesture:")
scnView.addGestureRecognizer(panRecognizer)
在识别平移手势以旋转立方体时
func panGesture(gestureRecognize: UIPanGestureRecognizer){
let translation = gestureRecognize.translationInView(gestureRecognize.view!)
let x = Float(translation.x)
let y = Float(-translation.y)
let anglePan = sqrt(pow(x,2)+pow(y,2))*(Float)(M_PI)/180.0
var rotationVector = SCNVector4()
rotationVector.x = -y
rotationVector.y = x
rotationVector.z = 0
rotationVector.w = anglePan
geometryNode.rotation = rotationVector
//geometryNode.transform = SCNMatrix4MakeRotation(anglePan, -y, x, 0)
if(gestureRecognize.state == UIGestureRecognizerState.Ended) {
//
}
}
以上代码不保留之前的平移手势。如何使用“旋转向量”或
SCNMatrix4MakeRotation(anglePan, -y, x, 0)
旋转立方体
【问题讨论】: