Skip to content

Commit

Permalink
Merge pull request #255 from Pilot-Marc/route-step-pivot-point
Browse files Browse the repository at this point in the history
Fix minor error with placement of route steps
  • Loading branch information
halmueller authored Dec 1, 2019
2 parents d09ba4e + 2f5f292 commit 1a728b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
13 changes: 13 additions & 0 deletions Sources/ARKit-CoreLocation/Extensions/CLLocation+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ public extension CLLocation {
let x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon)
return atan2(y, x).radiansToDegrees
}

/// Returns the midpoint between two locations
/// Note: Only usable for short distances like MKPolyline segments
func approxMidpoint(to: CLLocation) -> CLLocation {
return CLLocation(
coordinate: CLLocationCoordinate2D(
latitude: (coordinate.latitude + to.coordinate.latitude) / 2,
longitude: (coordinate.longitude + to.coordinate.longitude) / 2
),
altitude: (altitude + to.altitude) / 2
)
} // approxMidpoint(to:)

}

public extension CLLocation {
Expand Down
1 change: 1 addition & 0 deletions Sources/ARKit-CoreLocation/Nodes/LocationNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ open class LocationNode: SCNNode {
}
} else {
//Calculates distance based on the distance within the scene, as the location isn't yet confirmed
//TODO: This yields zero, perhaps we should investigate
adjustedDistance = Double(position.distance(to: position))

scale = SCNVector3(x: 1, y: 1, z: 1)
Expand Down
8 changes: 3 additions & 5 deletions Sources/ARKit-CoreLocation/Nodes/PolylineNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private extension PolylineNode {
for i in 0 ..< polyline.pointCount - 1 {
let currentLocation = CLLocation(coordinate: points[i].coordinate, altitude: altitude)
let nextLocation = CLLocation(coordinate: points[i + 1].coordinate, altitude: altitude)
let midLocation = currentLocation.approxMidpoint(to: nextLocation)

let distance = currentLocation.distance(from: nextLocation)

Expand All @@ -82,13 +83,10 @@ private extension PolylineNode {

let bearing = -currentLocation.bearing(between: nextLocation)

// This pivot translation in the +Z direction will cause the box to be
// rendered a bit away from its true location. The actual factor should
// probably be a parameter or property of some sort.
boxNode.pivot = SCNMatrix4MakeTranslation(0, 0, 0.5 * Float(distance))
// Orient the line to point from currentLoction to nextLocation
boxNode.eulerAngles.y = Float(bearing).degreesToRadians

let locationNode = LocationNode(location: currentLocation, tag: tag)
let locationNode = LocationNode(location: midLocation, tag: tag)
locationNode.addChildNode(boxNode)

locationNodes.append(locationNode)
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.2
- [PR #255 - Fix minor error with placement of route steps](https://github.com/ProjectDent/ARKit-CoreLocation/pull/255)
- [PR #249 - Fix Memory Leak](https://github.com/ProjectDent/ARKit-CoreLocation/pull/249)
- [PR #244 - Improve geodesy calculations and test coverage](https://github.com/ProjectDent/ARKit-CoreLocation/pull/244)
- [PR #240 - Fix build error, update compiler checks](https://github.com/ProjectDent/ARKit-CoreLocation/pull/240)
Expand Down

0 comments on commit 1a728b5

Please sign in to comment.