2 // GameViewController.swift
5 // Created by Alan Knowles on 30/3/2022.
12 class GameViewController: UIViewController {
14 override func loadView()
16 let scnView = SCNView()
22 override func viewDidLoad() {
26 let scene = SCNScene(named: "art.scnassets/ship.scn")!
28 // create and add a camera to the scene
29 let cameraNode = SCNNode()
30 cameraNode.camera = SCNCamera()
31 scene.rootNode.addChildNode(cameraNode)
34 cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
36 // create and add a light to the scene
37 let lightNode = SCNNode()
38 lightNode.light = SCNLight()
39 lightNode.light!.type = .omni
40 lightNode.position = SCNVector3(x: 0, y: 10, z: 10)
41 scene.rootNode.addChildNode(lightNode)
43 // create and add an ambient light to the scene
44 let ambientLightNode = SCNNode()
45 ambientLightNode.light = SCNLight()
46 ambientLightNode.light!.type = .ambient
47 ambientLightNode.light!.color = UIColor.darkGray
48 scene.rootNode.addChildNode(ambientLightNode)
50 // retrieve the ship node
51 //let ship = scene.rootNode.childNode(withName: "ship", recursively: true)!
53 // animate the 3d object
54 //ship.runAction(SCNAction.repeatForever(SCNAction.rotateBy(x: 0, y: 2, z: 0, duration: 1)))
56 // retrieve the SCNView
57 let scnView = self.view as! SCNView
59 // set the scene to the view
62 // allows the user to manipulate the camera
63 scnView.allowsCameraControl = true
65 // show statistics such as fps and timing information
66 scnView.showsStatistics = true
69 scnView.backgroundColor = UIColor.red
71 // add a tap gesture recognizer
72 //let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
73 //scnView.addGestureRecognizer(tapGesture)
79 override var shouldAutorotate: Bool {
83 override var prefersStatusBarHidden: Bool {
87 override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
88 if UIDevice.current.userInterfaceIdiom == .phone {
89 return .allButUpsideDown