Implemented LookAtDetectorBase
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "DebugPrint.h"
|
||||
#include "Tangible.h"
|
||||
#include "TangibleManager.h"
|
||||
#include "LookAtDetector.h"
|
||||
#include "CommonTypes.h"
|
||||
#include "AnimQueue.h"
|
||||
#include <string>
|
||||
@@ -83,9 +84,8 @@ void AIntegrationGameModeBase::ResetToInitialState()
|
||||
// Clear the PlayerID
|
||||
PlayerId = 0;
|
||||
|
||||
// Clear the camera ray state.
|
||||
CameraRayTarget = nullptr;
|
||||
CameraRayChanged = false;
|
||||
// Clear the actor selector;
|
||||
LookAtDetector = nullptr;
|
||||
|
||||
// Reset the clocks.
|
||||
EngineSeconds = 0.0;
|
||||
@@ -152,54 +152,6 @@ void AIntegrationGameModeBase::UpdatePossessedTangible() {
|
||||
}
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::CastCameraRay() {
|
||||
// The range we're using is currently hardwired.
|
||||
double range = 1000.0;
|
||||
|
||||
// If there's no possessed tangible, then we don't even try casting the ray.
|
||||
UlxTangible *possessed = TangibleManager->GetPossessedTangible();
|
||||
if (possessed == nullptr) {
|
||||
CameraRayChanged = (CameraRayTarget != nullptr);
|
||||
CameraRayTarget = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the ray in question.
|
||||
// APlayerCameraManager *camManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager;
|
||||
// FVector TraceStart = camManager->GetCameraLocation();
|
||||
// FVector TraceEnd = camManager->GetCameraRotation().Vector() * range;
|
||||
FVector TraceStart, TraceVector;
|
||||
APlayerController *ctrl = GetWorld()->GetFirstPlayerController();
|
||||
ctrl->DeprojectScreenPositionToWorld(0.5, 0.5, TraceStart, TraceVector);
|
||||
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, 5.0f, 0, 10.0f);
|
||||
// UE_LOG(LogTemp, Log, TEXT("Tracing line: %s to %s"), *TraceStart.ToCompactString(), *TraceEnd.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;
|
||||
}
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::LuaCallEnd(InvocationKind kind, int64 place_id) {
|
||||
std::string_view datapk = LuaCallBuffer.view();
|
||||
FlxLockedWrapper w(LockableWrapper);
|
||||
@@ -273,7 +225,7 @@ void AIntegrationGameModeBase::OnWorldPreActorTick(UWorld* InWorld, ELevelTick I
|
||||
UpdateConsoleOutput();
|
||||
UpdateTangibles();
|
||||
UpdatePossessedTangible();
|
||||
//CastCameraRay();
|
||||
if (LookAtDetector != nullptr) LookAtDetector->Update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,6 +330,11 @@ AIntegrationGameModeBase *AIntegrationGameModeBase::GetFromContext(UObject *cont
|
||||
return GetFromWorld(context->GetWorld());
|
||||
}
|
||||
|
||||
void AIntegrationGameModeBase::SetLookAtDetector(UlxLookAtActorBase *selector) {
|
||||
LookAtDetector = selector;
|
||||
}
|
||||
|
||||
|
||||
// /** Gets the game mode that owns this component, this will always return null on the client */
|
||||
// template <class T>
|
||||
// T* GetGameMode() const
|
||||
|
||||
Reference in New Issue
Block a user