Inheritance: MonoBehaviour
Exemplo n.º 1
0
        public override object Clone()
        {
            var clone = (PlaceModel)MemberwiseClone();

            clone.Position = Position.CloneModel();
            clone.FlyTo    = FlyTo.CloneModel();
            return(clone);
        }
Exemplo n.º 2
0
        private void writeKML(string filename)
        {
            SharpKml.Dom.AltitudeMode altmode = SharpKml.Dom.AltitudeMode.Absolute;

            if (MainV2.cs.firmware == MainV2.Firmwares.ArduPlane)
            {
                altmode = SharpKml.Dom.AltitudeMode.Absolute;
            }
            else if (MainV2.cs.firmware == MainV2.Firmwares.ArduCopter2)
            {
                altmode = SharpKml.Dom.AltitudeMode.RelativeToGround;
            }

            Color[] colours = { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet, Color.Pink };

            Document kml = new Document();

            Tour tour = new Tour()
            {
                Name = "First Person View"
            };
            Playlist tourplaylist = new Playlist();

            AddNamespace(kml, "gx", "http://www.google.com/kml/ext/2.2");

            Style style = new Style();

            style.Id   = "yellowLineGreenPoly";
            style.Line = new LineStyle(new Color32(HexStringToColor("7f00ffff")), 4);



            PolygonStyle pstyle = new PolygonStyle();

            pstyle.Color  = new Color32(HexStringToColor("7f00ff00"));
            style.Polygon = pstyle;

            kml.AddStyle(style);

            Style stylet = new Style();

            stylet.Id = "track";
            SharpKml.Dom.IconStyle ico = new SharpKml.Dom.IconStyle();
            LabelStyle             lst = new LabelStyle();

            lst.Scale         = 0;
            stylet.Icon       = ico;
            ico.Icon          = new IconStyle.IconLink(new Uri("http://earth.google.com/images/kml-icons/track-directional/track-none.png"));
            stylet.Icon.Scale = 0.5;
            stylet.Label      = lst;

            kml.AddStyle(stylet);

            // create sub folders
            Folder planes = new Folder();

            planes.Name = "Planes";
            kml.AddFeature(planes);

            Folder points = new Folder();

            points.Name = "Points";
            kml.AddFeature(points);


            // coords for line string
            CoordinateCollection coords = new CoordinateCollection();

            int      a          = 1;
            int      c          = -1;
            DateTime lasttime   = DateTime.MaxValue;
            DateTime starttime  = DateTime.MinValue;
            Color    stylecolor = Color.AliceBlue;
            string   mode       = "";

            if (flightdata.Count > 0)
            {
                mode = flightdata[0].mode;
            }
            foreach (CurrentState cs in flightdata)
            {
                progressBar1.Value = 50 + (int)((float)a / (float)flightdata.Count * 100.0f / 2.0f);
                progressBar1.Refresh();

                if (starttime == DateTime.MinValue)
                {
                    starttime = cs.datetime;
                    lasttime  = cs.datetime;
                }

                if (mode != cs.mode || flightdata.Count == a)
                {
                    c++;

                    LineString ls = new LineString();
                    ls.AltitudeMode = altmode;
                    ls.Extrude      = true;

                    ls.Coordinates = coords;

                    Placemark pm = new Placemark();

                    pm.Name     = c + " Flight Path " + mode;
                    pm.StyleUrl = new Uri("#yellowLineGreenPoly", UriKind.Relative);
                    pm.Geometry = ls;

                    SharpKml.Dom.TimeSpan ts = new SharpKml.Dom.TimeSpan();
                    ts.Begin = starttime;
                    ts.End   = cs.datetime;

                    pm.Time = ts;

                    // setup for next line
                    mode      = cs.mode;
                    starttime = cs.datetime;

                    stylecolor = colours[c % (colours.Length - 1)];

                    Style style2 = new Style();
                    style2.Line = new LineStyle(new Color32(stylecolor), 4);

                    pm.StyleSelector = style2;

                    kml.AddFeature(pm);

                    coords = new CoordinateCollection();
                }

                coords.Add(new Vector(cs.lat, cs.lng, cs.alt));

                SharpKml.Dom.Timestamp tstamp = new SharpKml.Dom.Timestamp();
                tstamp.When = cs.datetime;

                FlyTo flyto = new FlyTo();

                flyto.Duration = (cs.datetime - lasttime).TotalMilliseconds / 1000.0;

                flyto.Mode = FlyToMode.Smooth;
                SharpKml.Dom.Camera cam = new SharpKml.Dom.Camera();
                cam.AltitudeMode = altmode;
                cam.Latitude     = cs.lat;
                cam.Longitude    = cs.lng;
                cam.Altitude     = cs.alt;
                cam.Heading      = cs.yaw;
                cam.Roll         = -cs.roll;
                cam.Tilt         = (90 - (cs.pitch * -1));

                cam.GXTimePrimitive = tstamp;

                flyto.View = cam;
                //if (Math.Abs(flyto.Duration.Value) > 0.1)
                {
                    tourplaylist.AddTourPrimitive(flyto);
                    lasttime = cs.datetime;
                }


                Placemark pmplane = new Placemark();
                pmplane.Name = "Point " + a;



                pmplane.Time = tstamp;

                pmplane.Visibility = false;

                SharpKml.Dom.Location loc = new SharpKml.Dom.Location();
                loc.Latitude  = cs.lat;
                loc.Longitude = cs.lng;
                loc.Altitude  = cs.alt;

                if (loc.Altitude < 0)
                {
                    loc.Altitude = 0.01;
                }

                SharpKml.Dom.Orientation ori = new SharpKml.Dom.Orientation();
                ori.Heading = cs.yaw;
                ori.Roll    = -cs.roll;
                ori.Tilt    = -cs.pitch;

                SharpKml.Dom.Scale sca = new SharpKml.Dom.Scale();

                sca.X = 2;
                sca.Y = 2;
                sca.Z = 2;

                Model model = new Model();
                model.Location     = loc;
                model.Orientation  = ori;
                model.AltitudeMode = altmode;
                model.Scale        = sca;

                try
                {
                    Description desc = new Description();
                    desc.Text = @"<![CDATA[
              <table>
                <tr><td>Roll: " + model.Orientation.Roll.Value.ToString("0.00") + @" </td></tr>
                <tr><td>Pitch: " + model.Orientation.Tilt.Value.ToString("0.00") + @" </td></tr>
                <tr><td>Yaw: " + model.Orientation.Heading.Value.ToString("0.00") + @" </td></tr>
                <tr><td>Time: " + cs.datetime.ToString("HH:mm:sszzzzzz") + @" </td></tr>
              </table> ";
//            ]]>";

                    pmplane.Description = desc;
                }
                catch { }

                Link link = new Link();
                link.Href = new Uri("block_plane_0.dae", UriKind.Relative);

                model.Link = link;

                pmplane.Geometry = model;

                planes.AddFeature(pmplane);

                ///

                Placemark pmt = new Placemark();

                SharpKml.Dom.Point pnt = new SharpKml.Dom.Point();
                pnt.AltitudeMode = altmode;
                pnt.Coordinate   = new Vector(cs.lat, cs.lng, cs.alt);

                pmt.Name = "" + a;

                pmt.Description = pmplane.Description;

                pmt.Time = tstamp;

                pmt.Geometry = pnt;
                pmt.StyleUrl = new Uri("#track", UriKind.Relative);

                points.AddFeature(pmt);

                a++;
            }

            tour.Playlist = tourplaylist;

            kml.AddFeature(tour);

            Serializer serializer = new Serializer();

            serializer.Serialize(kml);


            //Console.WriteLine(serializer.Xml);

            StreamWriter sw = new StreamWriter(filename);

            sw.Write(serializer.Xml);
            sw.Close();

            // create kmz - aka zip file

            FileStream      fs        = File.Open(filename.Replace(Path.GetExtension(filename), ".kmz"), FileMode.Create);
            ZipOutputStream zipStream = new ZipOutputStream(fs);

            zipStream.SetLevel(9);             //0-9, 9 being the highest level of compression
            zipStream.UseZip64 = UseZip64.Off; // older zipfile

            // entry 1
            string   entryName = ZipEntry.CleanName(Path.GetFileName(filename)); // Removes drive from name and fixes slash direction
            ZipEntry newEntry  = new ZipEntry(entryName);

            newEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(newEntry);

            // Zip the file in buffered chunks
            // the "using" will close the stream even if an exception occurs
            byte[] buffer = new byte[4096];
            using (FileStream streamReader = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                StreamUtils.Copy(streamReader, zipStream, buffer);
            }
            zipStream.CloseEntry();

            filename = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "block_plane_0.dae";

            // entry 2
            entryName         = ZipEntry.CleanName(Path.GetFileName(filename)); // Removes drive from name and fixes slash direction
            newEntry          = new ZipEntry(entryName);
            newEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(newEntry);

            // Zip the file in buffered chunks
            // the "using" will close the stream even if an exception occurs
            buffer = new byte[4096];
            using (FileStream streamReader = File.OpenRead(filename))
            {
                StreamUtils.Copy(streamReader, zipStream, buffer);
            }
            zipStream.CloseEntry();


            zipStream.IsStreamOwner = true;     // Makes the Close also Close the underlying stream
            zipStream.Close();

            flightdata.Clear();
        }
