-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
143 additions
and
9 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARPathLayer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.kylecorry.trail_sense.tools.augmented_reality | ||
|
||
import com.kylecorry.andromeda.canvas.ICanvasDrawer | ||
import com.kylecorry.andromeda.core.units.PixelCoordinate | ||
import com.kylecorry.sol.units.Coordinate | ||
import com.kylecorry.sol.units.Distance | ||
import com.kylecorry.trail_sense.tools.augmented_reality.position.GeographicARPoint | ||
import com.kylecorry.trail_sense.tools.navigation.ui.IMappableLocation | ||
import com.kylecorry.trail_sense.tools.navigation.ui.IMappablePath | ||
import com.kylecorry.trail_sense.tools.navigation.ui.MappablePath | ||
import com.kylecorry.trail_sense.tools.paths.ui.IPathLayer | ||
|
||
class ARPathLayer(private val viewDistance: Distance) : ARLayer, IPathLayer { | ||
|
||
private val lineLayer = ARLineLayer() | ||
private val pointLayer = ARMarkerLayer(0.1f, 6f) | ||
private var lastLocation = Coordinate.zero | ||
private val viewDistanceMeters = viewDistance.meters().distance | ||
|
||
override fun draw(drawer: ICanvasDrawer, view: AugmentedRealityView) { | ||
lastLocation = view.location | ||
lineLayer.draw(drawer, view) | ||
pointLayer.draw(drawer, view) | ||
} | ||
|
||
override fun invalidate() { | ||
lineLayer.invalidate() | ||
pointLayer.invalidate() | ||
} | ||
|
||
override fun onClick( | ||
drawer: ICanvasDrawer, | ||
view: AugmentedRealityView, | ||
pixel: PixelCoordinate | ||
): Boolean { | ||
return false | ||
} | ||
|
||
override fun onFocus(drawer: ICanvasDrawer, view: AugmentedRealityView): Boolean { | ||
return false | ||
} | ||
|
||
override fun setPaths(paths: List<IMappablePath>) { | ||
|
||
val location = lastLocation | ||
|
||
val splitPaths = paths.flatMap { path -> | ||
clipPath(path, location, viewDistanceMeters) | ||
} | ||
|
||
lineLayer.setLines(splitPaths.map { path -> | ||
ARLine( | ||
path.points.map { | ||
GeographicARPoint(it.coordinate, it.elevation) | ||
}, | ||
path.color, | ||
1f, | ||
ARLine.ThicknessUnits.Dp | ||
) | ||
}) | ||
|
||
// Only render the closest 20 points | ||
val nearby = splitPaths.flatMap { path -> | ||
path.points.map { | ||
it to path.color | ||
} | ||
}.sortedBy { | ||
it.first.coordinate.distanceTo(location) | ||
}.take(20).map { | ||
ARMarker( | ||
GeographicARPoint(it.first.coordinate, it.first.elevation), | ||
CanvasCircle(it.second) | ||
) | ||
} | ||
pointLayer.setMarkers(nearby) | ||
} | ||
|
||
private fun clipPath(path: IMappablePath, location: Coordinate, distance: Float): List<IMappablePath> { | ||
val clipped = mutableListOf<IMappablePath>() | ||
val currentPoints = mutableListOf<IMappableLocation>() | ||
|
||
for (point in path.points) { | ||
if (point.coordinate.distanceTo(location) < distance) { | ||
currentPoints.add(point) | ||
} else { | ||
// TODO: Clip instead of remove | ||
if (currentPoints.isNotEmpty()) { | ||
clipped.add(MappablePath(path.id, currentPoints.toList(), path.color, path.style)) | ||
currentPoints.clear() | ||
} | ||
} | ||
} | ||
|
||
if (currentPoints.isNotEmpty()) { | ||
clipped.add(MappablePath(path.id, currentPoints.toList(), path.color, path.style)) | ||
} | ||
|
||
return clipped | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/kylecorry/trail_sense/tools/paths/ui/IPathLayer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kylecorry.trail_sense.tools.paths.ui | ||
|
||
import com.kylecorry.trail_sense.tools.navigation.ui.IMappablePath | ||
|
||
interface IPathLayer { | ||
fun setPaths(paths: List<IMappablePath>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters