1.创建飞机
参数帮助文档
var poitList = GetTracksData();
var waypointPropagator = new WaypointPropagator(m_earth, poitList);
var locationPoint = waypointPropagator.CreatePoint();m_aircraft = new Platform
{Name = "MH730",LocationPoint = locationPoint,OrientationAxes = new AxesVehicleVelocityLocalHorizontal(m_earth.FixedFrame, locationPoint),
};// Set the identifier for the aircraft in the CZML document.
m_aircraft.Extensions.Add(new IdentifierExtension("MH730"));// Hermite interpolation works better for aircraft-like vehicles.
m_aircraft.Extensions.Add(new CesiumPositionExtension
{InterpolationAlgorithm = CesiumInterpolationAlgorithm.Hermite
});// Configure a glTF model for the aircraft.
m_aircraft.Extensions.Add(new ModelGraphicsExtension(new ModelGraphics
{// Link to a binary glTF file.Model = new CesiumResource(GetModelUri("aircraft.glb"), CesiumResourceBehavior.LinkTo),// Flip the model visually to point Z in the correct direction.NodeTransformations = new Dictionary<string, NodeTransformationGraphics>{{"Aircraft", new NodeTransformationGraphics{Rotation = new UnitQuaternion(new ElementaryRotation(AxisIndicator.Third, Math.PI))}}},RunAnimations = false,
}));// Show the path of the aircraft.
m_aircraft.Extensions.Add(new PathGraphicsExtension(new PathGraphics
{Width = 2.0,LeadTime = Duration.FromHours(1.0).TotalSeconds,TrailTime = Duration.FromHours(1.0).TotalSeconds,Material = new PolylineOutlineMaterialGraphics{Color = Color.White,OutlineColor = Color.Black,OutlineWidth = 1.0,},
}));// Configure label for the aircraft.
m_aircraft.Extensions.Add(new LabelGraphicsExtension(new LabelGraphics
{Text = m_aircraft.Name,// Change label color over time.FillColor = new TimeIntervalCollection<Color>{// Green by default...TimeInterval.Infinite.AddData(Color.Red),// Red between first and second waypoints.//new TimeInterval<Color>(waypoint1.Date, waypoint2.Date, Color.Red),},// Only show label when camera is far enough from the aircraft,// to avoid visually clashing with the model.DistanceDisplayCondition = new Bounds(1000.0, double.MaxValue),
}));// Define a description for the aircraft which will be shown when selected in Cesium.
m_aircraft.Extensions.Add(new DescriptionExtension(new Description("Aircraft with two offset sensors")));
GetTracksData()函数是对自定义数据处理。其实就是经纬度。
2.飞机上也可以在添加传感器
// Create 30 degree simple conic sensor definition
var sensorCone = new ComplexConic();
sensorCone.SetHalfAngles(0.0, Trig.DegreesToRadians(15));
sensorCone.SetClockAngles(Trig.DegreesToRadians(20), Trig.DegreesToRadians(50));
sensorCone.Radius = double.PositiveInfinity;// Create a sensor pointing "forward".
// Position sensor underneath the wing.
var sensorOneLocationPoint = new PointFixedOffset(m_aircraft.ReferenceFrame, new Cartesian(-3.0, 8.0, 0.0));
var sensorAxesOne = new AxesAlignedConstrained(m_aircraft.OrientationAxes.GetVectorElement(CartesianElement.Z), AxisIndicator.Third,m_aircraft.OrientationAxes.GetVectorElement(CartesianElement.X), AxisIndicator.First);
// This rotation points the z-axis of the volume back along the x-axis of the ellipsoid.
var rotationOne = new UnitQuaternion(new ElementaryRotation(AxisIndicator.Second, Constants.HalfPi / 4));m_aircraftSensorOne = new Platform
{LocationPoint = sensorOneLocationPoint,OrientationAxes = new AxesFixedOffset(sensorAxesOne, rotationOne),
};// Set the identifier for the sensor in the CZML document.
m_aircraftSensorOne.Extensions.Add(new IdentifierExtension("AircraftSensorOne"));m_aircraftSensorOne.Extensions.Add(new CesiumPositionExtension
{InterpolationAlgorithm = CesiumInterpolationAlgorithm.Hermite
});// Define the sensor geometry.
m_aircraftSensorOne.Extensions.Add(new FieldOfViewExtension(sensorCone));// Configure graphical display of the sensor.
m_aircraftSensorOne.Extensions.Add(new FieldOfViewGraphicsExtension(new SensorFieldOfViewGraphics
{// Configure the outline of the projection onto the earth.EllipsoidSurfaceMaterial = new SolidColorMaterialGraphics(Color.White),IntersectionWidth = 2.0,LateralSurfaceMaterial = new GridMaterialGraphics{Color = Color.FromArgb(171, Color.Blue),},
}));// Create sensor pointing to the "side".
// Position sensor underneath the wing.
var sensorTwoLocationPoint = new PointFixedOffset(m_aircraft.ReferenceFrame, new Cartesian(-3.0, -8.0, 0.0));
var sensorAxesTwo = new AxesAlignedConstrained(m_aircraft.OrientationAxes.GetVectorElement(CartesianElement.Z), AxisIndicator.Third,m_aircraft.OrientationAxes.GetVectorElement(CartesianElement.Y), AxisIndicator.Second);// This rotation points the z-axis of the volume back along the x-axis of the ellipsoid.
var rotationTwo = new UnitQuaternion(new ElementaryRotation(AxisIndicator.First, Constants.HalfPi / 2));m_aircraftSensorTwo = new Platform
{LocationPoint = sensorTwoLocationPoint,OrientationAxes = new AxesFixedOffset(sensorAxesTwo, rotationTwo),
};// Set the identifier for the sensor in the CZML document.
m_aircraftSensorTwo.Extensions.Add(new IdentifierExtension("AircraftSensorTwo"));m_aircraftSensorTwo.Extensions.Add(new CesiumPositionExtension
{InterpolationAlgorithm = CesiumInterpolationAlgorithm.Hermite
});// Define the sensor geometry.
m_aircraftSensorTwo.Extensions.Add(new FieldOfViewExtension(sensorCone));// Configure graphical display of the sensor.
m_aircraftSensorTwo.Extensions.Add(new FieldOfViewGraphicsExtension(new SensorFieldOfViewGraphics
{// Configure the outline of the projection onto the earth.EllipsoidSurfaceMaterial = new SolidColorMaterialGraphics(Color.White),IntersectionWidth = 2.0,LateralSurfaceMaterial = new GridMaterialGraphics{Color = Color.FromArgb(171, Color.Red),},
}));
效果:
传感器
同理汽车也可以根据定义的轨迹运行