Skip to content

Commit e4b4208

Browse files
committedMar 7, 2019
not so useful changes
1 parent ca3d15b commit e4b4208

7 files changed

+84
-145
lines changed
 

‎Stickeee/AppDelegate.swift

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
//
2-
// AppDelegate.swift
3-
// Stickeee
4-
//
5-
// Created by Michael Ganzorig on 3/2/19.
6-
// Copyright © 2019 Michael Ganzorig. All rights reserved.
7-
//
8-
91
import UIKit
102
import CoreLocation
113
import Firebase
124

135
@UIApplicationMain
146
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate
157
{
16-
178
var window: UIWindow?
189
var locationManager: CLLocationManager!
19-
10+
2011
func getLocation() -> CLLocation
2112
{
2213
var currentLocation: CLLocation!
@@ -37,7 +28,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate
3728
locationManager.desiredAccuracy=kCLLocationAccuracyBest
3829
locationManager.startUpdatingLocation()
3930
locationManager.startUpdatingHeading()
40-
4131
locationManager.requestWhenInUseAuthorization()
4232

4333
FirebaseApp.configure()

‎Stickeee/Info.plist

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>CFBundleURLSchemes</key>
6-
<array>
7-
<string>example</string>
8-
</array>
9-
<key>LSApplicationQueriesSchemes</key>
10-
<array>
11-
<string>snapchat</string>
12-
</array>
13-
<key>SCSDKRedirectUrl</key>
14-
<string>example://redirect</string>
15-
<key>SCSDKClientId</key>
16-
<string>616c0a63-31db-47a1-85ab-1d5e24dba34d</string>
175
<key>CFBundleDevelopmentRegion</key>
186
<string>$(DEVELOPMENT_LANGUAGE)</string>
197
<key>CFBundleExecutable</key>
@@ -28,10 +16,18 @@
2816
<string>APPL</string>
2917
<key>CFBundleShortVersionString</key>
3018
<string>1.0</string>
19+
<key>CFBundleURLSchemes</key>
20+
<array>
21+
<string>example</string>
22+
</array>
3123
<key>CFBundleVersion</key>
3224
<string>1</string>
3325
<key>LSApplicationCategoryType</key>
3426
<string></string>
27+
<key>LSApplicationQueriesSchemes</key>
28+
<array>
29+
<string>snapchat</string>
30+
</array>
3531
<key>LSRequiresIPhoneOS</key>
3632
<true/>
3733
<key>NSCameraUsageDescription</key>
@@ -40,6 +36,10 @@
4036
<string>I need your location</string>
4137
<key>NSLocationWhenInUseUsageDescription</key>
4238
<string>I need your location</string>
39+
<key>SCSDKClientId</key>
40+
<string>616c0a63-31db-47a1-85ab-1d5e24dba34d</string>
41+
<key>SCSDKRedirectUrl</key>
42+
<string>example://redirect</string>
4343
<key>UILaunchStoryboardName</key>
4444
<string>LaunchScreen</string>
4545
<key>UIMainStoryboardFile</key>

‎Stickeee/Networking.swift

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
//
2-
// Networking.swift
3-
// Stickeee
4-
//
5-
// Created by Michael Ganzorig on 3/2/19.
6-
// Copyright © 2019 Michael Ganzorig. All rights reserved.
7-
//
8-
91
import Foundation
102
import ARKit
113
import SpriteKit
@@ -16,9 +8,9 @@ class Networking
168
{
179
init() {}
1810

19-
static func UploadToServer(sticker: Sticker?)
11+
static func UploadToServer(lat: Double, lon: Double, name: String)
2012
{
2113
let ref = Database.database().reference()
22-
ref.childByAutoId().setValue(["lat": sticker?.lat, "lon": sticker?.lon, "string": sticker?.anchor.name])
14+
ref.childByAutoId().setValue(["lat": lat, "lon": lon, "string": name])
2315
}
2416
}

‎Stickeee/Scene.swift

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
//
2-
// Scene.swift
3-
// Stickeee
4-
//
5-
// Created by Michael Ganzorig on 3/2/19.
6-
// Copyright © 2019 Michael Ganzorig. All rights reserved.
7-
//
8-
91
import SpriteKit
102
import ARKit
113

@@ -19,14 +11,24 @@ class Scene: SKScene {
1911
// Called before each frame is rendered
2012
}
2113

22-
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
14+
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
15+
{
2316
guard let sceneView = self.view as? ARSKView else {
2417
return
2518
}
2619

20+
if ViewController.userInput != ""
21+
{
22+
let currLocation = (UIApplication.shared.delegate as! AppDelegate).getLocation()
23+
Networking.UploadToServer(lat: currLocation.coordinate.latitude,
24+
lon: currLocation.coordinate.longitude,
25+
name: ViewController.userInput)
26+
}
27+
28+
/*
2729
// Create anchor using the camera's current position
28-
if let currentFrame = sceneView.session.currentFrame {
29-
30+
if let currentFrame = sceneView.session.currentFrame
31+
{
3032
// Create a transform with a translation of 0.2 meters in front of the camera
3133
var translation = matrix_identity_float4x4
3234
translation.columns.3.z = -0.2
@@ -35,14 +37,13 @@ class Scene: SKScene {
3537
// Add a new sticker
3638
let currLocation = (UIApplication.shared.delegate as! AppDelegate).getLocation()
3739

38-
if currLocation != nil && ViewController.userInput != ""
39-
{
40-
let sticker = Sticker(transform: transform, sceneView: sceneView, latitude: currLocation.coordinate.latitude, longitude: currLocation.coordinate.longitude, lab: ViewController.userInput)
41-
Networking.UploadToServer(sticker: sticker)
42-
} else
40+
if ViewController.userInput != ""
4341
{
44-
print("The sticker is null")
42+
Networking.UploadToServer(lat: currLocation.coordinate.latitude,
43+
lon: currLocation.coordinate.longitude,
44+
name: ViewController.userInput)
4545
}
4646
}
47+
*/
4748
}
4849
}

‎Stickeee/SpawnManager.swift

-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
//
2-
// SpawnManager.swift
3-
// Stickeee
4-
//
5-
// Created by Michael Ganzorig on 3/2/19.
6-
// Copyright © 2019 Michael Ganzorig. All rights reserved.
7-
//
8-
91
import Foundation
102
import SpriteKit
113

‎Stickeee/Sticker.swift

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
//
2-
// Sticker.swift
3-
// Stickeee
4-
//
5-
// Created by Michael Ganzorig on 3/2/19.
6-
// Copyright © 2019 Michael Ganzorig. All rights reserved.
7-
//
8-
91
import Foundation
102
import ARKit
113
import SpriteKit
@@ -18,7 +10,7 @@ class Sticker
1810
let lat: Double
1911
let lon: Double
2012

21-
init(transform: simd_float4x4, sceneView: ARSKView, latitude: Double, longitude: Double, lab: String)
13+
init(_ transform: simd_float4x4, _ sceneView: ARSKView, _ latitude: Double, _ longitude: Double, _ lab: String)
2214
{
2315
lat = latitude
2416
lon = longitude
@@ -30,19 +22,32 @@ class Sticker
3022

3123
static func LatLonToMetres(lat1: Double, lon1: Double, lat2: Double, lon2: Double) -> Double
3224
{
25+
print("From lat: " + String(lat1))
26+
print("From lon: " + String(lon1))
3327
let co1 = CLLocation(latitude: lat1, longitude: lon1)
3428
let co2 = CLLocation(latitude: lat2, longitude: lon2)
3529

3630
return co1.distance(from: co2)
31+
32+
/*let R = 6378.137 // Radius of earth in KM
33+
let dLat = lat2 * Double.pi / 180 - lat1 * Double.pi / 180;
34+
let dLon = lon2 * Double.pi / 180 - lon1 * Double.pi / 180;
35+
let a = sin(dLat/2) * sin(dLat/2) + cos(lat1 * Double.pi / 180) * cos(lat2 * Double.pi / 180) * sin(dLon/2) * sin(dLon/2);
36+
let c = 2 * atan2(sqrt(a), sqrt(1-a));
37+
let d = R * c;
38+
return d * 1000; // meters*/
3739
}
3840

39-
static func GetXY(lat1: Double, lon1: Double, lat2: Double, lon2: Double) -> Dictionary<String, Double>
41+
static func GetXY(lat2: Double, lon2: Double) -> Dictionary<String, Double>
4042
{
41-
if(lon1 == lon2 && lat1 == lat2)
43+
let currLocation = (UIApplication.shared.delegate as! AppDelegate).getLocation()
44+
let lat1 = currLocation.coordinate.latitude
45+
let lon1 = currLocation.coordinate.longitude
46+
47+
if lon1 == lon2 && lat1 == lat2
4248
{
4349
return ["x": 0, "y": 0]
4450
}
45-
4651
var y = lat2 - lat1
4752
var x = lon2 - lon1
4853

‎Stickeee/ViewController.swift

+34-75
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
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-
91
import UIKit
102
import SpriteKit
113
import ARKit
@@ -20,21 +12,23 @@ class ViewController: UIViewController, ARSKViewDelegate, UITextFieldDelegate
2012
static var loaded = false
2113

2214
//scene view for AR
23-
@IBOutlet var sceneView: ARSKView!
15+
@IBOutlet weak var sceneView: ARSKView!
2416

2517
//text box
2618
@IBOutlet weak var textBox: UITextField!
2719

2820

2921
//after pressing done on text box
30-
@IBAction func pressedEnd(_ sender: Any) {
22+
@IBAction func pressedEnd(_ sender: Any)
23+
{
3124
textBox.isHidden = true //hides text box
3225
button.isHidden = false //shows button
3326
textBox.resignFirstResponder()
3427
ViewController.userInput = textBox.text!
3528
}
3629

37-
@IBAction func snappybutton(_ sender: Any) {
30+
@IBAction func snappybutton(_ sender: Any)
31+
{
3832
let url = URL(string: "https://www.stickplace.net/image/getSnapChatImage")
3933
let sticker = SCSDKSnapSticker(stickerUrl: url!, isAnimated: false)
4034
let snap = SCSDKNoSnapContent()
@@ -57,11 +51,10 @@ class ViewController: UIViewController, ARSKViewDelegate, UITextFieldDelegate
5751
}
5852

5953

60-
override func viewDidLoad() {
54+
override func viewDidLoad()
55+
{
6156
super.viewDidLoad()
62-
63-
addListenerToDatabase()
64-
57+
6558
// Set the view's delegate
6659
sceneView.delegate = self
6760

@@ -73,86 +66,52 @@ class ViewController: UIViewController, ARSKViewDelegate, UITextFieldDelegate
7366
if let scene = SKScene(fileNamed: "Scene") {
7467
sceneView.presentScene(scene)
7568
}
76-
69+
addListenerToDatabase()
7770
}
7871

7972
func addListenerToDatabase()
8073
{
8174
let ref = Database.database().reference()
8275

8376
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
8779
var string: String?
8880

8981
for child in snapshot.children.allObjects as? [DataSnapshot] ?? []
9082
{
91-
// later on prevent double spawn of stickers
92-
if let val = child.value as? Double
83+
if child.key == "lat"
9384
{
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"
10492
{
105-
string = child.value as? String ?? "none"
106-
print("Key: " + String(child.key as? String ?? "none") + " Value: " + string!)
93+
string = child.value as? String
10794
}
10895
}
109-
110-
self.newStickerFromDatabase(newLat: lat, newLon: lon, label: string!)
96+
print("\nLat: " + String(lat))
97+
print("Lon: " + String(lon))
98+
print("String: " + string! + "\n")
99+
self.newStickerFromDatabase(lat, lon, string!)
111100
})
112101
}
113102

114-
func newStickerFromDatabase(newLat: Double, newLon: Double, label: String)
103+
func newStickerFromDatabase(_ newLat: Double, _ newLon: Double, _ label: String)
115104
{
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
119106
{
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)
140108

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)
156115
}
157116
}
158117

@@ -180,7 +139,7 @@ class ViewController: UIViewController, ARSKViewDelegate, UITextFieldDelegate
180139

181140
let labelNode = SKLabelNode(text: anchor.name)
182141
labelNode.fontName = "Arial"
183-
labelNode.fontSize = 68
142+
labelNode.fontSize = 60
184143
labelNode.horizontalAlignmentMode = .center
185144
labelNode.verticalAlignmentMode = .center
186145
return labelNode;

0 commit comments

Comments
 (0)
Please sign in to comment.