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
}
}
“苹果”的方式是“自然的”,但我不喜欢它,尝试使用-y –