3
3
// PanoView
4
4
//
5
5
// Created by idz on 5/1/16.
6
- // Copyright © 2016 iOS Developer Zone.
6
+ // Copyright © 2016 iOS Developer Zone.
7
7
// License: MIT https://raw.githubusercontent.com/iosdevzone/PanoView/master/LICENSE
8
8
//
9
9
@@ -18,7 +18,7 @@ class ViewController: UIViewController {
18
18
19
19
20
20
@IBOutlet weak var sceneView : SCNView !
21
-
21
+
22
22
override func viewDidLoad( ) {
23
23
super. viewDidLoad ( )
24
24
// Load assets
@@ -43,51 +43,33 @@ class ViewController: UIViewController {
43
43
sphereNode. position = SCNVector3Make ( 0 , 0 , 0 )
44
44
scene. rootNode. addChildNode ( sphereNode)
45
45
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
-
53
46
// Camera, ...
54
47
cameraNode. camera = SCNCamera ( )
55
48
cameraNode. position = SCNVector3Make ( 0 , 0 , 0 )
56
49
scene. rootNode. addChildNode ( cameraNode)
50
+
57
51
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 {
80
53
fatalError ( " Device motion is not available " )
81
54
}
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
+ }
84
66
}
85
-
67
+
86
68
override func didReceiveMemoryWarning( ) {
87
69
super. didReceiveMemoryWarning ( )
88
70
// Dispose of any resources that can be recreated.
89
71
}
90
-
91
-
72
+
73
+
92
74
}
93
75
0 commit comments