33// PanoView
44//
55// Created by idz on 5/1/16.
6- // Copyright © 2016 iOS Developer Zone.
6+ // Copyright © 2016 iOS Developer Zone.
77// License: MIT https://raw.githubusercontent.com/iosdevzone/PanoView/master/LICENSE
88//
99
@@ -18,7 +18,7 @@ class ViewController: UIViewController {
1818
1919
2020 @IBOutlet weak var sceneView : SCNView !
21-
21+
2222 override func viewDidLoad( ) {
2323 super. viewDidLoad ( )
2424 // Load assets
@@ -43,51 +43,33 @@ class ViewController: UIViewController {
4343 sphereNode. position = SCNVector3Make ( 0 , 0 , 0 )
4444 scene. rootNode. addChildNode ( sphereNode)
4545
46- // Lights, ...
47- let ambientLightNode = SCNNode ( )
48- ambientLightNode. light = SCNLight ( )
49- ambientLightNode. light!. type = SCNLightTypeAmbient
50- ambientLightNode. light!. color = UIColor ( white: 0.67 , alpha: 1.0 )
51- scene. rootNode. addChildNode ( ambientLightNode)
52-
5346 // Camera, ...
5447 cameraNode. camera = SCNCamera ( )
5548 cameraNode. position = SCNVector3Make ( 0 , 0 , 0 )
5649 scene. rootNode. addChildNode ( cameraNode)
50+
5751
58- // Action (Sorry! I could not help myself)
59- if motionManager. deviceMotionAvailable {
60- motionManager. deviceMotionUpdateInterval = 1.0 / 60.0
61- motionManager. startDeviceMotionUpdatesToQueue ( NSOperationQueue . mainQueue ( ) ) {
62- [ weak self] ( data: CMDeviceMotion ? , error: NSError ? ) in
63-
64- guard let data = data else {
65- NSLog ( " Error in deviceMotionUpdate \( error) " )
66- return
67- }
68- guard let strongSelf = self else {
69- NSLog ( " Captured weak self was nil in deviceMotionUpdate " )
70- return
71- }
72-
73- let attitude : CMAttitude = data. attitude
74-
75- strongSelf. cameraNode. eulerAngles = SCNVector3Make ( Float ( attitude. roll - M_PI/ 2.0 ) , Float ( attitude. yaw) , Float ( attitude. pitch) )
76- }
77-
78- }
79- else {
52+ guard motionManager. deviceMotionAvailable else {
8053 fatalError ( " Device motion is not available " )
8154 }
82-
83-
55+
56+ // Action
57+ motionManager. deviceMotionUpdateInterval = 1.0 / 60.0
58+ motionManager. startDeviceMotionUpdatesToQueue ( NSOperationQueue . mainQueue ( ) ) {
59+ [ weak self] ( data: CMDeviceMotion ? , error: NSError ? ) in
60+
61+ guard let data = data else { return }
62+
63+ let attitude : CMAttitude = data. attitude
64+ self ? . cameraNode. eulerAngles = SCNVector3Make ( Float ( attitude. roll - M_PI/ 2.0 ) , Float ( attitude. yaw) , Float ( attitude. pitch) )
65+ }
8466 }
85-
67+
8668 override func didReceiveMemoryWarning( ) {
8769 super. didReceiveMemoryWarning ( )
8870 // Dispose of any resources that can be recreated.
8971 }
90-
91-
72+
73+
9274}
9375
0 commit comments