diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARAstronomyLayer.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARAstronomyLayer.kt index 0818f4c7b..2bb11849a 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARAstronomyLayer.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARAstronomyLayer.kt @@ -20,6 +20,7 @@ import java.time.ZoneId import java.time.ZonedDateTime class ARAstronomyLayer( + private val drawLines: Boolean, private val onSunFocus: (time: ZonedDateTime) -> Boolean, private val onMoonFocus: (time: ZonedDateTime) -> Boolean ) : ARLayer { @@ -27,7 +28,15 @@ class ARAstronomyLayer( private val scope = CoroutineScope(Dispatchers.Default) private val runner = CoroutineQueueRunner() + private val sunLineLayer = ARLineLayer( + AppColor.Yellow.color, + curved = true + ) private val sunLayer = ARMarkerLayer() + private val moonLineLayer = ARLineLayer( + Color.WHITE, + curved = true + ) private val moonLayer = ARMarkerLayer() private val astro = AstronomyService() @@ -50,11 +59,17 @@ class ARAstronomyLayer( updatePositions(drawer, location, ZonedDateTime.now()) } + if (drawLines) { + moonLineLayer.draw(drawer, view) + sunLineLayer.draw(drawer, view) + } moonLayer.draw(drawer, view) sunLayer.draw(drawer, view) } override fun invalidate() { + moonLineLayer.invalidate() + sunLineLayer.invalidate() moonLayer.invalidate() sunLayer.invalidate() } @@ -80,22 +95,22 @@ class ARAstronomyLayer( val moonBeforePathObject = CanvasCircle( Color.WHITE, - opacity = 20 + opacity = 60 ) val moonAfterPathObject = CanvasCircle( Color.WHITE, - opacity = 127 + opacity = 200 ) val sunBeforePathObject = CanvasCircle( AppColor.Yellow.color, - opacity = 20 + opacity = 60 ) val sunAfterPathObject = CanvasCircle( AppColor.Yellow.color, - opacity = 127 + opacity = 200 ) val moonPositions = Time.getReadings( @@ -114,7 +129,7 @@ class ARAstronomyLayer( astro.getMoonAzimuth(location, it).value, astro.getMoonAltitude(location, it), isTrueNorth = true, - angularDiameter = 1f + angularDiameter = 0.5f ), canvasObject = obj, onFocusedFn = { @@ -137,7 +152,7 @@ class ARAstronomyLayer( astro.getSunAzimuth(location, it).value, astro.getSunAltitude(location, it), isTrueNorth = true, - angularDiameter = 1f + angularDiameter = 0.5f ), canvasObject = obj, onFocusedFn = { @@ -184,6 +199,12 @@ class ARAstronomyLayer( } ) + sunLineLayer.setLines(listOf(sunPositions.map { it.point } + listOfNotNull( + sunPositions.firstOrNull()?.point + ))) + moonLineLayer.setLines(listOf(moonPositions.map { it.point } + listOfNotNull( + moonPositions.firstOrNull()?.point + ))) sunLayer.setMarkers(sunPositions + sun) moonLayer.setMarkers(moonPositions + moon) } diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARLineLayer.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARLineLayer.kt index ca1ab6d02..bdffaa3df 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARLineLayer.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARLineLayer.kt @@ -15,7 +15,8 @@ import kotlin.math.roundToInt // TODO: Create a generic version of this that works like the path tool. The consumers should be able to specify the line style, color, thickness, and whether it should be curved or straight between points class ARLineLayer( @ColorInt private val color: Int = Color.WHITE, - private val thicknessDp: Float = 1f + private val thicknessDp: Float = 1f, + private val curved: Boolean = true ) : ARLayer { private val path = Path() @@ -55,38 +56,40 @@ class ARLineLayer( path.reset() drawer.stroke(color) - // TODO: This should split the lines into smaller chunks (which will allow distance splitting) - keeping it this way for now for the clinometer - var previous: PixelCoordinate? = null - for (point in line){ - val pixel = view.toPixel(point.getHorizonCoordinate(view)) - // TODO: This should split the line if the distance is too great - if (previous != null) { - path.lineTo(pixel.x, pixel.y) - } else { - path.moveTo(pixel.x, pixel.y) + if (curved) { + // Curved + increased resolution + val pixels = getLinePixels( + view, + line, + resolutionDegrees.toFloat(), + maxDistance.toFloat() + ) + for (pixelLine in pixels) { + var previous: PixelCoordinate? = null + for (pixel in pixelLine) { + if (previous != null) { + path.lineTo(pixel.x, pixel.y) + } else { + path.moveTo(pixel.x, pixel.y) + } + previous = pixel + } + } + } else { + // TODO: This should split the lines into smaller chunks (which will allow distance splitting) - keeping it this way for now for the clinometer + var previous: PixelCoordinate? = null + for (point in line) { + val pixel = view.toPixel(point.getHorizonCoordinate(view)) + // TODO: This should split the line if the distance is too great + if (previous != null) { + path.lineTo(pixel.x, pixel.y) + } else { + path.moveTo(pixel.x, pixel.y) + } + previous = pixel } - previous = pixel } - // Curved + increased resolution -// val pixels = getLinePixels( -// view, -// line, -// resolutionDegrees.toFloat(), -// maxDistance.toFloat() -// ) -// for (pixelLine in pixels) { -// var previous: PixelCoordinate? = null -// for (pixel in pixelLine) { -// if (previous != null) { -// path.lineTo(pixel.x, pixel.y) -// } else { -// path.moveTo(pixel.x, pixel.y) -// } -// previous = pixel -// } -// } - drawer.path(path) } diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARMarker.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARMarker.kt index e59fb93a2..c5bbdbef4 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARMarker.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARMarker.kt @@ -8,7 +8,7 @@ import com.kylecorry.trail_sense.tools.augmented_reality.position.GeographicARPo import com.kylecorry.trail_sense.tools.augmented_reality.position.SphericalARPoint class ARMarker( - private val point: ARPoint, + val point: ARPoint, private val canvasObject: CanvasObject, private val keepFacingUp: Boolean = false, private val onFocusedFn: (() -> Boolean) = { false }, diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt index 5dcea12c2..4fbe65518 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/AugmentedRealityFragment.kt @@ -54,7 +54,7 @@ class AugmentedRealityFragment : BoundFragment( } private val astronomyLayer by lazy { - ARAstronomyLayer(this::onSunFocused, this::onMoonFocused) + ARAstronomyLayer(false, this::onSunFocused, this::onMoonFocused) } private val navigator by lazy { Navigator.getInstance(requireContext()) } diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/clinometer/ui/ClinometerFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/clinometer/ui/ClinometerFragment.kt index c54565b3c..ac304105b 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/clinometer/ui/ClinometerFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/clinometer/ui/ClinometerFragment.kt @@ -86,7 +86,7 @@ class ClinometerFragment : BoundFragment() { // Augmented reality private val markerLayer = ARMarkerLayer() - private val lineLayer = ARLineLayer() + private val lineLayer = ARLineLayer(curved = false) private var startMarker: ARPoint? = null private var endMarker: ARPoint? = null