Skip to content

Commit

Permalink
Construct AR grid points off of ui thread
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Jan 13, 2024
1 parent 43d104d commit 6ff4375
Showing 1 changed file with 57 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.tools.augmented_reality.position.ARPoint
import com.kylecorry.trail_sense.tools.augmented_reality.position.AugmentedRealityCoordinate
import com.kylecorry.trail_sense.tools.augmented_reality.position.SphericalARPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class ARGridLayer(
spacing: Int = 30,
Expand All @@ -32,67 +35,71 @@ class ARGridLayer(

private val resolution = 6

init {
val regularLines = mutableListOf<List<ARPoint>>()

// Horizontal lines
for (elevation in -90..90 step spacing) {
// Skip horizon
if (elevation == 0) {
continue
}
private val scope = CoroutineScope(Dispatchers.Default)

val line = mutableListOf<ARPoint>()
for (azimuth in 0..360 step resolution) {
line.add(
SphericalARPoint(
azimuth.toFloat(),
elevation.toFloat(),
isTrueNorth = useTrueNorth
init {
scope.launch {
val regularLines = mutableListOf<List<ARPoint>>()

// Horizontal lines
for (elevation in -90..90 step spacing) {
// Skip horizon
if (elevation == 0) {
continue
}

val line = mutableListOf<ARPoint>()
for (azimuth in 0..360 step resolution) {
line.add(
SphericalARPoint(
azimuth.toFloat(),
elevation.toFloat(),
isTrueNorth = useTrueNorth
)
)
)
}
regularLines.add(line)
}
regularLines.add(line)
}

// Vertical lines
for (azimuth in 0 until 360 step spacing) {

// Skip north
if (azimuth == 0) {
continue
// Vertical lines
for (azimuth in 0 until 360 step spacing) {

// Skip north
if (azimuth == 0) {
continue
}

val line = mutableListOf<ARPoint>()
for (elevation in -90..90 step resolution) {
line.add(
SphericalARPoint(
azimuth.toFloat(),
elevation.toFloat(),
isTrueNorth = useTrueNorth
)
)
}
regularLines.add(line)
}

val line = mutableListOf<ARPoint>()
// North line
val northLine = mutableListOf<ARPoint>()
for (elevation in -90..90 step resolution) {
line.add(
SphericalARPoint(
azimuth.toFloat(),
elevation.toFloat(),
isTrueNorth = useTrueNorth
)
)
northLine.add(SphericalARPoint(0f, elevation.toFloat(), isTrueNorth = useTrueNorth))
}
regularLines.add(line)
}

// North line
val northLine = mutableListOf<ARPoint>()
for (elevation in -90..90 step resolution) {
northLine.add(SphericalARPoint(0f, elevation.toFloat(), isTrueNorth = useTrueNorth))
}
// Horizon line
val horizonLine = mutableListOf<ARPoint>()
for (azimuth in 0..360 step resolution) {
horizonLine.add(SphericalARPoint(azimuth.toFloat(), 0f, isTrueNorth = useTrueNorth))
}

// Horizon line
val horizonLine = mutableListOf<ARPoint>()
for (azimuth in 0..360 step resolution) {
horizonLine.add(SphericalARPoint(azimuth.toFloat(), 0f, isTrueNorth = useTrueNorth))
lineLayer.setLines(
regularLines.map { ARLine(it, color, thicknessDp) } +
ARLine(northLine, northColor, thicknessDp) +
ARLine(horizonLine, horizonColor, thicknessDp)
)
}

lineLayer.setLines(
regularLines.map { ARLine(it, color, thicknessDp) } +
ARLine(northLine, northColor, thicknessDp) +
ARLine(horizonLine, horizonColor, thicknessDp)
)
}

override fun draw(drawer: ICanvasDrawer, view: AugmentedRealityView) {
Expand Down

0 comments on commit 6ff4375

Please sign in to comment.