Untitled
unknown
plain_text
a year ago
2.9 kB
10
Indexable
onSessionUpdated = { session, updatedFrame ->
val currentTime = System.currentTimeMillis()
Log.d("tot", "ARSceneContent: "+totalDistance)
if (currentTime - lastUpdateTime >= updateInterval) {
lastUpdateTime = currentTime
val earth = session.earth
if (earth?.earthState == Earth.EarthState.ENABLED) {
// Get user's current location
val userLatLng = LatLng(
earth.cameraGeospatialPose.latitude,
earth.cameraGeospatialPose.longitude
)
if (latlongpointslist.isNotEmpty()) {
val nextWaypoint = latlongpointslist.first() // Get the next point in the route
// Calculate the bearing to the next waypoint
val bearing = calculateBearing(userLatLng, nextWaypoint)
// Remove the previous anchor and node
currentAnchor?.detach()
currentAnchor = null
// Create a new anchor with rotation
val newAnchor = createDestinationAnchorWithRotation(earth, nextWaypoint, bearing)
newAnchor?.let { anchor ->
currentAnchor = anchor
// Create a single arrow node
val arrowNode = createAnchorNode(
engine = engine,
modelLoader = modelLoader,
materialLoader = materialLoader,
anchor = anchor
)
currentNode = arrowNode
childNodes += arrowNode
}
val lastPoint = latlongpointslist.last()
val distanceToLastPoint = calculateDistance(userLatLng, lastPoint)
if (distanceToLastPoint <= 5) { // Threshold of 5 meters
Toast.makeText(this@ArCore,
"You have reached your destination! Total distance: $totalDistance meters.",
Toast.LENGTH_LONG
).show()
}
}
}
}
}Editor is loading...
Leave a Comment