136 lines
4.1 KiB
C++
136 lines
4.1 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "LyraCameraComponent.h"
|
|
|
|
#include "Camera/CameraTypes.h"
|
|
#include "Containers/EnumAsByte.h"
|
|
#include "Containers/UnrealString.h"
|
|
#include "Engine/Canvas.h"
|
|
#include "Engine/Engine.h"
|
|
#include "Engine/Scene.h"
|
|
#include "GameFramework/Pawn.h"
|
|
#include "GameFramework/PlayerController.h"
|
|
#include "LyraCameraMode.h"
|
|
#include "Math/Color.h"
|
|
#include "Math/Rotator.h"
|
|
#include "Math/UnrealMathSSE.h"
|
|
#include "Math/Vector.h"
|
|
#include "Misc/AssertionMacros.h"
|
|
#include "Templates/Casts.h"
|
|
#include "Templates/SubclassOf.h"
|
|
#include "UObject/UObjectBaseUtility.h"
|
|
|
|
|
|
ULyraCameraComponent::ULyraCameraComponent(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
CameraModeStack = nullptr;
|
|
FieldOfViewOffset = 0.0f;
|
|
}
|
|
|
|
void ULyraCameraComponent::OnRegister()
|
|
{
|
|
Super::OnRegister();
|
|
|
|
if (!CameraModeStack)
|
|
{
|
|
CameraModeStack = NewObject<ULyraCameraModeStack>(this);
|
|
check(CameraModeStack);
|
|
}
|
|
}
|
|
|
|
void ULyraCameraComponent::GetCameraView(float DeltaTime, FMinimalViewInfo& DesiredView)
|
|
{
|
|
check(CameraModeStack);
|
|
|
|
UpdateCameraModes();
|
|
|
|
FLyraCameraModeView CameraModeView;
|
|
CameraModeStack->EvaluateStack(DeltaTime, CameraModeView);
|
|
|
|
// Keep player controller in sync with the latest view.
|
|
if (APawn* TargetPawn = Cast<APawn>(GetTargetActor()))
|
|
{
|
|
if (APlayerController* PC = TargetPawn->GetController<APlayerController>())
|
|
{
|
|
PC->SetControlRotation(CameraModeView.ControlRotation);
|
|
}
|
|
}
|
|
|
|
// Apply any offset that was added to the field of view.
|
|
CameraModeView.FieldOfView += FieldOfViewOffset;
|
|
FieldOfViewOffset = 0.0f;
|
|
|
|
// Keep camera component in sync with the latest view.
|
|
SetWorldLocationAndRotation(CameraModeView.Location, CameraModeView.Rotation);
|
|
FieldOfView = CameraModeView.FieldOfView;
|
|
|
|
// Fill in desired view.
|
|
DesiredView.Location = CameraModeView.Location;
|
|
DesiredView.Rotation = CameraModeView.Rotation;
|
|
DesiredView.FOV = CameraModeView.FieldOfView;
|
|
DesiredView.OrthoWidth = OrthoWidth;
|
|
DesiredView.OrthoNearClipPlane = OrthoNearClipPlane;
|
|
DesiredView.OrthoFarClipPlane = OrthoFarClipPlane;
|
|
DesiredView.AspectRatio = AspectRatio;
|
|
DesiredView.bConstrainAspectRatio = bConstrainAspectRatio;
|
|
DesiredView.bUseFieldOfViewForLOD = bUseFieldOfViewForLOD;
|
|
DesiredView.ProjectionMode = ProjectionMode;
|
|
|
|
// See if the CameraActor wants to override the PostProcess settings used.
|
|
DesiredView.PostProcessBlendWeight = PostProcessBlendWeight;
|
|
if (PostProcessBlendWeight > 0.0f)
|
|
{
|
|
DesiredView.PostProcessSettings = PostProcessSettings;
|
|
}
|
|
|
|
|
|
if (IsXRHeadTrackedCamera())
|
|
{
|
|
// In XR much of the camera behavior above is irrellevant, but the post process settings are not.
|
|
Super::GetCameraView(DeltaTime, DesiredView);
|
|
}
|
|
}
|
|
|
|
void ULyraCameraComponent::UpdateCameraModes()
|
|
{
|
|
check(CameraModeStack);
|
|
|
|
if (CameraModeStack->IsStackActivate())
|
|
{
|
|
if (DetermineCameraModeDelegate.IsBound())
|
|
{
|
|
if (const TSubclassOf<ULyraCameraMode> CameraMode = DetermineCameraModeDelegate.Execute())
|
|
{
|
|
CameraModeStack->PushCameraMode(CameraMode);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void ULyraCameraComponent::DrawDebug(UCanvas* Canvas) const
|
|
{
|
|
check(Canvas);
|
|
|
|
FDisplayDebugManager& DisplayDebugManager = Canvas->DisplayDebugManager;
|
|
|
|
DisplayDebugManager.SetFont(GEngine->GetSmallFont());
|
|
DisplayDebugManager.SetDrawColor(FColor::Yellow);
|
|
DisplayDebugManager.DrawString(FString::Printf(TEXT("LyraCameraComponent: %s"), *GetNameSafe(GetTargetActor())));
|
|
|
|
DisplayDebugManager.SetDrawColor(FColor::White);
|
|
DisplayDebugManager.DrawString(FString::Printf(TEXT(" Location: %s"), *GetComponentLocation().ToCompactString()));
|
|
DisplayDebugManager.DrawString(FString::Printf(TEXT(" Rotation: %s"), *GetComponentRotation().ToCompactString()));
|
|
DisplayDebugManager.DrawString(FString::Printf(TEXT(" FOV: %f"), FieldOfView));
|
|
|
|
check(CameraModeStack);
|
|
CameraModeStack->DrawDebug(Canvas);
|
|
}
|
|
|
|
void ULyraCameraComponent::GetBlendInfo(float& OutWeightOfTopLayer, FGameplayTag& OutTagOfTopLayer) const
|
|
{
|
|
check(CameraModeStack);
|
|
CameraModeStack->GetBlendInfo(/*out*/ OutWeightOfTopLayer, /*out*/ OutTagOfTopLayer);
|
|
}
|
|
|