void UAISenseConfig_Hearing::DrawDebugInfo(UCanvas& Canvas, UAIPerceptionComponent& PerceptionComponent) const { const AActor* BodyActor = PerceptionComponent.GetBodyActor(); if (BodyActor != nullptr) { UWorld* World = BodyActor->GetWorld(); FVector OwnerLocation = BodyActor->GetActorLocation(); DrawDebugCylinder(World, OwnerLocation, OwnerLocation + FVector(0, 0, -50), HearingRange, 32, UAISense_Hearing::GetDebugHearingRangeColor()); if (bUseLoSHearing) { DrawDebugCylinder(World, OwnerLocation, OwnerLocation + FVector(0, 0, -50), LoSHearingRange, 32, UAISense_Hearing::GetDebugLoSHearingRangeeColor()); } } }
void UAISenseConfig_Sight::DrawDebugInfo(UCanvas& Canvas, UAIPerceptionComponent& PerceptionComponent) const { /*PeripheralVisionAngleDegrees*/ const AActor* BodyActor = PerceptionComponent.GetBodyActor(); if (BodyActor != nullptr) { UWorld* World = BodyActor->GetWorld(); FVector BodyLocation, BodyFacing; PerceptionComponent.GetLocationAndDirection(BodyLocation, BodyFacing); DrawDebugCylinder(World, BodyLocation, BodyLocation + FVector(0, 0, -50), SightRadius, 32, UAISense_Sight::GetDebugSightRangeColor()); DrawDebugCylinder(World, BodyLocation, BodyLocation + FVector(0, 0, -50), LoseSightRadius, 32, UAISense_Sight::GetDebugLoseSightColor()); const float SightPieLength = FMath::Max(LoseSightRadius, SightRadius); DrawDebugLine(World, BodyLocation, BodyLocation + (BodyFacing * SightPieLength), UAISense_Sight::GetDebugSightRangeColor()); DrawDebugLine(World, BodyLocation, BodyLocation + (BodyFacing.RotateAngleAxis(PeripheralVisionAngleDegrees, FVector::UpVector) * SightPieLength), UAISense_Sight::GetDebugSightRangeColor()); DrawDebugLine(World, BodyLocation, BodyLocation + (BodyFacing.RotateAngleAxis(-PeripheralVisionAngleDegrees, FVector::UpVector) * SightPieLength), UAISense_Sight::GetDebugSightRangeColor()); } }
void AGameplayDebuggingHUDComponent::DrawPerception(APlayerController* PC, class UGameplayDebuggingComponent *DebugComponent) { #if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) if (!DebugComponent) { return; } PrintString(DefaultContext, FColor::Green, TEXT("\nPERCEPTION COMPONENT\n")); PrintString(DefaultContext, FString::Printf(TEXT("Draw Colors:"))); PrintString(DefaultContext, *DebugComponent->PerceptionLegend); PrintString(DefaultContext, FString::Printf(TEXT("\nDistance Sensor-PlayerPawn: %.1f\n"), DebugComponent->DistanceFromSensor)); PrintString(DefaultContext, FString::Printf(TEXT("Distance Pawn-PlayerPawn: %.1f\n"), DebugComponent->DistanceFromPlayer)); float VerticalLabelOffset = 0.f; for (const FGameplayDebuggerShapeElement& Shape : DebugComponent->PerceptionShapeElements) { switch (Shape.GetType()) { case EGameplayDebuggerShapeElement::String: { const FVector& Loc = Shape.Points[0]; const FVector ScreenLoc = DefaultContext.Canvas->Project(Loc); PrintString(DefaultContext, Shape.GetFColor(), Shape.Description, ScreenLoc.X, ScreenLoc.Y + VerticalLabelOffset); VerticalLabelOffset += 17; } break; case EGameplayDebuggerShapeElement::Segment: { DrawDebugLine(World, Shape.Points[0], Shape.Points[1], Shape.GetFColor()); } break; case EGameplayDebuggerShapeElement::SinglePoint: { DrawDebugSphere(World, Shape.Points[0], Shape.ThicknesOrRadius, 16, Shape.GetFColor()); } break; case EGameplayDebuggerShapeElement::Cylinder: { static const float DefaultCylinderHeight = 50.f; const FVector EndLocation = ensure(Shape.Points.Num() > 1) ? Shape.Points[1] : (Shape.Points[0] + FVector::UpVector * DefaultCylinderHeight); DrawDebugCylinder(World, Shape.Points[0], Shape.Points[1], Shape.ThicknesOrRadius, 16, Shape.GetFColor()); } break; } } #endif // !(UE_BUILD_SHIPPING || UE_BUILD_TEST) }
void UCrowdManager::DrawDebugNeighbors(const dtCrowdAgent* CrowdAgent) const { UWorld* World = GetWorld(); FVector Center = Recast2UnrealPoint(CrowdAgent->npos) + CrowdDebugDrawing::Offset; DrawDebugCylinder(World, Center - CrowdDebugDrawing::Offset, Center, CrowdAgent->params.collisionQueryRange, 32, CrowdDebugDrawing::CollisionRange); for (int32 Idx = 0; Idx < CrowdAgent->nneis; Idx++) { const dtCrowdAgent* nei = DetourCrowd->getAgent(CrowdAgent->neis[Idx].idx); if (nei) { FVector Pt0 = Recast2UnrealPoint(nei->npos) + CrowdDebugDrawing::Offset; DrawDebugLine(World, Center, Pt0, CrowdDebugDrawing::Neighbor); } } }
void UCrowdManager::DrawDebugCollisionSegments(const dtCrowdAgent* CrowdAgent) const { FVector Center = Recast2UnrealPoint(CrowdAgent->boundary.getCenter()) + CrowdDebugDrawing::Offset; DrawDebugCylinder(GetWorld(), Center - CrowdDebugDrawing::Offset, Center, CrowdAgent->params.collisionQueryRange, 32, CrowdDebugDrawing::CollisionRange); for (int32 Idx = 0; Idx < CrowdAgent->boundary.getSegmentCount(); Idx++) { const float* s = CrowdAgent->boundary.getSegment(Idx); const int32 SegFlags = CrowdAgent->boundary.getSegmentFlags(Idx); const FColor Color = (SegFlags & DT_CROWD_BOUNDARY_IGNORE) ? CrowdDebugDrawing::CollisionSegIgnored : (dtTriArea2D(CrowdAgent->npos, s, s + 3) < 0.0f) ? CrowdDebugDrawing::CollisionSeg1 : CrowdDebugDrawing::CollisionSeg0; FVector Pt0 = Recast2UnrealPoint(s); FVector Pt1 = Recast2UnrealPoint(s + 3); DrawDebugLine(GetWorld(), Pt0 + CrowdDebugDrawing::Offset, Pt1 + CrowdDebugDrawing::Offset, Color, false, -1.0f, SDPG_World, 3.5f); } }
void UCrowdManager::DrawDebugSharedBoundary() const { UWorld* World = GetWorld(); FColor Colors[] = { FColorList::Red, FColorList::Orange }; const dtSharedBoundary* sharedBounds = DetourCrowd->getSharedBoundary(); for (int32 Idx = 0; Idx < sharedBounds->Data.Num(); Idx++) { FColor Color = Colors[Idx % ARRAY_COUNT(Colors)]; const FVector Center = Recast2UnrealPoint(sharedBounds->Data[Idx].Center); DrawDebugCylinder(World, Center - CrowdDebugDrawing::Offset, Center, sharedBounds->Data[Idx].Radius, 32, Color); for (int32 WallIdx = 0; WallIdx < sharedBounds->Data[Idx].Edges.Num(); WallIdx++) { const FVector WallV0 = Recast2UnrealPoint(sharedBounds->Data[Idx].Edges[WallIdx].v0) + CrowdDebugDrawing::Offset; const FVector WallV1 = Recast2UnrealPoint(sharedBounds->Data[Idx].Edges[WallIdx].v1) + CrowdDebugDrawing::Offset; DrawDebugLine(World, WallV0, WallV1, Color); } } }
void UCrowdManager::DrawDebugVelocityObstacles(const dtCrowdAgent* CrowdAgent) const { FVector Center = Recast2UnrealPoint(CrowdAgent->npos) + CrowdDebugDrawing::Offset; DrawDebugCylinder(GetWorld(), Center - CrowdDebugDrawing::Offset, Center, CrowdAgent->params.maxSpeed, 32, CrowdDebugDrawing::AvoidanceRange); const float InvQueryMultiplier = 1.0f / CrowdAgent->params.avoidanceQueryMultiplier; float BestSampleScore = -1.0f; FVector BestSampleLocation = FVector::ZeroVector; for (int32 Idx = 0; Idx < DetourAvoidanceDebug->getSampleCount(); Idx++) { const float* p = DetourAvoidanceDebug->getSampleVelocity(Idx); const float sr = DetourAvoidanceDebug->getSampleSize(Idx) * InvQueryMultiplier; const float pen = DetourAvoidanceDebug->getSamplePenalty(Idx); const float pen2 = DetourAvoidanceDebug->getSamplePreferredSidePenalty(Idx); FVector SamplePos = Center + Recast2UnrealPoint(p); if (BestSampleScore <= -1.0f || pen < BestSampleScore) { BestSampleScore = pen; BestSampleLocation = SamplePos; } float SamplePenalty = pen * 0.75f + pen2 * 0.25f; FColor SampleColor = FColor::MakeRedToGreenColorFromScalar(1.0f - SamplePenalty); FPlane Plane(0, 0, 1, SamplePos.Z); DrawDebugSolidPlane(GetWorld(), Plane, SamplePos, sr, SampleColor); } if (BestSampleScore >= 0.0f) { DrawDebugLine(GetWorld(), BestSampleLocation + FVector(0, 0, 100), BestSampleLocation + FVector(0, 0, -100), FColor::Green); } }
void FNavigationPath::DebugDraw(const ANavigationData* NavData, FColor PathColor, UCanvas* Canvas, bool bPersistent, const uint32 NextPathPointIndex) const { static const FColor Grey(100,100,100); const int32 NumPathVerts = PathPoints.Num(); UWorld* World = NavData->GetWorld(); for (int32 VertIdx = 0; VertIdx < NumPathVerts-1; ++VertIdx) { // draw box at vert FVector const VertLoc = PathPoints[VertIdx].Location + NavigationDebugDrawing::PathOffset; DrawDebugSolidBox(World, VertLoc, NavigationDebugDrawing::PathNodeBoxExtent, VertIdx < int32(NextPathPointIndex) ? Grey : PathColor, bPersistent); // draw line to next loc FVector const NextVertLoc = PathPoints[VertIdx+1].Location + NavigationDebugDrawing::PathOffset; DrawDebugLine(World, VertLoc, NextVertLoc, VertIdx < int32(NextPathPointIndex)-1 ? Grey : PathColor, bPersistent , /*LifeTime*/-1.f, /*DepthPriority*/0 , /*Thickness*/NavigationDebugDrawing::PathLineThickness); } // draw last vert if (NumPathVerts > 0) { DrawDebugBox(World, PathPoints[NumPathVerts-1].Location + NavigationDebugDrawing::PathOffset, FVector(15.f), PathColor, bPersistent); } // if observing goal actor draw a radius and a line to the goal if (GoalActor.IsValid()) { const FVector GoalLocation = GetGoalLocation() + NavigationDebugDrawing::PathOffset; const FVector EndLocation = GetEndLocation() + NavigationDebugDrawing::PathOffset; static const FVector CylinderHalfHeight = FVector::UpVector * 10.f; DrawDebugCylinder(World, EndLocation - CylinderHalfHeight, EndLocation + CylinderHalfHeight, FMath::Sqrt(GoalActorLocationTetherDistanceSq), 16, PathColor, bPersistent); DrawDebugLine(World, EndLocation, GoalLocation, Grey, bPersistent); } }
void FGameplayDebuggerShape::Draw(UWorld* World, FGameplayDebuggerCanvasContext& Context) { FVector DescLocation; switch (Type) { case EGameplayDebuggerShape::Point: if (ShapeData.Num() == 2 && ShapeData[1].X > 0) { DrawDebugSphere(World, ShapeData[0], ShapeData[1].X, 16, Color); DescLocation = ShapeData[0]; } break; case EGameplayDebuggerShape::Segment: if (ShapeData.Num() == 3 && ShapeData[2].X > 0) { DrawDebugLine(World, ShapeData[0], ShapeData[1], Color, false, -1.0f, 0, ShapeData[2].X); DescLocation = (ShapeData[0] + ShapeData[1]) * 0.5f; } break; case EGameplayDebuggerShape::Box: if (ShapeData.Num() == 2) { DrawDebugBox(World, ShapeData[0], ShapeData[1], Color); DescLocation = ShapeData[0]; } break; case EGameplayDebuggerShape::Cone: if (ShapeData.Num() == 3 && ShapeData[2].X > 0) { DrawDebugCone(World, ShapeData[0], ShapeData[1], ShapeData[2].X, PI * 0.5f, PI * 0.5f, 16, Color); DescLocation = ShapeData[0]; } break; case EGameplayDebuggerShape::Cylinder: if (ShapeData.Num() == 2) { DrawDebugCylinder(World, ShapeData[0] - FVector(0, 0, ShapeData[1].Z), ShapeData[0] + FVector(0, 0, ShapeData[1].Z), ShapeData[1].X, 16, Color); DescLocation = ShapeData[0]; } break; case EGameplayDebuggerShape::Capsule: if (ShapeData.Num() == 2) { DrawDebugCapsule(World, ShapeData[0], ShapeData[1].Z, ShapeData[1].X, FQuat::Identity, Color); DescLocation = ShapeData[0]; } break; case EGameplayDebuggerShape::Polygon: if (ShapeData.Num() > 0) { FVector MidPoint = FVector::ZeroVector; TArray<int32> Indices; for (int32 Idx = 0; Idx < ShapeData.Num(); Idx++) { Indices.Add(Idx); MidPoint += ShapeData[Idx]; } DrawDebugMesh(World, ShapeData, Indices, Color); DescLocation = MidPoint / ShapeData.Num(); } break; default: break; } if (Description.Len() && Context.IsLocationVisible(DescLocation)) { const FVector2D ScreenLoc = Context.ProjectLocation(DescLocation); Context.PrintAt(ScreenLoc.X, ScreenLoc.Y, Color, Description); } }