cesium for unreal文档中的更新

以前调试过cesium for unreal,再调试时一惊,发现api变了。
静下心来思考流程
1,样本条要放在actor里
2,包含样本条的actor坐标放在原点
3,样本条坐标和法向量都要从经纬高到ue空间转换

变的只是api,所以深入了代码看了下,传递的经纬度从度数到了弧度。

废话不多说,上代码

//按照datatable进行获取数据
UCLASS()
class CESIUM_FLY_API APlaneTrack : public AActor
{
GENERATED_BODY()

public:
// Sets default values for this actor’s properties
APlaneTrack();

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

public:
// Called every frame
virtual void Tick(float DeltaTime) override;

public:
//用于保存航班数据的虚幻引擎数据表
UPROPERTY(EditAnywhere, Category = “FlightTracker”)
UDataTable* aircraftsRawDataTable;

//从两点间插值创建样条线轨迹
UFUNCTION(BlueprintCallable)
void LoadSplineTrackPoints();

UFUNCTION(BlueprintCallable)
USplineComponent* GetSplineTrack()
{
	return splineTrack;
}

//Cesium工具类,包含很多有用的坐标转换相关的函数
UPROPERTY(EditAnywhere, Category = "FlightTracker")
	ACesiumGeoreference* cesiumGeoreference;

private:
//根组件
class USceneComponent* RootScene;
//代表航班轨迹的样条线成员变量
USplineComponent* splineTrack;

};

// Called when the game starts or when spawned
void APlaneTrack::BeginPlay()
{
Super::BeginPlay();

}

// Called every frame
void APlaneTrack::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

void APlaneTrack::LoadSplineTrackPoints()
{
if (this->aircraftsRawDataTable == nullptr)
{
return;
}
if (nullptr == this->cesiumGeoreference)
{
return;
}

//初始化轨迹
splineTrack = NewObject<USplineComponent>(this,TEXT("SplineTrack"));
splineTrack->RegisterComponent();
//让样本线在运行模式下可见
splineTrack->SetDrawDebug(true);
//设置样本条的颜色
splineTrack->SetUnselectedSplineSegmentColor(FLinearColor(1.0f, 0.0f, 0.0f));
//设置样条线的粗细或者宽度
splineTrack->ScaleVisualizationWidth = 70.0f;
splineTrack->AttachToComponent(RootScene, FAttachmentTransformRules::KeepRelativeTransform);
int32 pointIndex = 0;
for (auto& row : this->aircraftsRawDataTable->GetRowMap())
{
	FAircraftRawData* point = (FAircraftRawData*)row.Value;
	//获取经纬高,转为Ue4坐标
	double pointLatitude = point->latitude;
	double pointLongitude = point->longitude;
	double pointHeight = point->height;

#if 1 //先统一加1000
pointHeight += 100;
#endif
//计算ue里的坐标
glm::dvec3 posXYZ = this->cesiumGeoreference->TransformLongitudeLatitudeHeightToUnreal(glm::dvec3(
FMath::DegreesToRadians(pointLongitude),
FMath::DegreesToRadians(pointLatitude),
FMath::DegreesToRadians(pointHeight)));
FVector splinePointPosition = FVector(posXYZ.x, posXYZ.y, posXYZ.z);
this->splineTrack->AddSplinePointAtIndex(splinePointPosition, pointIndex, ESplineCoordinateSpace::World, false);

	//获取飞机的向上方向
	const CesiumGeospatial::Ellipsoid& ell = CesiumGeospatial::Ellipsoid::WGS84;
	glm::dvec3 upVector = ell.geodeticSurfaceNormal(CesiumGeospatial::Cartographic(
		FMath::DegreesToRadians(pointLongitude),
		FMath::DegreesToRadians(pointLatitude),
		FMath::DegreesToRadians(pointHeight)));
	
	//计算飞机上的UE向上方向
	glm::dvec3 unrealUp = this->cesiumGeoreference->TransformLongitudeLatitudeHeightToUnreal(upVector);
	this->splineTrack->SetUpVectorAtSplinePoint(pointIndex, FVector(unrealUp.x, unrealUp.y, unrealUp.z), ESplineCoordinateSpace::World, false);
	pointIndex++;


}
this->splineTrack->UpdateSpline();
//this->AttachToComponent(this->cesiumGeoreference->GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);

}
另外数据库里的高度都是负值,钻到地底下了。所以都加个100
在这里插入图片描述
运行Ok

Cesium for Unreal是一个用于在虚幻引擎中集成Cesium的插件,它允许您在虚幻引擎中使用Cesium的地理可视化和地球渲染功能。要在离线环境下使用Cesium for Unreal,您可以按照以下步骤进行操作: 1. 下载和安装插件:将Cesium for Unreal插件下载到您的计算机上,并按照Cesium for Unreal官方文档中提供的说明进行安装。确保您已经安装了虚幻引擎,并且版本与插件兼容。 2. 准备离线地形数据:在离线环境中,您需要准备地形数据作为输入。这可以是地形切片、高程数据或其他格式的地形数据。 3. 导入地形数据:在虚幻引擎中,您可以使用Cesium for Unreal提供的工具来导入地形数据。具体步骤包括创建一个地形图层、指定地形数据源并进行导入。详细的导入步骤可以在Cesium for Unreal官方文档中找到。 4. 配置和使用插件功能:一旦地形数据导入成功,您可以使用Cesium for Unreal插件提供的功能来创建地球场景、添加3D模型、渲染卫星图像等。通过在虚幻引擎中使用Cesium for Unreal的蓝图和工具,您可以实现地理可视化和地球渲染效果。 请注意,Cesium for Unreal是一个商业插件,您可能需要购买许可证才能在离线环境中使用完整的功能。此外,确保遵守相关的许可和使用条款。 以上是使用Cesium for Unreal在离线环境中进行地理可视化和地球渲染的基本步骤。建议您参考Cesium for Unreal官方文档以获取更详细和具体的指导。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值