Files
integration/Source/Integration/LookAtDetector.cpp
2024-09-17 17:22:47 -04:00

82 lines
3.1 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "LookAtDetector.h"
#include "IntegrationGameModeBase.h"
UlxLookAtActorBase::UlxLookAtActorBase() {
GameMode = nullptr;
Player = nullptr;
PlayerController = nullptr;
CameraManager = nullptr;
PreviousSelectedActor = nullptr;
CurrentSelectedActor = nullptr;
}
void UlxLookAtActorBase::Update() {
GameMode = nullptr;
Player = nullptr;
PlayerController = nullptr;
CameraManager = nullptr;
PreviousSelectedActor = CurrentSelectedActor;
CurrentSelectedActor = nullptr;
// Make sure the world is fully configured before we attempt to cast rays.
AIntegrationGameModeBase *gm = AIntegrationGameModeBase::GetFromWorld(GetWorld());
if (gm == nullptr) return;
UlxTangible *possessed = gm->TangibleManager->GetPossessedTangible();
if (possessed == nullptr) return;
APlayerController *pc = GetWorld()->GetFirstPlayerController();
if (pc == nullptr) return;
APawn *pawn = pc->GetPawn();
if (pawn == nullptr) return;
APlayerCameraManager *cam = pc->PlayerCameraManager;
if (cam == nullptr) return;
GameMode = gm;
Player = pawn;
PlayerController = pc;
CameraManager = cam;
Recalculate();
}
// void AIntegrationGameModeBase::CastCameraRay() {
// // The range we're using is currently hardwired.
// double range = 1000.0;
// // Get the ray in question.
// APlayerCameraManager *camManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager;
// FVector TraceStart = camManager->GetCameraLocation();
// FVector TraceVector = camManager->GetCameraRotation().Vector();
// FVector TraceEnd = TraceStart + (TraceVector * range);
// // FHitResult will hold all data returned by our line collision query
// FHitResult Hit;
// // You can use FCollisionQueryParams to further configure the query
// // Here we add ourselves to the ignored list so we won't block the trace
// FCollisionQueryParams QueryParams;
// QueryParams.AddIgnoredActor(possessed->GetActor());
// // To run the query, you need a pointer to the current level, which you can get from an Actor with GetWorld()
// // UWorld()->LineTraceSingleByChannel runs a line trace and returns the first actor hit over the provided collision channel.
// GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_Visibility, QueryParams);
// // You can use DrawDebug helpers and the log to help visualize and debug your trace queries.
// // DrawDebugLine(GetWorld(), TraceStart, TraceEnd, Hit.bBlockingHit ? FColor::Blue : FColor::Red, false, 2.0f, 0, 5.0f);
// // UE_LOG(LogTemp, Log, TEXT("Tracing line: %s to %s"), *TraceStart.ToCompactString(), *TraceVector.ToCompactString());
// // If the trace hit something, bBlockingHit will be true,
// // and its fields will be filled with detailed info about what was hit
// if (Hit.bBlockingHit && IsValid(Hit.GetActor())) {
// CameraRayChanged = (CameraRayTarget != Hit.GetActor());
// CameraRayTarget = Hit.GetActor();
// } else {
// CameraRayChanged = (CameraRayTarget != nullptr);
// CameraRayTarget = nullptr;
// }
// }