gpt4 book ai didi

ios - 如何通过平移手势旋转 SCNSphere/Node

转载 作者:可可西里 更新时间:2023-10-31 23:44:41 25 4
gpt4 key购买 nike

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

这是我的相机代码

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

最佳答案

我想通了,它一直在工作,只是灯光使它看起来像什么都没有动过。相反,我需要旋转灯光。

关于ios - 如何通过平移手势旋转 SCNSphere/Node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31545596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com