/// <summary> /// Create a Platform for the requested satellite using a TLE for position. /// The satellite will be visually represented by a labeled glTF model, /// the satellite's orbit will be shown, and vectors will be drawn for /// the body axes of the satellite, plus a vector indicating the direction /// of the sun. /// </summary> private void CreateSatellite() { // Get the current TLE for the given satellite identifier. var tleList = TwoLineElementSetHelper.GetTles(m_satelliteIdentifier, JulianDate.Now); // Use the epoch of the first TLE, since the TLE may have been loaded from offline data. m_epoch = tleList[0].Epoch; // Propagate the TLE and use that as the satellite's location point. var locationPoint = new Sgp4Propagator(tleList).CreatePoint(); m_satellite = new Platform { Name = "Satellite " + m_satelliteIdentifier, LocationPoint = locationPoint, // Orient the satellite using Vehicle Velocity Local Horizontal (VVLH) axes. OrientationAxes = new AxesVehicleVelocityLocalHorizontal(m_earth.FixedFrame, locationPoint), }; // Set the identifier for the satellite in the CZML document. m_satellite.Extensions.Add(new IdentifierExtension(m_satelliteIdentifier)); // Configure a glTF model for the satellite. m_satellite.Extensions.Add(new ModelGraphicsExtension(new ModelGraphics { // Link to a binary glTF file. Model = new CesiumResource(GetModelUri("satellite.glb"), CesiumResourceBehavior.LinkTo), // By default, Cesium plays all animations in the model simultaneously, which is not desirable. RunAnimations = false, })); // Configure a label for the satellite. m_satellite.Extensions.Add(new LabelGraphicsExtension(new LabelGraphics { // Use the name of the satellite as the text of the label. Text = m_satellite.Name, // Change the color of the label after 12 hours. This demonstrates specifying that // a value varies over time using intervals. FillColor = new TimeIntervalCollection <Color> { // Green for the first half day... new TimeInterval <Color>(JulianDate.MinValue, m_epoch.AddDays(0.5), Color.Green, true, false), // Red thereafter. new TimeInterval <Color>(m_epoch.AddDays(0.5), JulianDate.MaxValue, Color.Red, false, true), }, // Only show label when camera is far enough from the satellite, // to avoid visually clashing with the model. DistanceDisplayCondition = new Bounds(1000.0, double.MaxValue), })); // Configure graphical display of the orbital path of the satellite. m_satellite.Extensions.Add(new PathGraphicsExtension(new PathGraphics { // Configure the visual appearance of the line. Material = new PolylineOutlineMaterialGraphics { Color = Color.White, OutlineWidth = 1.0, OutlineColor = Color.Black, }, Width = 2.0, // Lead and Trail time indicate how much of the path to render. LeadTime = Duration.FromMinutes(44.0).TotalSeconds, TrailTime = Duration.FromMinutes(44.0).TotalSeconds, })); // Create vectors for the X, Y, and Z axes of the satellite. m_satelliteXAxis = CreateAxesVector(m_satellite, CartesianElement.X, Color.Green, "SatelliteX"); m_satelliteYAxis = CreateAxesVector(m_satellite, CartesianElement.Y, Color.Red, "SatelliteY"); m_satelliteZAxis = CreateAxesVector(m_satellite, CartesianElement.Z, Color.Blue, "SatelliteZ"); // Create a vector from the satellite to the Sun. // Compute the vector from the satellite's location to the Sun's center of mass. var sunCenterOfMassPoint = CentralBodiesFacet.GetFromContext().Sun.CenterOfMassPoint; var vectorSatelliteToSun = new VectorTrueDisplacement(m_satellite.LocationPoint, sunCenterOfMassPoint); // Create the visual vector. m_satelliteSunVector = new GraphicalVector { LocationPoint = m_satellite.LocationPoint, Vector = vectorSatelliteToSun, VectorGraphics = new VectorGraphics { Length = 5.0, Color = Color.Yellow, }, }; // Set the identifier for the vector in the CZML document. m_satelliteSunVector.Extensions.Add(new IdentifierExtension("SunVector")); // Orient the solar panels on the satellite model to point at the sun. var satelliteYVector = m_satellite.OrientationAxes.GetVectorElement(CartesianElement.Y); // allow only Z axis to rotate to follow sun vector. Constrain sun vector to Y, and satellite Y vector to X. var constrainedAxes = new AxesAlignedConstrained(satelliteYVector, AxisIndicator.First, vectorSatelliteToSun, AxisIndicator.Second); // Satellite axes are Vehicle Velocity Local Horizontal (VVLH) axes, where X is forward and Z is down, // but Cesium model axes are Z forward, Y up. So, create an axes rotates to the Cesium model axes. var offset = new UnitQuaternion(new ElementaryRotation(AxisIndicator.First, -Math.PI / 2)) * new UnitQuaternion(new ElementaryRotation(AxisIndicator.Third, Math.PI / 2)); var cesiumModelAxes = new AxesFixedOffset(m_satellite.OrientationAxes, offset); // The rotation will be from the Cesium model axes to the constrained axes. var solarPanelRotationAxes = new AxesInAxes(constrainedAxes, cesiumModelAxes); // Add a node transformation to rotate the SolarPanels node of the model. m_satellite.Extensions.GetByType <ModelGraphicsExtension>().ModelGraphics.NodeTransformations = new Dictionary <string, NodeTransformationGraphics> { { "SolarPanels", new NodeTransformationGraphics { Rotation = new AxesCesiumProperty(solarPanelRotationAxes) } } }; }
/// <summary> /// Create another ground facility with a sensor dome, and a rotating sensor inside the dome. /// </summary> private void CreateSensorDome() { // Define the location of the facility using cartographic coordinates. var locationPoint = new PointCartographic(m_earth, new Cartographic(Trig.DegreesToRadians(-122.3), Trig.DegreesToRadians(46), 456.359)); m_sensorDome = new Platform { Name = "Sensor Dome", LocationPoint = locationPoint, OrientationAxes = new AxesEastNorthUp(m_earth, locationPoint), }; // Set the identifier for the facility in the CZML document. m_sensorDome.Extensions.Add(new IdentifierExtension("SensorDome")); // Define the sensor geometry. var dome = new ComplexConic(); dome.SetHalfAngles(0.0, Math.PI); dome.SetClockAngles(0.0, Math.PI * 2); dome.Radius = 10000.0; m_sensorDome.Extensions.Add(new FieldOfViewExtension(dome)); // Configure graphical display of the sensor dome. m_sensorDome.Extensions.Add(new FieldOfViewGraphicsExtension(new SensorFieldOfViewGraphics { DomeSurfaceMaterial = new GridMaterialGraphics { Color = Color.White, CellAlpha = 0.1, }, })); // Define a rotating axes. var rotatingAxes = new AxesLinearRate { ReferenceAxes = new AxesEastNorthUp(m_earth, locationPoint), ReferenceEpoch = m_epoch, InitialRotation = UnitQuaternion.Identity, SpinAxis = UnitCartesian.UnitZ, InitialRotationalVelocity = Trig.DegreesToRadians(5.0), // 5 degrees per second RotationalAcceleration = 0.0, }; // Define a rotation around X. UnitQuaternion quaternion = new UnitQuaternion(new AngleAxisRotation(Math.PI / 3.0, UnitCartesian.UnitX)); // Define an angular offset for the rotating axes. var rotatedOffsetAxes = new AxesFixedOffset(rotatingAxes, quaternion); m_rotatingSensor = new Platform { Name = "Rotating Sensor", LocationPoint = locationPoint, OrientationAxes = rotatedOffsetAxes }; // Set the identifier for the sensor in the CZML document. m_rotatingSensor.Extensions.Add(new IdentifierExtension("RotatingSensor")); // Define the sensor geometry. m_rotatingSensor.Extensions.Add(new FieldOfViewExtension(new RectangularPyramid { XHalfAngle = Trig.DegreesToRadians(30), YHalfAngle = Trig.DegreesToRadians(30), Radius = 10000.0, })); // Configure graphical display of the sensor. m_rotatingSensor.Extensions.Add(new FieldOfViewGraphicsExtension(new SensorFieldOfViewGraphics { DomeSurfaceMaterial = new GridMaterialGraphics { Color = Color.Green, CellAlpha = 0.5, }, LateralSurfaceMaterial = new GridMaterialGraphics { Color = Color.Pink, CellAlpha = 0.5, }, IntersectionColor = Color.White, ShowIntersection = true, ShowEllipsoidHorizonSurfaces = true, })); }