Prototype/Source/Prototype/Private/Task_UpdateMap.cpp
/* Update the agent's onboard map from sensor data.
*/
Update the agent's onboard map from sensor data.
Update the agent ' s onboard map from sensor data .
void AUSARAgent::UpdateMap()
{
    FVector currLoc = GetActorLocation();
    float xMax = currLoc.X + VISION_RADIUS;
    float yMax = currLoc.Y + VISION_RADIUS;
    float zMax = currLoc.Z + VISION_RADIUS;
    float gridZ = currLoc.Z - VISION_RADIUS;
    while (gridZ <= zMax) {
        float gridX = currLoc.X - VISION_RADIUS;
        while (gridX <= xMax) {
            float gridY = currLoc.Y - VISION_RADIUS;
            while (gridY <= yMax) {
                FVector gridLoc = FVector(gridX, gridY, gridZ);
                float dist = FVector::Dist(currLoc, gridLoc);
                if (dist <= VISION_RADIUS) {
                    FHitResult hitResult;
                    FCollisionObjectQueryParams objectParams;
                    objectParams.AddObjectTypesToQuery(ECC_WorldStatic);
                    FCollisionQueryParams queryParams;
                    queryParams.AddIgnoredActor(this);
                    if (!GetWorld()->LineTraceSingleByObjectType(hitResult, currLoc, gridLoc, objectParams, queryParams)) {
                        AddGrid(gridLoc, false);
                    }
                    else {
                        FVector hitLoc = hitResult.ImpactPoint;
                        float xHit = SnapToGrid(hitLoc.X);
                        float yHit = SnapToGrid(hitLoc.Y);
                        float zHit = SnapToGrid(hitLoc.Z);
                        FVector hitGrid = FVector(xHit, yHit, zHit);
                        dist = FVector::Dist(GetActorLocation(), hitLoc);
                        AddGrid(hitLoc, true);
                    }
                }
                gridY += GRID_SIZE;
            }
            gridX += GRID_SIZE;
        }
        gridZ += GRID_SIZE;
    }
    DetectionTask();
}
void AUSARAgent :: UpdateMap ( ) { FVector currLoc = GetActorLocation ( ) ; float xMax = currLoc . X + VISION_RADIUS ; float yMax = currLoc . Y + VISION_RADIUS ; float zMax = currLoc . Z + VISION_RADIUS ; float gridZ = currLoc . Z - VISION_RADIUS ; while ( gridZ <= zMax ) { float gridX = currLoc . X - VISION_RADIUS ; while ( gridX <= xMax ) { float gridY = currLoc . Y - VISION_RADIUS ; while ( gridY <= yMax ) { FVector gridLoc = FVector ( gridX , gridY , gridZ ) ; float dist = FVector :: Dist ( currLoc , gridLoc ) ; if ( dist <= VISION_RADIUS ) { FHitResult hitResult ; FCollisionObjectQueryParams objectParams ; objectParams . AddObjectTypesToQuery ( ECC_WorldStatic ) ; FCollisionQueryParams queryParams ; queryParams . AddIgnoredActor ( this ) ; if ( ! GetWorld ( ) -> LineTraceSingleByObjectType ( hitResult , currLoc , gridLoc , objectParams , queryParams ) ) { AddGrid ( gridLoc , false ) ; } else { FVector hitLoc = hitResult . ImpactPoint ; float xHit = SnapToGrid ( hitLoc . X ) ; float yHit = SnapToGrid ( hitLoc . Y ) ; float zHit = SnapToGrid ( hitLoc . Z ) ; FVector hitGrid = FVector ( xHit , yHit , zHit ) ; dist = FVector :: Dist ( GetActorLocation ( ) , hitLoc ) ; AddGrid ( hitLoc , true ) ; } } gridY += GRID_SIZE ; } gridX += GRID_SIZE ; } gridZ += GRID_SIZE ; } DetectionTask ( ) ; }
Update the agent's onboard map from sensor data.
Update the agent ' s onboard map from sensor data .
/*DEBUGGING*/ //if (showDebug) { //    DrawDebugPoint(GetWorld(), hitGrid, 5, FColor::Orange, false, RATE_MAP_UPDATE); //} /*DEBUGGING*/