-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbbc736
commit f6d352f
Showing
7 changed files
with
177 additions
and
25 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ARMode.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,8 @@ | ||
package com.kylecorry.trail_sense.tools.augmented_reality | ||
|
||
import com.kylecorry.trail_sense.shared.database.Identifiable | ||
|
||
enum class ARMode(override val id: Long) : Identifiable { | ||
Normal(1), | ||
Astronomy(2), | ||
} |
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
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/guide/ARGuide.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,8 @@ | ||
package com.kylecorry.trail_sense.tools.augmented_reality.guide | ||
|
||
import com.kylecorry.trail_sense.tools.augmented_reality.AugmentedRealityView | ||
|
||
interface ARGuide { | ||
fun start(arView: AugmentedRealityView) | ||
fun stop(arView: AugmentedRealityView) | ||
} |
55 changes: 55 additions & 0 deletions
55
...src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/guide/AstronomyARGuide.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,55 @@ | ||
package com.kylecorry.trail_sense.tools.augmented_reality.guide | ||
|
||
import com.kylecorry.andromeda.core.time.CoroutineTimer | ||
import com.kylecorry.trail_sense.astronomy.domain.AstronomyService | ||
import com.kylecorry.trail_sense.tools.augmented_reality.AugmentedRealityView | ||
import com.kylecorry.trail_sense.tools.augmented_reality.position.SphericalARPoint | ||
import java.time.ZonedDateTime | ||
|
||
class AstronomyARGuide : ARGuide { | ||
|
||
private var objectToTrack = AstronomyObject.Sun | ||
private val astro = AstronomyService() | ||
private var arView: AugmentedRealityView? = null | ||
private val timer = CoroutineTimer { | ||
val arView = arView ?: return@CoroutineTimer | ||
// TODO: Make time configurable | ||
val time = ZonedDateTime.now() | ||
|
||
val destination = when (objectToTrack) { | ||
AstronomyObject.Sun -> { | ||
val azimuth = astro.getSunAzimuth(arView.location, time).value | ||
val altitude = astro.getSunAltitude(arView.location, time) | ||
SphericalARPoint(azimuth, altitude, angularDiameter = 2f) | ||
} | ||
AstronomyObject.Moon -> { | ||
val azimuth = astro.getMoonAzimuth(arView.location, time).value | ||
val altitude = astro.getMoonAltitude(arView.location, time) | ||
SphericalARPoint(azimuth, altitude, angularDiameter = 2f) | ||
} | ||
} | ||
|
||
arView.guideTo(destination) { | ||
// Do nothing when reached | ||
} | ||
|
||
} | ||
|
||
override fun start(arView: AugmentedRealityView) { | ||
this.arView = arView | ||
timer.interval(1000) | ||
} | ||
|
||
override fun stop(arView: AugmentedRealityView) { | ||
this.arView = null | ||
timer.stop() | ||
arView.clearGuide() | ||
} | ||
|
||
|
||
private enum class AstronomyObject { | ||
Sun, | ||
Moon | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...rc/main/java/com/kylecorry/trail_sense/tools/augmented_reality/guide/NavigationARGuide.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,35 @@ | ||
package com.kylecorry.trail_sense.tools.augmented_reality.guide | ||
|
||
import com.kylecorry.trail_sense.navigation.infrastructure.Navigator | ||
import com.kylecorry.trail_sense.tools.augmented_reality.AugmentedRealityView | ||
import com.kylecorry.trail_sense.tools.augmented_reality.position.GeographicARPoint | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
|
||
class NavigationARGuide(private val navigator: Navigator) : ARGuide { | ||
|
||
private val scope = CoroutineScope(Dispatchers.Default) | ||
private var job: Job? = null | ||
|
||
override fun start(arView: AugmentedRealityView) { | ||
job?.cancel() | ||
job = scope.launch { | ||
navigator.destination.collect { | ||
if (it == null) { | ||
arView.clearGuide() | ||
} else { | ||
arView.guideTo(GeographicARPoint(it.coordinate, it.elevation)) { | ||
// Do nothing when reached | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun stop(arView: AugmentedRealityView) { | ||
job?.cancel() | ||
arView.clearGuide() | ||
} | ||
} |
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