使用Cesium for Unreal插件构建航班轨迹
Build a Flight Tracker with Cesium for Unreal
使用航班ADS-B
数据创建USplineComponent
(样条曲线组件)构建航班轨迹,并通过Timeline
控制动画飞行的速度。
飞行轨迹
航班ADS-B数据
导入航班Excel
或者csv
数据到FAircraftRawData
。
USTRUCT(BlueprintType)
struct FAircraftRawData : public FTableRowBase
{
GENERATED_USTRUCT_BODY()
public:
FAircraftRawData()
: Longitude(0.0)
, Latitude(0.0)
, Height(0.0)
{}
UPROPERTY(EditAnywhere, Category = "FlightTracker")
double Longitude;
UPROPERTY(EditAnywhere, Category = "FlightTracker")
double Latitude;
UPROPERTY(EditAnywhere, Category = "FlightTracker")
double Height;
};
生成曲线轨迹
void APlaneTrack::LoadSplineTrackPoints()
{
if (this->AircraftsRawDataTable != nullptr && this->CesiumGeoreference != nullptr)
{
int32 PointIndex = 0;
for (auto& row : this->AircraftsRawDataTable->GetRowMap())
{
FAircraftRawData* Point = (FAircraftRawData*)row.Value;
// Get row data point in lat/long/alt and transform it into UE4 points
double PointLatitude = Point->Latitude;
double PointLongitude = Point->Longitude;
double PointHeight = Point->Height;
// Compute the position in UE coordinates
glm::dvec3 UECoords = this->CesiumGeoreference->TransformLongitudeLatitudeHeightToUe(glm::dvec3(PointLongitude, PointLatitude, PointHeight));
FVector SplinePointPosition = FVector(UECoords.x, UECoords.y, UECoords.z);
this->SplineTrack->AddSplinePointAtIndex(SplinePointPosition, PointIndex, ESplineCoordinateSpace::World, false);
// Get the up vector at the position to orient the aircraft
const CesiumGeospatial::Ellipsoid& Ellipsoid = CesiumGeospatial::Ellipsoid::WGS84;
glm::dvec3 upVector = Ellipsoid.geodeticSurfaceNormal(CesiumGeospatial::Cartographic(FMath::DegreesToRadians(PointLongitude), FMath::DegreesToRadians(PointLatitude), FMath::DegreesToRadians(PointHeight)));
// Compute the up vector at each point to correctly orient the plane
glm::dvec4 ecefUp(upVector, 0.0);
const glm::dmat4& ecefToUnreal = this->CesiumGeoreference->GetEllipsoidCenteredToUnrealWorldTransform();
glm::dvec4 unrealUp = ecefToUnreal * ecefUp;
this->SplineTrack->SetUpVectorAtSplinePoint(PointIndex, FVector(unrealUp.x, unrealUp.y, unrealUp.z), ESplineCoordinateSpace::World, false);
PointIndex++;
}
this->SplineTrack->UpdateSpline();
}
}
曲线轨迹
网友评论