Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor error with placement of route steps #255

Merged
merged 9 commits into from
Dec 1, 2019
18 changes: 13 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 midLoction = midPoint(currentLocation, nextLocation)
halmueller marked this conversation as resolved.
Show resolved Hide resolved

let distance = currentLocation.distance(from: nextLocation)

Expand All @@ -82,17 +83,24 @@ 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: midLoction, tag: tag)
locationNode.addChildNode(boxNode)

locationNodes.append(locationNode)
}
}

func midPoint (_ first: CLLocation, _ second: CLLocation) -> CLLocation {
halmueller marked this conversation as resolved.
Show resolved Hide resolved
return CLLocation(
coordinate: CLLocationCoordinate2D(
latitude: (first.coordinate.latitude + second.coordinate.latitude) / 2,
longitude: (first.coordinate.longitude + second.coordinate.longitude) / 2
),
altitude: (first.altitude + second.altitude) / 2
)
} // midPoint(_:_:)

}
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