Untitled
onSessionUpdated = { session, updatedFrame -> val currentTime = System.currentTimeMillis() 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) Log.d("ARScene", "Bearing to next waypoint: $bearing") // 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 } // Check distance to last point val lastPoint = latlongpointslist.last() val distanceToLastPoint = calculateDistance(userLatLng, lastPoint) Log.d("ARScene", "Distance to last point: $distanceToLastPoint meters") if (distanceToLastPoint <= 2) { // Threshold of 5 meters Log.d("ARScene", "Destination reached!") Toast.makeText( this@ArCore, "You have reached your destination! Total distance: $totalDistance meters.", Toast.LENGTH_LONG ).show() } } } } }
Leave a Comment