大佬教程收集整理的这篇文章主要介绍了swift – 如何使用平移手势旋转场景中的对象 – SceneKit,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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) { // } }
上面的代码不保留以前的平移手势.我如何使用“rotationvector”或
SCNMatrix4MakeRotation(anglePan,0)
旋转立方体
以上是大佬教程为你收集整理的swift – 如何使用平移手势旋转场景中的对象 – SceneKit全部内容,希望文章能够帮你解决swift – 如何使用平移手势旋转场景中的对象 – SceneKit所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。