Working on camera ray stuff, not working right now

This commit is contained in:
2024-09-11 16:07:47 -04:00
parent fabbc55b86
commit 6556efed10
5 changed files with 97 additions and 27 deletions

View File

@@ -80,8 +80,15 @@ void AIntegrationGameModeBase::ResetToInitialState()
// Clear the lua call assembly buffer.
LuaCallBuffer.clear();
// Clear the PlayerID
PlayerId = 0;
// Clear the camera ray state.
CameraRayTarget = nullptr;
CameraRayChanged = false;
// Reset the clocks.
EngineSeconds = 0;
EngineSeconds = 0.0;
NextRotateCube = 1.0;
}
@@ -123,12 +130,6 @@ void AIntegrationGameModeBase::UpdateTangibles() {
for (int i = 0; i < alltans.Num(); i++) {
alltans[i]->UpdateAnimationQueue(allqueues[i]);
}
// Maybe call 'BecomePossessed' on some tangible.
UlxTangible *poss = TangibleManager->SetPossessedTangible(PlayerId);
if (poss != nullptr) {
IlxTangibleInterface::Execute_BecomePossessed(poss->GetActor());
}
}
// This is where we run the blueprint code that updates animation
// states. Be aware that the blueprint code could call back
@@ -141,6 +142,64 @@ void AIntegrationGameModeBase::UpdateTangibles() {
TangibleManager->DeleteFarawayTangibles();
}
void AIntegrationGameModeBase::UpdatePossessedTangible() {
bool updated = TangibleManager->SetPossessedTangible(PlayerId);
if (updated) {
UlxTangible *ptan = TangibleManager->GetPossessedTangible();
if (ptan != nullptr) {
IlxTangibleInterface::Execute_BecomePossessed(ptan->GetActor());
}
}
}
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);
@@ -213,6 +272,8 @@ void AIntegrationGameModeBase::OnWorldPreActorTick(UWorld* InWorld, ELevelTick I
EngineSeconds += deltaseconds;
UpdateConsoleOutput();
UpdateTangibles();
UpdatePossessedTangible();
//CastCameraRay();
}
}
@@ -228,8 +289,6 @@ void AIntegrationGameModeBase::OnWorldPostActorTick(UWorld* InWorld, ELevelTick
void AIntegrationGameModeBase::Tick(float deltaseconds)
{
Super::Tick(deltaseconds);
UpdateConsoleOutput();
UpdateTangibles();
}
void AIntegrationGameModeBase::BeginPlay()