private Tuple <float?, Motion <Cartesian> > GenerateStageFrameData(Profiledata arg)
        {
            //var baseCartesian = manager.GetReferenceCartesian();
            var baseCartesian = CesiumDataManager.GetBaseCartesian();
            //var unitVector = baseCartesian.Normalize();
            var ellipsoid = Ellipsoid.Wgs84;

            var unitVector = ellipsoid.GeodeticSurfaceNormal(baseCartesian);
            // add altitude to the vector
            var altVector =
                baseCartesian.Add(new Cartesian(arg.altitude.Value * 1000.0 * unitVector.X, arg.altitude.Value * 1000.0 * unitVector.Y,
                                                arg.altitude.Value * 1000.0 * unitVector.Z));

            // add downrange to the vector

            var drVector = altVector.Add(new Cartesian((arg.actualdownrange.Value * 1000.0 * unitVector.X), 0, 0));

            var altitude  = (arg.altitude * 1000.0 * (unitVector.Z)) + baseCartesian.Z;
            var downRange = (arg.actualdownrange * 1000.0 * unitVector.X) + baseCartesian.X;
            //var latitude = arg.downrange*1000.0*unitVector.Y + baseCartesian.Y;
            var time           = arg.time;
            var deltaAlt       = arg.dalt;
            var deltaDownRange = arg.ddrange;


            if (altitude != null)
            {
                if (downRange != null)
                {
                    //var motion = new Motion<Cartesian>(new Cartesian(downRange.Value, baseCartesian.Y, altitude.Value),
                    //    new Cartesian(deltaDownRange, 0, deltaAlt));
                    manager.GenerateReferenceCartesian(baseCartesian, arg);
                    var currentCartesian = new Cartesian(downRange.Value, baseCartesian.Y, altitude.Value);
                    var scaledCartesian  = ellipsoid.ScaleToGeodeticSurface(currentCartesian);


                    var normal             = scaledCartesian.Normalize();
                    var newScaledCartesian = scaledCartesian.Add(new Cartesian(0, 0, ((arg.altitude * 1000.0 * normal.Z)).Value));

                    var motion = new Motion <Cartesian>(drVector,
                                                        new Cartesian(deltaDownRange, 0, deltaAlt));

                    var tuple = new Tuple <float?, Motion <Cartesian> >(time, motion);
                    return(tuple);
                }
            }
            throw new NullReferenceException();
        }
Exemplo n.º 2
0
        // convert the distance of the downrange into a distance from the launch site, at a specific trajectory



        /// <summary>
        /// This handles the HTTP request by writing some example CZML into the response.
        /// </summary>
        /// <param name="context">The current HttpContext</param>
        public void ProcessRequest(HttpContext context)
        {
            // A more complex example could examine context.Request here for
            // inputs coming from the client-side application.

            // Set the response type for CZML, which is JSON.
            context.Response.ContentType = "application/json";

            // Create an output stream writer for the response.
            using (var outputStream = new StreamWriter(context.Response.OutputStream))
            {
                var cesiumWriter = new CesiumStreamWriter();
                var output       = new CesiumOutputStream(outputStream);

                // Since this is a demo, turning on PrettyFormatting makes the response easier to view
                // with web browser developer tools.  It just adds whitespace and newlines to the response,
                // so production environments would typically leave this turned off.
                output.PrettyFormatting = true;

                // The whole body of CZML must be wrapped in a JSON array, opened here.
                output.WriteStartSequence();

                // The first packet (JSON object) of CZML must be the document packet.
                using (var entity = cesiumWriter.OpenPacket(output))
                {
                    entity.WriteId("document");
                    entity.WriteVersion("1.0");
                }

                using (var entity = cesiumWriter.OpenPacket(output))
                {
                    entity.WriteId("canavitem");
                    using (var pos = entity.OpenPositionProperty())
                    {
                        pos.WriteCartesian(CesiumDataManager.GetBaseCartesian());
                    }
                    using (var point = entity.OpenPointProperty())
                    {
                        point.WriteColorProperty(Color.Aqua);
                        point.WritePixelSizeProperty(10.0);
                    }
                }

                rocketData = new RocketTrajectoryData();

                var entities = rocketData.GetStandardRocketTrajectoryData();


                var cartList = new List <Cartesian>();
                var dateList = new List <JulianDate>();

                var now = DateTime.Now;

                for (int i = 0; i < entities.data[2].x.Count; i++)
                {
                    var cartesian = CesiumDataManager.GenerateCartesian(entities.data[2].x[i], entities.data[2].y[i]);
                    cartList.Add(cartesian);
                    var julDate = new JulianDate(now + TimeSpan.FromSeconds(i * 2));
                    dateList.Add(julDate);
                }

                using (var thisEntity = cesiumWriter.OpenPacket(output))
                {
                    thisEntity.WriteId("testpath");
                    thisEntity.WriteDescriptionProperty("rocket launch path");
                    using (var position = thisEntity.OpenPositionProperty())
                    {
                        position.WriteCartesian(dateList, cartList);
                        position.WriteReferenceFrame("#referenceitem");
                    }

                    //using (var model = thisEntity.OpenModelProperty())
                    //{
                    //    model.WriteGltfProperty(new Uri("http://localhost:56332/Models/CesiumAir/Cesium_Air.gltf"),CesiumResourceBehavior.Embed);
                    //}

                    using (var path = thisEntity.OpenPathProperty())
                    {
                        using (var material = path.OpenMaterialProperty())
                        {
                            using (var outline = material.OpenSolidColorProperty())
                            {
                                using (var colour = outline.OpenColorProperty())
                                {
                                    colour.WriteRgba(Color.DarkSeaGreen);
                                }
                            }
                        }
                        path.WriteWidthProperty(8);
                        path.WriteLeadTimeProperty(10);
                        path.WriteTrailTimeProperty(1000);
                        path.WriteResolutionProperty(5);
                    }
                }



                // Close the JSON array that wraps the entire CZML document.
                output.WriteEndSequence();
            }
        }