Skip to content

Commit 638cbdc

Browse files
committed
Switched default orientation to true north
1 parent ad21ffa commit 638cbdc

13 files changed

+133
-32
lines changed

Turbah.xcodeproj/project.pbxproj

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
FAA121EE24C50C4A009F12C2 /* UserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA121ED24C50C4A009F12C2 /* UserDefaults.swift */; };
2222
FAA121F124C50CAC009F12C2 /* SegmentedCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA121F024C50CAC009F12C2 /* SegmentedCell.swift */; };
2323
FAA121F324C52F2F009F12C2 /* ContactCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA121F224C52F2F009F12C2 /* ContactCell.swift */; };
24+
FAA121FA24C69ADA009F12C2 /* ImageEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA121F924C69ADA009F12C2 /* ImageEntity.swift */; };
25+
FAA121FC24C6A935009F12C2 /* DistanceCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA121FB24C6A935009F12C2 /* DistanceCell.swift */; };
2426
FACE7EB524C15494002FE5FC /* ErrorOverlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = FACE7EB424C15494002FE5FC /* ErrorOverlay.swift */; };
2527
FACE7EB724C173FE002FE5FC /* LocationsListMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = FACE7EB624C173FE002FE5FC /* LocationsListMenu.swift */; };
2628
FACE7EB924C176EB002FE5FC /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = FACE7EB824C176EB002FE5FC /* Location.swift */; };
@@ -45,6 +47,8 @@
4547
FAA121ED24C50C4A009F12C2 /* UserDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaults.swift; sourceTree = "<group>"; };
4648
FAA121F024C50CAC009F12C2 /* SegmentedCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentedCell.swift; sourceTree = "<group>"; };
4749
FAA121F224C52F2F009F12C2 /* ContactCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactCell.swift; sourceTree = "<group>"; };
50+
FAA121F924C69ADA009F12C2 /* ImageEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageEntity.swift; sourceTree = "<group>"; };
51+
FAA121FB24C6A935009F12C2 /* DistanceCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DistanceCell.swift; sourceTree = "<group>"; };
4852
FACE7EB424C15494002FE5FC /* ErrorOverlay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorOverlay.swift; sourceTree = "<group>"; };
4953
FACE7EB624C173FE002FE5FC /* LocationsListMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationsListMenu.swift; sourceTree = "<group>"; };
5054
FACE7EB824C176EB002FE5FC /* Location.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = "<group>"; };
@@ -108,6 +112,7 @@
108112
children = (
109113
FAA121EF24C50C8E009F12C2 /* Settings */,
110114
FACE7EB824C176EB002FE5FC /* Location.swift */,
115+
FAA121F924C69ADA009F12C2 /* ImageEntity.swift */,
111116
FA51865624C13A56009064F6 /* CustomTurbah.swift */,
112117
FACE7EC024C4006D002FE5FC /* CompassView.swift */,
113118
FA8EC36024BFD452004FF5E2 /* VisualEffectButton.swift */,
@@ -126,6 +131,7 @@
126131
FA51865424C133AD009064F6 /* SettingsFooterView.swift */,
127132
FAA121F024C50CAC009F12C2 /* SegmentedCell.swift */,
128133
FAA121F224C52F2F009F12C2 /* ContactCell.swift */,
134+
FAA121FB24C6A935009F12C2 /* DistanceCell.swift */,
129135
);
130136
path = Settings;
131137
sourceTree = "<group>";
@@ -146,6 +152,8 @@
146152
dependencies = (
147153
);
148154
name = Turbah;
155+
packageProductDependencies = (
156+
);
149157
productName = Turbah;
150158
productReference = FA7A250424BFA497003D8825 /* Turbah.app */;
151159
productType = "com.apple.product-type.application";
@@ -174,6 +182,8 @@
174182
Base,
175183
);
176184
mainGroup = FA7A24FB24BFA497003D8825;
185+
packageReferences = (
186+
);
177187
productRefGroup = FA7A250524BFA497003D8825 /* Products */;
178188
projectDirPath = "";
179189
projectRoot = "";
@@ -200,9 +210,11 @@
200210
isa = PBXSourcesBuildPhase;
201211
buildActionMask = 2147483647;
202212
files = (
213+
FAA121FA24C69ADA009F12C2 /* ImageEntity.swift in Sources */,
203214
FA8EC36324BFD48D004FF5E2 /* Super.swift in Sources */,
204215
FAA121F324C52F2F009F12C2 /* ContactCell.swift in Sources */,
205216
FACE7EB524C15494002FE5FC /* ErrorOverlay.swift in Sources */,
217+
FAA121FC24C6A935009F12C2 /* DistanceCell.swift in Sources */,
206218
FA8EC36124BFD452004FF5E2 /* VisualEffectButton.swift in Sources */,
207219
FACE7EB924C176EB002FE5FC /* Location.swift in Sources */,
208220
FACE7EB724C173FE002FE5FC /* LocationsListMenu.swift in Sources */,

Turbah.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Turbah/Classes/CustomTurbah.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import UIKit
1010
import RealityKit
1111

12-
class CustomTurbah: Entity, HasModel, HasAnchoring, HasCollision {
12+
class CustomTurbah: Entity, HasModel, HasAnchoring {
1313

1414
required init(color: UIColor, size: Float) {
1515
super.init()
@@ -28,8 +28,6 @@ class CustomTurbah: Entity, HasModel, HasAnchoring, HasCollision {
2828
self.position = position
2929
}
3030

31-
required init() {
32-
fatalError("init() has not been implemented")
33-
}
31+
required init() { fatalError("init() has not been implemented") }
3432

3533
}

Turbah/Classes/ImageEntity.swift

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// ImageEntity.swift
3+
// Turbah
4+
//
5+
// Created by MMQ on 7/20/20.
6+
// Copyright © 2020 MMQ. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import RealityKit
11+
12+
//class ImageEntity: Entity, HasModel, HasAnchoring {
13+
//
14+
// let location: Locations
15+
//
16+
// required init(location: Locations) {
17+
// self.location = location
18+
// super.init()
19+
// }
20+
//
21+
// required init() { fatalError("init() has not been implemented") }
22+
//
23+
//}

Turbah/Classes/Location.swift

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Coordinates.swift
2+
// Location.swift
33
// Turbah
44
//
55
// Created by MMQ on 7/17/20.
@@ -60,6 +60,23 @@ enum Locations {
6060
case .test: return "Test"
6161
}
6262
}
63+
64+
var imageString: String {
65+
switch self {
66+
case .kabah: return "Launch"
67+
case .aqsa: return "Launch"
68+
case .prophet: return "Launch"
69+
case .ali: return "Launch"
70+
case .hussain: return "Launch"
71+
case .reza: return "Launch"
72+
case .askariain: return "Launch"
73+
case .baqi: return "Launch"
74+
case .masuma: return "Launch"
75+
case .zainab: return "Launch"
76+
case .test: return "Launch"
77+
}
78+
}
79+
6380
}
6481

6582
extension Double {

Turbah/Classes/Settings/ContactCell.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class ContactCell: UITableViewCell {
2525
])
2626

2727
stack.axis = .horizontal
28-
stack.alignment = .fill
29-
stack.distribution = .fill
28+
stack.alignment = .center
29+
stack.distribution = .fillProportionally
3030
stack.spacing = 15
3131
stack.addArrangedSubview(iconImageView)
3232
stack.addArrangedSubview(infoLabel)
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// DistanceCell.swift
3+
// Turbah
4+
//
5+
// Created by MMQ on 7/21/20.
6+
// Copyright © 2020 MMQ. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class DistanceCell: UITableViewCell {
12+
13+
static let id = "distanceCell"
14+
15+
private var stack = UIStackView()
16+
var titleLabel = UILabel()
17+
var distanceSlider = UISlider()
18+
19+
private func setupUI() {
20+
stack.axis = .vertical
21+
stack.alignment = .leading
22+
stack.distribution = .fillProportionally
23+
stack.spacing = 10
24+
stack.addArrangedSubview(titleLabel)
25+
stack.addArrangedSubview(distanceSlider)
26+
addSubview(stack)
27+
stack.fillSuperview(padding: UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15))
28+
}
29+
30+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
31+
super.init(style: style, reuseIdentifier: reuseIdentifier)
32+
setupUI()
33+
}
34+
35+
required init?(coder: NSCoder) {
36+
super.init(coder: coder)
37+
setupUI()
38+
}
39+
40+
}

