Cesium 全球视角 和 多方案镜头切换

一.切换镜头

镜头切换,在一个Pawn里的多个镜头。可以使用UE中World Settings里的玩家控制器中,默认的控制器行为会对当前开启的Camera组件进行激活处理。 

谁激活谁就是主相机。

			Cast<UCameraComponent>(m_childComponentMap[it.CameraName])->SetAutoActivate(false);
			Cast<UCameraComponent>(m_childComponentMap[it.CameraName])->SetActive(false);

激活处理。

但是如果是两个Pawn之间切换,就要用Poccess 掌控。蓝图如下:

1.我用这两个都行,前提是这个是在世界里的物体。

	APlayerController* tmpPC = UGameplayStatics::GetPlayerController(GetWorld(), 0);
APlayerController* tmpPC = UGameplayStatics::GetPlayerController(Cast<UObject>(this), 0);
APlayerController* PC1 = GetWorld()->GetFirstLocalPlayerFromController()->GetPlayerController(GetWorld());

APlayerController* PC2 = GetWorld()->GetFirstPlayerController();

APlayerController* PC3 = GEngine->GetFirstLocalPlayerController(GetWorld());

APlayerController* PC4 = UGameplayStatics::GetPlayerController(GetWorld(), 0);

这里我是让每个Pawn自己抢夺,控制权。将Controller安在自己身上。实现不同Pawn之间的是视角切换。

		tmpPC->SetViewTargetWithBlend(Cast<AActor>(this));
		tmpPC->Possess(this);

二. 全球视角 有点像卫星,绕着地球转。

1.这个主要讲思路因为实现,算是比较好实现了。

将控制拿到。

	APlayerController* tmpPC = UGameplayStatics::GetPlayerController(Cast<UObject>(this), 0);
	if (tmpPC)
	{
		tmpPC->SetViewTargetWithBlend(Cast<AActor>(this));
		tmpPC->Possess(this);
		/*m_childComponentMap[cameraName]->SetActive(true);
		usingCamera = Cast<UCameraComponent>(m_childComponentMap[cameraName]);*/
	}

2.通过GlobeAnchor位移,鼠标导致经纬移动,有插值和映射,离地球越远越快。

void AWorldCameraPawn::MoveX(float value)
{
	if (globeAnchor != nullptr)
	{
		FVector curLLH = globeAnchor->GetLongitudeLatitudeHeight();
		double height = curLLH.Z;
		double change;
		change= UKismetMathLibrary::MapRangeClamped(height, 100, 100000, 0.001, 0.3);
		FVector toLLH = FVector(curLLH.X + value * change, curLLH.Y, curLLH.Z);
		FVector finalLLH = FVector(FMath::Lerp(curLLH.X, toLLH.X, 0.1), curLLH.Y, curLLH.Z);
		globeAnchor->MoveToLongitudeLatitudeHeight(finalLLH);
		globeAnchor->SetEastSouthUpRotation(FRotator(-90, 0 - 90, 0).Quaternion());
	}
}

3.滚轮 导致高度变化

void AWorldCameraPawn::MoveUp()
{
	if (globeAnchor != nullptr)
	{
		FVector curLLH = globeAnchor->GetLongitudeLatitudeHeight();
		double height = curLLH.Z;
		double changeAltitude;
		double toAltitude;
		if (height > 10000)
		{
			changeAltitude = UKismetMathLibrary::MapRangeClamped(height, 100, 100000, 10, 200000);
			toAltitude = curLLH.Z + changeAltitude;	
		}
		else
		{
			changeAltitude = UKismetMathLibrary::MapRangeClamped(height, 100, 10000, 10, 1000);
			toAltitude = curLLH.Z + changeAltitude;
		}

		if (toAltitude < 300)
		{
			toAltitude = 300;
		}
		FVector toLLH = FVector(curLLH.X, curLLH.Y, toAltitude);
		globeAnchor->MoveToLongitudeLatitudeHeight(toLLH);
		globeAnchor->SetEastSouthUpRotation(FRotator(-90, 0 - 90, 0).Quaternion());
	}
}

三.处理输入,最好在Controller里,为什么因为你的Pawn换了,你也能逻辑清晰,不必重写。

同一个输入,可以将不同的Pawn对应不同的功能,可能相同也可能不同。这里WorldPawn就是升高高度。而MyCameraPawn是伸缩弹簧臂。

void PlayerController::WheelUpFunction()
{
		
		if (GetPawn()) {
		AAirForce* MyCameraPawn = Cast<AAirForce>(GetPawn());
		
		if (MyCameraPawn) {
			MyCameraPawn->Zoom(0, 10);
		}
		AWorldCameraPawn* WorldCameraPawn = Cast<AWorldCameraPawn>(GetPawn());
		if (WorldCameraPawn)
		{
			WorldCameraPawn->MoveDown();

		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值