SceneKit - 用鼠标旋转相机

时间:2017-03-19 17:55:34

标签: swift macos scenekit

我试图实现fps控制机制。问题是我的相机开始沿想要的方向移动然后来回跳跃...我也无法弄清楚如何连接2轴或更多轴。这是我的代码:

func gameView(didReceiveMouseMovedEvent event: NSEvent) {
        if let p = self.lastMouseP{
            var x:CGFloat = 0
            x = event.locationInWindow.x - p.x
            var y:CGFloat = 0
            y = event.locationInWindow.y - p.y
            self.player.move(cameraByX: 0, y: x, z: y, w: 0)
        }
        self.lastMouseP = event.locationInWindow
 }

在播放器文件中:

func move(cameraByX x: CGFloat, y: CGFloat, z:CGFloat, w:CGFloat){
        let rot = self.head.rotation
        let xx  = (x)*CGFloat(M_PI)/180.0 + rot.x
        let yy  = (y)*CGFloat(M_PI)/180.0 + rot.y
        let zz  = (z)*CGFloat(M_PI)/180.0 + rot.z
        //let xr = SCNMatrix4MakeRotation(xx, 1, 0, 0)
        let yr = SCNMatrix4MakeRotation(yy, 0, 1, 0)
        let zr = SCNMatrix4MakeRotation(zz, 0, 0, 1)
        self.head.transform = SCNMatrix4Mult(self.head.transform, zr)
}

0 个答案:

没有答案