Turbah/Classes/Settings/SegmentedCell.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ class SegmentedCell: UITableViewCell {
1515
var segmentedControl = UISegmentedControl()
1616

1717
private func setupUI() {
18-
segmentedControl.insertSegment(withTitle: "Magnetic North", at: 0, animated: false)
19-
segmentedControl.insertSegment(withTitle: "True North", at: 1, animated: false)
20-
segmentedControl.selectedSegmentIndex = save.northType
18+
segmentedControl.insertSegment(withTitle: "True North", at: 0, animated: false)
19+
segmentedControl.insertSegment(withTitle: "Magnetic North", at: 1, animated: false)
20+
segmentedControl.selectedSegmentIndex = (save.northType == .trueNorth) ? 0 : 1
2121
addSubview(segmentedControl)
2222
segmentedControl.fillSuperview(padding: UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15))
2323
}

Turbah/Classes/UserDefaults.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import Foundation
1010

1111
extension UserDefaults {
1212

13-
var northType: Int {
13+
enum northTypeEnum { case trueNorth, magneticNorth }
14+
var northType: northTypeEnum {
1415
get {
15-
return save.integer(forKey: "NorthType")
16+
return (save.integer(forKey: "NorthType") == 0) ? .trueNorth : .magneticNorth
1617
}
1718
set {
18-
save.set(newValue, forKey: "NorthType")
19+
save.set((newValue == .trueNorth) ? 0 : 1, forKey: "NorthType")
1920
}
2021
}
2122

Turbah/Controllers/SettingsVC.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class SettingsVC: UITableViewController, MFMailComposeViewControllerDelegate {
168168

169169

170170
@objc private func northTypeChanged(_ sender: UISegmentedControl) {
171-
save.northType = sender.selectedSegmentIndex
171+
save.northType = (sender.selectedSegmentIndex == 0) ? .trueNorth : .magneticNorth
172172
}
173173

174174
}

Turbah/Controllers/ViewController.swift

+14-17
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,27 @@ class ViewController: UIViewController, CLLocationManagerDelegate, ARCoachingOve
8282

8383
func placeTurbah() {
8484
guard let turbah = try! Turbah.loadScene().turbah else { print("error"); return }
85-
8685
anchor.addChild(turbah)
87-
8886
arView.scene.addAnchor(anchor)
8987

90-
print("before", anchor.position)
91-
print("euler", arView.session.currentFrame!.camera.eulerAngles)
9288
let cameraAngles = arView.session.currentFrame!.camera.transform.columns.3
9389

9490
let decreaseValue: Double = 3
9591

96-
anchor.position.z = Float(-1 * cos(bearingOfKabah) / decreaseValue) //(-1.0 / decreaseValue)// + cameraAngles.z
97-
anchor.position.x = Float(sin(bearingOfKabah) / decreaseValue) //(Float(sin(bearingOfKabah.radiansToDegrees)) / decreaseValue)// + cameraAngles.x
98-
//anchor.position.y += cameraAngles.y
92+
anchor.position.z = Float(-1 * cos(bearingOfKabah) / decreaseValue) + cameraAngles.z
93+
anchor.position.x = Float(sin(bearingOfKabah) / decreaseValue) + cameraAngles.x
94+
anchor.position.y += cameraAngles.y
9995
print("after", anchor.position)
10096

10197
let anchorAngles = anchor.transform.matrix.columns.3
10298

103-
//print("""
104-
//
105-
//camera: \(cameraAngles)
106-
//anchor: \(anchorAngles)
107-
//distance: \(length(cameraAngles - anchorAngles) * 3.28084) feet
108-
//
109-
//""")
99+
print("""
100+
101+
camera: \(cameraAngles)
102+
anchor: \(anchorAngles)
103+
distance: \(length(cameraAngles - anchorAngles) * 3.28084) feet
104+
105+
""")
110106

111107
turbahAdded = true
112108
}
@@ -264,7 +260,7 @@ class ViewController: UIViewController, CLLocationManagerDelegate, ARCoachingOve
264260
super.viewWillAppear(animated)
265261
let config = ARWorldTrackingConfiguration()
266262
config.planeDetection = .horizontal
267-
config.worldAlignment = .gravityAndHeading
263+
config.worldAlignment = (save.northType == .trueNorth) ? .gravityAndHeading : .gravity
268264
arView.session.run(config)
269265
}
270266

@@ -302,13 +298,14 @@ class ViewController: UIViewController, CLLocationManagerDelegate, ARCoachingOve
302298
var didAddCoaching = false
303299

304300
func locationManager(_ manager: CLLocationManager, didUpdateHeading heading: CLHeading) {
305-
let chosenHeading = (save.northType == 0) ? heading.magneticHeading : heading.trueHeading
301+
let chosenHeading = (save.northType == .trueNorth) ? heading.trueHeading : heading.magneticHeading
306302
let north = chosenHeading.degreesToRadians
307303
let directionOfKabah = north - bearingOfKabah
308304

309305
//print("qibla degreees:", directionOfKabah.radiansToDegrees)
310-
print("qibla radians:", directionOfKabah)
306+
print("phone", arView.session.currentFrame?.camera.transform.columns.3 ?? "")
311307
print("anchor", anchor.transform.matrix.columns.3)
308+
print("")
312309

313310
compassView.kabaImageView.transform = CGAffineTransform(rotationAngle: CGFloat(-directionOfKabah));
314311
compassView.isPointingAtQibla = (directionOfKabah < 0.1 && directionOfKabah > -0.1)

Turbah/Super.swift

+13
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ extension CALayer {
7979
}
8080

8181

82+
extension UIView {
83+
84+
var screenshot: UIImage {
85+
let renderer = UIGraphicsImageRenderer(bounds: bounds)
86+
return renderer.image { rendererContext in
87+
layer.render(in: rendererContext.cgContext)
88+
}
89+
}
90+
91+
}
92+
93+
94+
8295
func hapticFeedback(style: UIImpactFeedbackGenerator.FeedbackStyle = .light) {
8396
UIImpactFeedbackGenerator(style: style).impactOccurred()
8497
}

0 commit comments

Comments
 (0)