Skip to content

Commit

Permalink
Add aging transparency support to MilStd2525 placemarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
ComBatVision committed Sep 28, 2023
1 parent 4e8d3e6 commit 2a5d84c
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package earth.worldwind.shape.milstd2525
import earth.worldwind.render.RenderContext
import earth.worldwind.shape.Placemark
import earth.worldwind.shape.PlacemarkAttributes
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.hours

/**
* The [MilStd2525LevelOfDetailSelector] determines which set of [PlacemarkAttributes] to use for a [MilStd2525Placemark].
Expand All @@ -17,12 +21,38 @@ open class MilStd2525LevelOfDetailSelector : Placemark.LevelOfDetailSelector {
protected const val MEDIUM_LEVEL_OF_DETAIL = 1
protected const val HIGH_LEVEL_OF_DETAIL = 2
protected const val HIGHEST_LEVEL_OF_DETAIL = 3

/**
* Controls the symbol modifiers visibility threshold
*/
var modifiersThreshold = 5e4

/**
* Duration after which placemark becomes slightly transparent
*/
var firstAgingThreshold = 1.hours

/**
* Fist level of transparency
*/
var firstAgingAlpha = 0.75f

/**
* Duration after which placemark becomes moderate transparent
*/
var secondAgingThreshold = 1.days

/**
* Second level of transparency
*/
var secondAgingAlpha = 0.5f
}

/**
* Base time to calculate transparency of aging Placemarks
*/
var baseAgingTime = Instant.DISTANT_FUTURE

protected var lastLevelOfDetail = -1
protected var isHighlighted = false
protected var isInvalidateRequested = false
Expand Down Expand Up @@ -89,6 +119,16 @@ open class MilStd2525LevelOfDetailSelector : Placemark.LevelOfDetailSelector {
placemark.attributes.isDrawLeader = lastLevelOfDetail >= MEDIUM_LEVEL_OF_DETAIL
placemark.attributes.imageScale = if (isHighlighted) HIGHLIGHTED_SCALE else NORMAL_SCALE

if (baseAgingTime != Instant.DISTANT_FUTURE) {
val agingTime = Clock.System.now() - baseAgingTime
// Make placemark translucent with time
placemark.attributes.imageColor.alpha = when {
!isHighlighted && agingTime > secondAgingThreshold -> secondAgingAlpha
!isHighlighted && agingTime > firstAgingThreshold -> firstAgingAlpha
else -> 1.0f // Opaque placemark by default
}
}

return true
}
}

0 comments on commit 2a5d84c

Please sign in to comment.