|
|
|
|
| #include "LyraCameraComponent.h"
|
|
|
| #include "Engine/Canvas.h"
|
| #include "Engine/Engine.h"
|
| #include "GameFramework/Pawn.h"
|
| #include "GameFramework/PlayerController.h"
|
| #include "LyraCameraMode.h"
|
|
|
| #include UE_INLINE_GENERATED_CPP_BY_NAME(LyraCameraComponent)
|
|
|
|
|
| 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);
|
|
|
|
|
| if (APawn* TargetPawn = Cast<APawn>(GetTargetActor()))
|
| {
|
| if (APlayerController* PC = TargetPawn->GetController<APlayerController>())
|
| {
|
| PC->SetControlRotation(CameraModeView.ControlRotation);
|
| }
|
| }
|
|
|
|
|
| CameraModeView.FieldOfView += FieldOfViewOffset;
|
| FieldOfViewOffset = 0.0f;
|
|
|
|
|
| SetWorldLocationAndRotation(CameraModeView.Location, CameraModeView.Rotation);
|
| FieldOfView = CameraModeView.FieldOfView;
|
|
|
|
|
| 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;
|
|
|
|
|
| DesiredView.PostProcessBlendWeight = PostProcessBlendWeight;
|
| if (PostProcessBlendWeight > 0.0f)
|
| {
|
| DesiredView.PostProcessSettings = PostProcessSettings;
|
| }
|
|
|
|
|
| if (IsXRHeadTrackedCamera())
|
| {
|
|
|
| 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( OutWeightOfTopLayer, OutTagOfTopLayer);
|
| }
|
|
|
|
|
|
|