1
- //
2
- // ViewController.swift
3
- // Stickeee
4
- //
5
- // Created by Michael Ganzorig on 3/2/19.
6
- // Copyright © 2019 Michael Ganzorig. All rights reserved.
7
- //
8
-
9
1
import UIKit
10
2
import SpriteKit
11
3
import ARKit
@@ -20,21 +12,23 @@ class ViewController: UIViewController, ARSKViewDelegate, UITextFieldDelegate
20
12
static var loaded = false
21
13
22
14
//scene view for AR
23
- @IBOutlet var sceneView : ARSKView !
15
+ @IBOutlet weak var sceneView : ARSKView !
24
16
25
17
//text box
26
18
@IBOutlet weak var textBox : UITextField !
27
19
28
20
29
21
//after pressing done on text box
30
- @IBAction func pressedEnd( _ sender: Any ) {
22
+ @IBAction func pressedEnd( _ sender: Any )
23
+ {
31
24
textBox. isHidden = true //hides text box
32
25
button. isHidden = false //shows button
33
26
textBox. resignFirstResponder ( )
34
27
ViewController . userInput = textBox. text!
35
28
}
36
29
37
- @IBAction func snappybutton( _ sender: Any ) {
30
+ @IBAction func snappybutton( _ sender: Any )
31
+ {
38
32
let url = URL ( string: " https://www.stickplace.net/image/getSnapChatImage " )
39
33
let sticker = SCSDKSnapSticker ( stickerUrl: url!, isAnimated: false )
40
34
let snap = SCSDKNoSnapContent ( )
@@ -57,11 +51,10 @@ class ViewController: UIViewController, ARSKViewDelegate, UITextFieldDelegate
57
51
}
58
52
59
53
60
- override func viewDidLoad( ) {
54
+ override func viewDidLoad( )
55
+ {
61
56
super. viewDidLoad ( )
62
-
63
- addListenerToDatabase ( )
64
-
57
+
65
58
// Set the view's delegate
66
59
sceneView. delegate = self
67
60
@@ -73,86 +66,52 @@ class ViewController: UIViewController, ARSKViewDelegate, UITextFieldDelegate
73
66
if let scene = SKScene ( fileNamed: " Scene " ) {
74
67
sceneView. presentScene ( scene)
75
68
}
76
-
69
+ addListenerToDatabase ( )
77
70
}
78
71
79
72
func addListenerToDatabase( )
80
73
{
81
74
let ref = Database . database ( ) . reference ( )
82
75
83
76
ref. observe ( . childAdded, with: { ( snapshot) -> Void in
84
- // just for max value
85
- var lat : Double = 10000
86
- var lon : Double = 10000
77
+ var lat : Double = 0
78
+ var lon : Double = 0
87
79
var string : String ?
88
80
89
81
for child in snapshot. children. allObjects as? [ DataSnapshot ] ?? [ ]
90
82
{
91
- // later on prevent double spawn of stickers
92
- if let val = child. value as? Double
83
+ if child. key == " lat "
93
84
{
94
- if lat == 10000
95
- {
96
- lat = val
97
- }
98
- else if lon == 10000
99
- {
100
- lon = val
101
- }
102
- print ( " Key: " + ( child. key as? String ?? " none " ) + " Value: " + String( val) )
103
- } else
85
+ lat = ( child. value as? Double ) !
86
+ }
87
+ if child. key == " lon "
88
+ {
89
+ lon = ( child. value as? Double ) !
90
+ }
91
+ if child. key == " string "
104
92
{
105
- string = child. value as? String ?? " none "
106
- print ( " Key: " + String( child. key as? String ?? " none " ) + " Value: " + string!)
93
+ string = child. value as? String
107
94
}
108
95
}
109
-
110
- self . newStickerFromDatabase ( newLat: lat, newLon: lon, label: string!)
96
+ print ( " \n Lat: " + String( lat) )
97
+ print ( " Lon: " + String( lon) )
98
+ print ( " String: " + string! + " \n " )
99
+ self . newStickerFromDatabase ( lat, lon, string!)
111
100
} )
112
101
}
113
102
114
- func newStickerFromDatabase( newLat: Double , newLon: Double , label: String )
103
+ func newStickerFromDatabase( _ newLat: Double , _ newLon: Double , _ label: String )
115
104
{
116
- // Add a new sticker
117
- let currLocation = ( UIApplication . shared. delegate as! AppDelegate ) . getLocation ( )
118
- if currLocation != nil
105
+ if let currentFrame = sceneView. session. currentFrame
119
106
{
120
- if let sceneView = self . view as? ARSKView {
121
- if let currentFrame = sceneView. session. currentFrame
122
- {
123
- print ( " lat10: " + String( currLocation. coordinate. latitude) )
124
- var translation = matrix_identity_float4x4
125
- //print("\n"+String(currLocation.coordinate.latitude) + " " + String(currLocation.coordinate.longitude))
126
- //print("\n" + String(newLat) + " " + String(newLon))
127
-
128
- let xy = Sticker . GetXY ( lat1: currLocation. coordinate. latitude, lon1: currLocation. coordinate. longitude, lat2: newLat, lon2: newLon)
129
-
130
-
131
- translation. columns. 3 . y = Float ( xy [ " x " ] !)
132
- translation. columns. 3 . z = Float ( xy [ " y " ] ! - 0.2 )
133
- translation. columns. 3 . w = Float ( 1 )
134
- let transform = simd_mul ( currentFrame. camera. transform, translation)
135
- print ( currentFrame. camera. transform)
136
- Sticker ( transform: transform, sceneView: sceneView, latitude: xy [ " y " ] !, longitude: xy [ " x " ] !, lab: label)
137
- }
138
- return
139
- }
107
+ let xy = Sticker . GetXY ( lat2: newLat, lon2: newLon)
140
108
141
- if let currentFrame = sceneView. session. currentFrame
142
- {
143
- print ( " lat20: " + String( currLocation. coordinate. latitude) )
144
- var translation = matrix_identity_float4x4
145
-
146
- let xy = Sticker . GetXY ( lat1: currLocation. coordinate. latitude, lon1: currLocation. coordinate. longitude, lat2: newLat, lon2: newLon)
147
-
148
-
149
- translation. columns. 3 . y = Float ( xy [ " x " ] !)
150
- translation. columns. 3 . z = Float ( xy [ " y " ] ! - 0.2 )
151
- translation. columns. 3 . w = Float ( 1 )
152
- let transform = simd_mul ( currentFrame. camera. transform, translation)
153
- print ( currentFrame. camera. transform)
154
- Sticker ( transform: transform, sceneView: sceneView, latitude: xy [ " y " ] !, longitude: xy [ " x " ] !, lab: label)
155
- }
109
+ var translation = matrix_identity_float4x4
110
+ translation. columns. 3 . z = Float ( - xy[ " y " ] ! + 0.2 )
111
+ translation. columns. 3 . y = Float ( xy [ " x " ] !)
112
+
113
+ let transform = simd_mul ( currentFrame. camera. transform, translation)
114
+ Sticker ( transform, sceneView, xy [ " y " ] !, xy [ " x " ] !, label)
156
115
}
157
116
}
158
117
@@ -180,7 +139,7 @@ class ViewController: UIViewController, ARSKViewDelegate, UITextFieldDelegate
180
139
181
140
let labelNode = SKLabelNode ( text: anchor. name)
182
141
labelNode. fontName = " Arial "
183
- labelNode. fontSize = 68
142
+ labelNode. fontSize = 60
184
143
labelNode. horizontalAlignmentMode = . center
185
144
labelNode. verticalAlignmentMode = . center
186
145
return labelNode;
0 commit comments