Exemplo n.º 3
0
        public static int Generate(string whereClause, string filename, bool isMyRandotrips)
        {
            try
            {
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
                builder.DataSource     = Consts.DB_SERVER;
                builder.UserID         = Consts.DB_USER;
                builder.Password       = Consts.DB_PASSWORD;
                builder.InitialCatalog = Consts.DB_NAME;

                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    StringBuilder ssb = new StringBuilder();
                    ssb.Append("SELECT point_type,intent_set,what_3_words,text,photos,short_hash_id,latitude,longitude,final_bearing,power,z_score,nearest_place,country,datetime FROM ");
                    //                      0          1           2        3     4        5            6         7          8          9      10       11          12
#if RELEASE_PROD
                    ssb.Append("reports");
#else
                    ssb.Append("reports");
                    //ssb.Append("reports_dev");
#endif
                    ssb.Append($" WHERE VISITED = '1' {whereClause} ORDER BY DATETIME ASC;");
                    Console.WriteLine("SQL:" + ssb.ToString());

                    List <FlyTo> flytos = new List <FlyTo>();
                    List <Point> points = new List <Point>();

                    using (SqlCommand sqlCommand = new SqlCommand(ssb.ToString(), connection))
                    {
                        using (SqlDataReader reader = sqlCommand.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var flyto = new FlyTo();
                                var point = new Point();

                                // latitude
                                if (!reader.IsDBNull(6))
                                {
                                    flyto.latitude = point.latitude = reader.GetDouble(6);
                                }
                                // longitude
                                if (!reader.IsDBNull(7))
                                {
                                    flyto.longitude = point.longitude = reader.GetDouble(7);
                                }
                                // bearing
                                if (!reader.IsDBNull(8))
                                {
                                    flyto.final_bearing = reader.GetDouble(8);
                                }
                                if (flyto.final_bearing < 0)
                                {
                                    flyto.final_bearing = (flyto.final_bearing + 360) % 360;
                                }

                                if (!reader.IsDBNull(0))
                                {
                                    point.point_type = reader.GetString(0);
                                }
                                if (!reader.IsDBNull(1))
                                {
                                    point.intent_set = reader.GetString(1);
                                }
                                if (!reader.IsDBNull(2))
                                {
                                    point.what_3_words = reader.GetString(2);
                                }
                                if (!reader.IsDBNull(3))
                                {
                                    point.report = reader.GetString(3);
                                }
                                if (!reader.IsDBNull(4))
                                {
                                    point.photos = reader.GetString(4);
                                }
                                if (!reader.IsDBNull(5))
                                {
                                    point.short_hash_id = reader.GetString(5);
                                }
                                if (!reader.IsDBNull(9))
                                {
                                    point.power = reader.GetDouble(9);
                                }
                                if (!reader.IsDBNull(10))
                                {
                                    point.z_score = reader.GetDouble(10);
                                }
                                if (!reader.IsDBNull(11))
                                {
                                    point.nearest_place = reader.GetString(11);
                                }
                                if (!reader.IsDBNull(12))
                                {
                                    point.country = reader.GetString(12);
                                }
                                if (!reader.IsDBNull(13))
                                {
                                    point.datetime = reader.GetDateTime(13);
                                }

                                flytos.Add(flyto);
                                points.Add(point);
                            }
                        }
                    }

                    var flyTosAppender = new StringBuilder();
                    int pointNo        = 1;
                    foreach (FlyTo flyto in flytos)
                    {
                        var var3 = (flyto.final_bearing + 360) % 360;
                        var var4 = (flyto.final_bearing + 360) % 360;
                        var var5 = (flyto.final_bearing + 360 + 90) % 360;
                        var var6 = (flyto.final_bearing + 360 + 180) % 360;
                        var var7 = (flyto.final_bearing + 360 + 270) % 360;
                        var var8 = (flyto.final_bearing + 360) % 360;
                        flyTosAppender.Append(string.Format(FLYTO_TEMPLATE, flyto.latitude, flyto.longitude, $"point{pointNo++}", var3, var4, var5, var6, var7, var8));
                    }

                    var pointsAppender = new StringBuilder();
                    pointNo = 1; // reset
                    foreach (Point point in points)
                    {
                        // Format content to show inside the balloon popup
                        var balloonString = new StringBuilder();
                        balloonString.Append("<![CDATA[");
                        if (!string.IsNullOrEmpty(point.nearest_place))
                        {
                            balloonString.Append($"in {point.nearest_place}, {point.country}<br>");
                        }
                        balloonString.Append($"@{point.latitude.ToString("G6")},{point.longitude.ToString("G6")} ({point.what_3_words})<br>");
                        balloonString.Append($"Power: {point.power.ToString("G3")}<br>");
                        balloonString.Append($"z-score: {point.z_score.ToString("G3")}<br>");
                        if (!string.IsNullOrEmpty(point.intent_set))
                        {
                            balloonString.Append($"Intent: {point.intent_set}<br>");
                        }
                        if (!string.IsNullOrEmpty(point.report))
                        {
                            balloonString.Append($"Report: {point.report}<br>");
                        }
                        if (!string.IsNullOrEmpty(point.photos))
                        {
                            var photos = point.photos.Split(",");
                            int i      = 0;
                            foreach (string url in photos)
                            {
                                balloonString.Append($"<a href=\"{url}\">photo {++i}</a> ");
                            }
                            balloonString.Append("<br>");
                        }
                        balloonString.Append($"{point.short_hash_id}<br>");
                        balloonString.Append("]]>");

                        var dateTimeStr = "";
                        if (isMyRandotrips)
                        {
                            // TODO: one day figure out how to show My Randotrips in user's local timezone
                            dateTimeStr = $"{point.point_type} {point.datetime.ToString("yyyy-MM-dd HH':'mm")} UTC";
                        }
                        else
                        {
                            dateTimeStr = $"{point.point_type} {point.datetime.ToString("yyyy-MM-dd HH':'mm")} UTC";
                        }

                        var formatted = string.Format(POINT_TEMPLATE,
                                                      $"point{pointNo++}",
                                                      dateTimeStr,
                                                      balloonString.ToString(),
                                                      point.longitude,
                                                      point.latitude
                                                      );

                        pointsAppender.Append(formatted);
                    }

                    var output = string.Format(MAIN_TEMPLATE, filename.Replace(".kml", "").Replace("randotrips_", ""), flyTosAppender, pointsAppender);
                    System.IO.File.WriteAllText($"wwwroot/flythrus/{filename}", output);
                    return(pointNo);
                }
            }
            catch (Exception e)
            {
                // My error handling is getting lazy
                Console.Write(e);
                return(-1);
            }
        }
