I am contacting to create a plot suite application for a Rubix Cube solution. I have my own dae file for the cube. this is my installation code in 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)
when detecting rotation to rotate the cube
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
Above code does not save previous gestures. how to use "rotationvector" or
SCNMatrix4MakeRotation(anglePan, -y, x, 0)
to rotate the cube
source share