首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过pan手势旋转SCNSphere/节点

如何通过pan手势旋转SCNSphere/节点
EN

Stack Overflow用户
提问于 2015-07-21 17:18:29
回答 1查看 1.9K关注 0票数 3

因此,对于一个个人项目,我决定在SceneKit中制作我自己的相机,它基本上复制默认的相机控制,除非用户放大,一个响亮的声音会播放,当放大时反之亦然。此外,我还希望当用户在球上平底时,声音会更快。我知道如何编辑声音,但我在实现潘手势有困难。

这是我的相机代码

代码语言:javascript
复制
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()
    }

下面是我的pan手势代码,它现在不起作用。相反,它向错误的方向旋转。

代码语言:javascript
复制
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
        }
        
      }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-06 21:53:02

我想出来了,它一直在工作,只是灯光看起来一点也不动。相反,我需要转动灯。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31545596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档