Exemplo n.º 4
0
    private IEnumerator StartLevel(bool train)
    {
        Play plays = play.GetComponent <Play> ();

        plays.level = level;

        GameObject titleClone = GameObject.Instantiate(title.gameObject);

        titleClone.transform.parent     = play.transform;
        titleClone.transform.position   = title.gameObject.transform.position;
        titleClone.transform.rotation   = title.gameObject.transform.rotation;
        titleClone.transform.localScale = title.transform.lossyScale;

        plays.floatingTitle = titleClone;

        title.gameObject.SetActive(false);

        FlyTo ft = titleClone.AddComponent <FlyTo> ();

        ft.destination      = playTitle.transform;
        ft.destinationColor = Color.white;
        ft.destinationScale = new Vector3(1.5f, 1.5f, 1.5f);

        ParticleSystem.EmissionModule emission = titleClone.GetComponent <ParticleSystem> ().emission;
        emission.enabled = true;


        int i = 0;

        foreach (var e in level.exercises)
        {
            yield return(new WaitForSeconds(0.25f));

            GameObject destination = GameObject.Instantiate(exPrefab);
            destination.transform.parent        = playExercises.transform;
            destination.transform.localPosition = new Vector3(0, 0, 0);
            destination.transform.localRotation = Quaternion.Euler(0, 0, 0);
            destination.transform.localScale    = new Vector3(1, 1, 1);


            GameObject exerciseGO         = exercisesPanel.transform.GetChild(i).gameObject;
            GameObject exerciseTitleClone = GameObject.Instantiate(exerciseGO);
            exerciseTitleClone.transform.parent     = play.transform;
            exerciseTitleClone.transform.position   = exerciseGO.gameObject.transform.position;
            exerciseTitleClone.transform.rotation   = exerciseGO.gameObject.transform.rotation;
            exerciseTitleClone.transform.localScale = exerciseGO.transform.lossyScale;
            exerciseTitleClone.GetComponent <RectTransform>().sizeDelta = new Vector2(100, 100);

            plays.floatingExercises.Add(e, exerciseTitleClone);

            exerciseGO.GetComponent <Text>().enabled = (false);

            FlyTo fly = exerciseTitleClone.AddComponent <FlyTo>();
            fly.destination      = destination.transform;
            fly.destinationColor = Color.white;
            fly.destinationScale = new Vector3(1.5f, 1.5f, 1.5f);

            // ParticleSystem.EmissionModule emission = titleClone.GetComponent<ParticleSystem>().emission;
            // emission.enabled = true;
            i++;
        }


        yield return(new WaitForSeconds(1f));

        menu.setMenu(4);
        yield return(new WaitForSeconds(3f));

        if (train)
        {
            plays.StartTraining();
        }
        else
        {
            plays.StartExam();
        }
    }
