• 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;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    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(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;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    #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);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

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

  • 相关阅读:
    1462. 课程表 IV-深度优先遍历
    【群答疑】jmeter关联获取上一个请求返回的字符串,分割后保存到数组,把数组元素依次作为下一个请求的入参...
    Java - @Transaction 异常不回滚
    netty系列之:使用Jboss Marshalling来序列化java对象
    IQ Products巨细胞病毒CMV感染检测试剂盒的特征和应用
    Jetson查看JetPack版本(tool)
    IDEA中的“Deployment“ 将项目直接部署到服务器上
    Kafka系列之:深入理解死信队列和重试队列
    2023人工智能全景报告《State of AI Report》出炉!AI未来一年的10大预测:GPT-4仍是全球最强,GenAI 大爆发,...
    VR开发(一)——SteamVR实现摇杆移动
  • 原文地址:https://blog.csdn.net/directx3d_beginner/article/details/126392074