这是我在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) { // }}
上面的代码不保留以前的平移手势.我如何使用“rotationvector”或
SCNMatrix4MakeRotation(anglePan,0)
旋转立方体
解决方法 问题已经解决了if(gestureRecognize.state == UIGestureRecognizerState.Ended) { let currentPivot = geometryNode.pivot let changePivot = SCNMatrix4Invert( geometryNode.transform) geometryNode.pivot = SCNMatrix4Mult(changePivot,currentPivot) geometryNode.transform = SCNMatrix4IDentity}总结
以上是内存溢出为你收集整理的swift – 如何使用平移手势旋转场景中的对象 – SceneKit全部内容,希望文章能够帮你解决swift – 如何使用平移手势旋转场景中的对象 – SceneKit所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)