您的位置:首页 > 汽车 > 时评 > Cesium 全球视角 和 多方案镜头切换

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

2024/10/8 3:42:49 来源:https://blog.csdn.net/m0_64217692/article/details/141175416  浏览:    关键词: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();}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com