Skip to content

Commit

Permalink
Adds support for AR Orientation Tracking (AndrewHartAR#198)
Browse files Browse the repository at this point in the history
* App Store 1024x1024 Icon

This eliminates an xcode compile warning

* Fix CLHeading.headingAccuracy variable definition

Was CLLocationDegrees, now CLLocationDirection.  Worth noting that both are doubles so the code compiled w/o error, but it's now correct.

* Camera tracking mechanism sync to device orientation better, especially after pause/resume

Was ARWorldTracdkingConfiguration, now AROrientationTrackingConfiguration.  Heading (Euler.y) now tracks soley to AHRS, before it tried to sense and track to planes - which doesn't make sense for an outside environment.

* Added a configuration option for World Tracking versus Orientation Tracking.  The default is World Tracking.

* Updated the changelog.

* Added more (defaulted) parameters to the convenience initializer and re-commented it.  Also addressed an issue Marc found in the PR.
  • Loading branch information
Pilot-Marc authored and intere committed Jun 21, 2019
1 parent 8b65ae2 commit cc47370
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "App Store Icon.png",
"scale" : "1x"
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "ARCL",
targets: ["ARKit-CoreLocation"]),
targets: ["ARKit-CoreLocation"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class LocationManager: NSObject {
var currentLocation: CLLocation?

private(set) public var heading: CLLocationDirection?
private(set) public var headingAccuracy: CLLocationDegrees?
private(set) public var headingAccuracy: CLLocationDirection?

override init() {
super.init()
Expand Down
44 changes: 35 additions & 9 deletions Sources/ARKit-CoreLocation/SceneLocationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ open class SceneLocationView: ARSCNView {
/// Measured in meters.
static let sceneLimit = 100.0

/// The type of tracking to use.
///
/// - orientationTracking: Informs the `SceneLocationView` to use Device Orientatoin tracking only.
/// See [Apple's documentation](https://developer.apple.com/documentation/arkit/arorientationtrackingconfiguration)
/// - worldTracking: Informs the `SceneLocationView` to use a World Tracking Configuration.
/// See [Apple's documentation](https://developer.apple.com/documentation/arkit/arworldtrackingconfiguration#overview)
public enum ARTrackingType {
case orientationTracking
case worldTracking
}

public weak var locationViewDelegate: SceneLocationViewDelegate?
public weak var locationEstimateDelegate: SceneLocationViewEstimateDelegate?
public weak var locationNodeTouchDelegate: LNTouchDelegate?
Expand Down Expand Up @@ -74,13 +85,23 @@ open class SceneLocationView: ARSCNView {

public internal(set) var locationNodes = [LocationNode]()
public internal(set) var polylineNodes = [PolylineNode]()
public internal(set) var arTrackingType: ARTrackingType = .worldTracking

// MARK: Internal desclarations
internal var didFetchInitialLocation = false

// MARK: Setup
public convenience init() {
self.init(frame: .zero, options: nil)

/// This initializer allows you to specify the type of tracking configuration (defaults to world tracking) as well as
/// some other optional values.
///
/// - Parameters:
/// - trackingType: The type of AR Tracking configuration (defaults to world tracking).
/// - frame: The CGRect for the frame (defaults to .zero).
/// - options: The rendering options for the `SCNView`.
public convenience init(trackingType: ARTrackingType = .worldTracking, frame: CGRect = .zero, options: [String: Any]? = nil) {
self.init(frame: frame, options: options)
self.arTrackingType = trackingType
}

public override init(frame: CGRect, options: [String: Any]? = nil) {
Expand Down Expand Up @@ -137,13 +158,18 @@ open class SceneLocationView: ARSCNView {
public extension SceneLocationView {

func run() {
// Create a session configuration
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = .horizontal
configuration.worldAlignment = orientToTrueNorth ? .gravityAndHeading : .gravity

// Run the view's session
session.run(configuration)
switch arTrackingType {
case .worldTracking:
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = .horizontal
configuration.worldAlignment = orientToTrueNorth ? .gravityAndHeading : .gravity
session.run(configuration)

case .orientationTracking:
let configuration = AROrientationTrackingConfiguration()
configuration.worldAlignment = orientToTrueNorth ? .gravityAndHeading : .gravity
session.run(configuration)
}
sceneLocationManager.run()
}

Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog
- 1.2.1
- [PR #198 - Adds support for AR Orientation Tracking](https://github.com/ProjectDent/ARKit-CoreLocation/pull/198)
- [PR #193 - Adds support for Swift Package Manager](https://github.com/ProjectDent/ARKit-CoreLocation/pull/193)
- 1.2.0
- [PR #185 - Custom boxes for directions](https://github.com/ProjectDent/ARKit-CoreLocation/pull/185/files)
Expand Down

0 comments on commit cc47370

Please sign in to comment.