2015-07-21 48 views
2

因此對於個人項目,我決定在SceneKit中製作自己的相機,該相機基本上覆制了默認的相機控件,除非用戶放大時播放響亮的聲音,縮小時反之亦然。另外,我還希望當用戶在球上晃動時聲音會更快。我知道如何編輯聲音,但我在執行平移手勢時遇到了問題。如何通過平移手勢旋轉SCNSphere /節點

這裏是我的相機代碼

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() 
    } 

那麼這裏就是我的移動手勢代碼,這不馬上工作。相反,它會以錯誤的方向旋轉。

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 
        } 
         
      } 
+1

「蘋果」的方式是「自然的」,但我不喜歡它,嘗試使用-y –

回答

0

我想通了,它一直在工作,只是照明設備看起來沒有任何動作。相反,我需要旋轉燈光。

相關問題