MCPcopy Create free account
hub / github.com/arnaud-jamin/Cog / EvaluateCandidate

Method EvaluateCandidate

Source/CogSample/CogSampleTargetAcquisition.cpp:398–609  ·  view source on GitHub ↗

--------------------------------------------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

396
397//--------------------------------------------------------------------------------------------------------------------------
398bool UCogSampleTargetAcquisition::EvaluateCandidate(
399 AActor* Candidate,
400 const FCogSampleTargetTargetAcquisitionParams& EvalParams,
401 float& CandidateScore,
402 bool& bIsCrosshairInsideCandidate) const
403{
404 TRACE_CPUPROFILER_EVENT_SCOPE(UCogSampleTargetAcquisition::EvaluateCandidate);
405
406 if (EvalParams.TargetsToIgnore.Contains(Candidate))
407 {
408 return false;
409 }
410
411 const FVector CandidateTargetLocation = UCogSampleFunctionLibrary_Gameplay::GetActorTargetLocation(Candidate);
412
413 FVector CandidateLocationDelta = CandidateTargetLocation - EvalParams.SourceLocation;
414 if (EvalParams.bWorldDistanceIgnoreZ)
415 {
416 CandidateLocationDelta.Z = 0.0f;
417 }
418 const float CandidateWorldDistance = CandidateLocationDelta.Length();
419 const FVector CandidateWorldDirection = CandidateWorldDistance > 0.0f ? CandidateLocationDelta / CandidateWorldDistance : FVector::ZeroVector;
420 const float ScreenMagnitude = FMath::Min(EvalParams.ViewRect.Width(), EvalParams.ViewRect.Height());
421 const bool IsSearchDirectionUsed = bUseSearchDirectionScore && EvalParams.SearchDirectionNormalized.IsNearlyZero() == false;
422
423 //--------------------------------------------------------------------------------------------------------------
424 // Filter by world distance limit
425 //--------------------------------------------------------------------------------------------------------------
426 if (CandidateWorldDistance > EvalParams.MaxWorldDistance)
427 {
428 IF_COG(FCogDebugDraw::String(LogCogTargetAcquisition, EvalParams.Controller, FString::Printf(TEXT("Dist: %0.2f"), CandidateWorldDistance * 0.01f), CandidateTargetLocation, FColor::Red, EvalParams.IsDebugPersistent));
429 return false;
430 }
431
432 //--------------------------------------------------------------------------------------------------------------
433 // Filter candidates base on yaw limit when using yaw, otherwise filter anyone behind the character
434 //--------------------------------------------------------------------------------------------------------------
435 const FVector CandidateWorldDirectionFlat = CandidateWorldDirection.GetSafeNormal2D();
436 const float CandidateDot = EvalParams.YawDirection.Dot(CandidateWorldDirectionFlat);
437 const float CandidateYaw = FRotator::NormalizeAxis(FMath::RadiansToDegrees(FMath::Acos(CandidateDot)));
438 if (bUseYawLimit && CandidateYaw > YawMax)
439 {
440 IF_COG(FCogDebugDraw::String(LogCogTargetAcquisition, EvalParams.Controller, FString::Printf(TEXT("Yaw: %0.2f"), CandidateYaw), CandidateTargetLocation, FColor::Red, EvalParams.IsDebugPersistent));
441 return false;
442 }
443
444 //--------------------------------------------------------------------------------------------------------------
445 // Find the candidate screen location. If the result distance is lower than zero, it means the crosshair is
446 // inside the candidate capsules.
447 //--------------------------------------------------------------------------------------------------------------
448 FVector2D CandidateScreenLocation;
449 FVector2D CandidateClosestScreenLocation;
450 float CandidateClosestScreenDistance;
451 const UCapsuleComponent* CandidateBestHitZone = nullptr;
452 if (!ComputeCandidateScreenLocation(Candidate, EvalParams, CandidateTargetLocation, CandidateScreenLocation, CandidateClosestScreenLocation, CandidateClosestScreenDistance))
453 {
454 return false;
455 }

Callers

nothing calls this directly

Calls 3

GetFloatValueMethod · 0.80
AppendMethod · 0.80
ContainsMethod · 0.45

Tested by

no test coverage detected