Exemplo n.º 5
0
    private IEnumerator StartPlay()
    {
        foreach (var e in level.exercises)
        {
            FlyTo     ft          = null;
            Transform exercisePos = null;
            try{
                GameObject floatingExercise = floatingExercises [e];

                ft          = floatingExercise.GetComponent <FlyTo> ();
                exercisePos = ft.destination;

                ft.destination = center;
            }catch (System.Exception) { return(false); }
            yield return(new WaitForSeconds(2f));

            try{
                if (aborted)
                {
                    return(false);
                }

                tutorial.gesture = e;

                if (training)
                {
                    tutorial.playing = true;
                    tutorial.GetComponent <Animator> ().SetBool("Show", true);
                }

                tutorial.UpdateGesture();
            }catch (System.Exception) { return(false); }

            yield return(new WaitForSeconds(1f));

            if (aborted)
            {
                return(false);
            }
            try{
                trainer.Clean();
                trainer.loadFromFrames(e.exerciseName, tutorial.GetFrames(), false);

                trainer.paused = false;
            }catch (System.Exception) { return(false); }

            yield return(new WaitUntil(() => maxScore > 0.3f));

            if (aborted)
            {
                return(false);
            }

            try{
                trainer.paused = true;

                if (!training && maxScore > e.score)
                {
                    e.score = maxScore;
                }

                // Save score
                // Give feedback

                totalScore += maxScore;
                maxScore    = 0;

                ft.destination      = exercisePos;
                ft.destinationColor = Color.green;

                tutorial.GetComponent <Animator> ().SetBool("Show", false);
            }catch (System.Exception) { return(false); }
        }

        yield return(new WaitForSeconds(2f));

        tutorial.playing = false;

        try{
            if (!training)
            {
                yay.PlayDelayed(.5f);
                float score = 0;
                foreach (var e in level.exercises)
                {
                    score += e.score;
                }
                score /= (level.exercises.Length * 1f);
                if (score > level.score)
                {
                    level.score = score;
                }

                exam.level = level;
                exam.GetComponent <Animator> ().SetBool("Show", true);
            }
            else
            {
                menu.Menu = 3;
                Abort();
            }
        }catch (UnityException) {}
    }
Exemplo n.º 6
0
 public HotSpot(Vector3 coord, int radius, FlyTo flyTo)
 {
     Coord  = coord;
     Radius = radius;
     FlyTo  = flyTo;
 }