Ios 如何通过平移手势旋转SCNSphere/节点
因此,对于一个个人项目,我决定在SceneKit中制作我自己的相机,它基本上复制了默认的相机控件,除了当用户放大时,会发出很大的声音,反之亦然。此外,我还希望当用户在球上摇动时声音能更快。我知道如何编辑声音,但执行平移手势时遇到问题 这是我的相机代码Ios 如何通过平移手势旋转SCNSphere/节点,ios,swift,scenekit,uipangesturerecognizer,Ios,Swift,Scenekit,Uipangesturerecognizer,因此,对于一个个人项目,我决定在SceneKit中制作我自己的相机,它基本上复制了默认的相机控件,除了当用户放大时,会发出很大的声音,反之亦然。此外,我还希望当用户在球上摇动时声音能更快。我知道如何编辑声音,但执行平移手势时遇到问题 这是我的相机代码 let camera = SCNCamera() //contructing the camera camera.usesOrthographicProjection = true
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
}
}
我明白了,它一直在工作,只是灯光让它看起来好像什么都没动。相反,我需要旋转灯光。苹果的方式是“自然”的,但我不喜欢,尝试使用-y