代码拉取完成,页面将自动刷新
#include "SCTLocationCapturer.h"
#include "Engine/SceneCapture2D.h"
#include "Engine/TextureRenderTarget2D.h"
#include "Components/SceneCaptureComponent2D.h"
#include "Engine/Engine.h"
#include "GameFramework/PlayerInput.h"
#include "Kismet/GameplayStatics.h"
#include "Camera/CameraComponent.h"
#include "TypedPrimitive.h"
#include "Materials/MaterialInstanceDynamic.h"
#include "Components/DrawFrustumComponent.h"
#include "GameFramework/SpringArmComponent.h"
#define NUM_SIDES 24
ASCTLocationCapturer* ASCTLocationCapturer::_Instance = nullptr;
ASCTLocationCapturer* ASCTLocationCapturer::GetCapturer2DInstance()
{
if (ASCTLocationCapturer::_Instance == nullptr)
{
//创建小地图摄像机并拖放到场景里
ASCTLocationCapturer::_Instance = GWorld->SpawnActor<ASCTLocationCapturer>(ASCTLocationCapturer::StaticClass());
}
return ASCTLocationCapturer::_Instance;
}
ASCTLocationCapturer::ASCTLocationCapturer()
{
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComponent"));
/*创建弹簧手臂和摄像机*/
CameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
CameraSpringArm->SetupAttachment(RootComponent);
CameraSpringArm->TargetArmLength = 500.f;
CameraSpringArm->bEnableCameraLag = false;
CameraSpringArm->bUsePawnControlRotation = true;
CameraSpringArm->bDoCollisionTest = false;
CameraSpringArm->CameraLagSpeed = 3.0f;
GetCaptureComponent2D()->SetupAttachment(CameraSpringArm);
GetCaptureComponent2D()->bCaptureEveryFrame = true;
GetCaptureComponent2D()->CaptureSource = ESceneCaptureSource::SCS_SceneColorSceneDepth;
GetCaptureComponent2D()->ProjectionType = ECameraProjectionMode::Perspective;
GetCaptureComponent2D()->OrthoWidth = 150.0f;
GetCaptureComponent2D()->CompositeMode = ESceneCaptureCompositeMode::SCCM_Overwrite;
GetCaptureComponent2D()->PrimitiveRenderMode = ESceneCapturePrimitiveRenderMode::PRM_UseShowOnlyList;
}
UTextureRenderTarget2D* ASCTLocationCapturer::GetMiniMapTexture()
{
//实例化渲染贴图
MiniMapTexture = NewObject<UTextureRenderTarget2D>();
MiniMapTexture->InitAutoFormat(128.0f, 128.0f);
MiniMapTexture->ClearColor = FLinearColor(1.0f, 0, 0, 1.0f);
//将相机的渲染目标到纹理上
GetCaptureComponent2D()->TextureTarget = MiniMapTexture;
return MiniMapTexture;
}
void ASCTLocationCapturer::UpdateCapture2DTransform(FVector ArroundLocation, FRotator NormRotator)
{
CameraSpringArm->SetWorldLocation(ArroundLocation);
CameraSpringArm->SetWorldRotation(NormRotator);
}
void ASCTLocationCapturer::ShowActor(AActor* AxisActor)
{
//创建显示的场景
GetCaptureComponent2D()->ShowOnlyActorComponents(AxisActor);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。