How to rotate SCNSphere / Node using panorama gestures

So, for a personal project, I decided to make my own camera in SceneKit, which basically replicated the default camera controls, except when the user zoomed in, there was a loud sound, on the contrary when zooming. In addition, I also wanted the sound to accelerate when the user pressed the ball. I know how to edit sound, but I am having problems implementing gestures.

Here is my camera code

let camera = SCNCamera()
         //contructing the camera
            camera.usesOrthographicProjection = true
            camera.orthographicScale = 5
            let cameraNode = SCNNode()
            cameraNode.camera = camera
            cameraNode.position = SCNVector3Make(0, 0, 15)
            scene.rootNode.addChildNode(cameraNode)
              
        //adding a pan recognizer (This doesn’t work)
            var panRecognizer = UIPanGestureRecognizer(target: self, action: "panGesture:")
            sceneView.addGestureRecognizer(panRecognizer)

            //adding a pinch recognizer (This works)
            var pinchRecognizer = UIPinchGestureRecognizer(target: self, action: "pinchGesture:")
            sceneView.addGestureRecognizer(pinchRecognizer)
                    
            sceneView.scene = scene 
            
        }
        
        
        super.viewDidAppear(animated)
        sceneSetup()
    }

      

Then here is my gesture code which is not working right now. Instead, it rotates in the wrong direction.

func panGesture(sender: UIPanGestureRecognizer) {
    //getting the CGpoint at the end of the pan
        let translation = sender.translationInView(sender.view!)
    //creating a new angle in radians from the x value
        var newAngle = (Float)(translation.x)*(Float)(M_PI)/180.0
    //current angle is an instance variable so i am adding the newAngle to the newAngle to it 
        newAngle += currentAngle

        //transforming the sphere node
        geometryNode.transform = SCNMatrix4MakeRotation(newAngle, Float(translation.x), Float(translation.y),Float(0.0))
        
        //getting the end angle of the swipe put into the instance variable
        if(sender.state == UIGestureRecognizerState.Ended) {
            currentAngle = newAngle
        }
        
      }

      

+3


source to share


1 answer


I figured it out, it was running all the time, just that the lighting appeared like nothing was moving. Instead, I needed to turn the light.



0


source







All Articles