add correct code
[app.GameProjectTest] / GameProjectTest / GameViewController.swift
1 //
2 //  GameViewController.swift
3 //  GameProjectTwo
4 //
5 //  Created by Alan Knowles on 30/3/2022.
6 //
7
8 import UIKit
9 import QuartzCore
10 import SceneKit
11
12 class GameViewController: UIViewController {
13     
14     override func loadView()
15     {
16         let scnView  = SCNView()
17         self.view = scnView
18         
19     }
20     
21
22     override func viewDidLoad() {
23         super.viewDidLoad()
24         
25         // create a new scene
26         let scene = SCNScene(named: "art.scnassets/ship.scn")!
27         
28         // create and add a camera to the scene
29         let cameraNode = SCNNode()
30         cameraNode.camera = SCNCamera()
31         scene.rootNode.addChildNode(cameraNode)
32         
33         // place the camera
34         cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
35         
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)
42         
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)
49         
50         // retrieve the ship node
51         //let ship = scene.rootNode.childNode(withName: "ship", recursively: true)!
52         
53         // animate the 3d object
54         //ship.runAction(SCNAction.repeatForever(SCNAction.rotateBy(x: 0, y: 2, z: 0, duration: 1)))
55         
56         // retrieve the SCNView
57         let scnView = self.view as! SCNView
58         
59         // set the scene to the view
60         scnView.scene = scene
61         
62         // allows the user to manipulate the camera
63         scnView.allowsCameraControl = true
64         
65         // show statistics such as fps and timing information
66         scnView.showsStatistics = true
67         
68         // configure the view
69         scnView.backgroundColor = UIColor.red
70         
71         // add a tap gesture recognizer
72         //let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
73         //scnView.addGestureRecognizer(tapGesture)
74          
75     }
76     
77    
78     
79     override var shouldAutorotate: Bool {
80         return true
81     }
82     
83     override var prefersStatusBarHidden: Bool {
84         return true
85     }
86     
87     override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
88         if UIDevice.current.userInterfaceIdiom == .phone {
89             return .allButUpsideDown
90         } else {
91             return .all
92         }
93     }
94
95 }