Exemple #1
0
    public void removeLine()
    {
        point1active = false;
        point2active = false;
        PlaybackControl pc = GameObject.Find("PlaybackControl").GetComponent <PlaybackControl> ();

        VectorLine.Destroy(ref myLine);
        pc.drawLine   = false;
        lineCrossed   = 0;
        crossingSpeed = 0.0f;

        crossings = new List <decimal> ();

        InfoText it = GameObject.Find("InfoText").GetComponent <InfoText> ();

        if (it.diagram)
        {
            it.removeDiagram();
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (point1active && !point2active)
        {
            RaycastHit hit;
            Ray        ray = GameObject.Find("Flycam").camera.ScreenPointToRay(Input.mousePosition);
            if (collider.Raycast(ray, out hit, Mathf.Infinity))
            {
                VectorLine.Destroy(ref myLine_tmp);
                VectorLine.SetCamera(GameObject.Find("Flycam").camera);
                myLine_tmp           = VectorLine.SetLine3D(Color.red, new Vector3[] { point1, hit.point });
                myLine_tmp.lineWidth = 3.0f;

                InfoText it = GameObject.Find("InfoText").GetComponent <InfoText> ();
                if (it.diagram)
                {
                    it.removeDiagram();
                }
            }
        }
        else
        {
            VectorLine.Destroy(ref myLine_tmp);
            if (point1active && point2active)
            {
                PlaybackControl pc = GameObject.Find("PlaybackControl").GetComponent <PlaybackControl> ();
                for (int i = 0; i < crossings.Count; i++)
                {
                    if (crossings[i] < pc.current_time - 1)
                    {
                        crossings.RemoveAt(i);
                    }
                }
            }
        }
    }
    void OnGUI()
    {
        playing      = GUI.Toggle(new Rect(30, 25, 100, 30), playing, " PLAY");
        current_time = (decimal)GUI.HorizontalSlider(new Rect(100, 30, 400, 30), (float)current_time, 0.0f, (float)total_time);

        string btnText = "show trajectories";

        if (trajectoriesShown)
        {
            btnText = "hide trajectories";
        }

        if (GUI.Button(new Rect(510, 20, 120, 30), btnText))
        {
            PedestrianLoader pl = GameObject.Find("PedestrianLoader").GetComponent <PedestrianLoader>();
            if (trajectoriesShown)
            {
                foreach (GameObject p in pl.pedestirans)
                {
                    p.GetComponent <Pedestrian>().hideTrajectory();
                }
                trajectoriesShown = false;
            }
            else
            {
                foreach (GameObject p in pl.pedestirans)
                {
                    p.GetComponent <Pedestrian>().showTrajectory();
                }
                trajectoriesShown = true;
            }
        }



        GeometryLoader gl = GameObject.Find("GeometryLoader").GetComponent <GeometryLoader> ();
        Groundplane    gp = gl.groundplane;

        btnText = "add line";
        if (drawLine)
        {
            GUI.color = Color.red;
        }
        if (lineIsDrawn)
        {
            btnText = "remove line";
        }

        if (GUI.Button(new Rect(640, 20, 80, 30), btnText))
        {
            if (lineIsDrawn)
            {
                gp.removeLine();
                drawLine    = false;
                lineIsDrawn = false;
            }
            else
            {
                drawLine = !drawLine;
                if (!drawLine)
                {
                    gp.removeLine();
                }
            }
        }
        GUI.color = Color.white;

        if (tiles == 0)
        {
            btnText = "colors by speed";
        }
        if (tiles == 1)
        {
            btnText = "colors by density";
        }
        if (tiles == 2)
        {
            btnText = "hide colors";
        }

        if (GUI.Button(new Rect(730, 20, 120, 30), btnText))
        {
            tiles = (tiles + 1) % 3;

            InfoText it = GameObject.Find("InfoText").GetComponent <InfoText> ();
            if (it.diagram)
            {
                it.removeDiagram();
            }

            if (tiles == 0)
            {
                tileColoringMode = TileColoringMode.TileColoringNone;
            }
            if (tiles == 1)
            {
                tileColoringMode = TileColoringMode.TileColoringSpeed;
            }
            if (tiles == 2)
            {
                tileColoringMode = TileColoringMode.TileColoringDensity;
            }
        }

        if (tileColoringMode == TileColoringMode.TileColoringDensity)
        {
            threshold = GUI.HorizontalSlider(new Rect(730, 55, 120, 30), threshold, 0.0f, 6.0f);
            GUI.Label(new Rect(730, 70, 120, 30), "Threshold: " + System.Math.Round(threshold, 2) + "/m²");
        }
    }
Exemple #4
0
    private void drawFundamentalDiagram(Rect position)
    {
        pc.playing = false;

        InfoText it = GameObject.Find("InfoText").GetComponent <InfoText> ();

        if (it.diagram)
        {
            it.removeDiagram();
        }

        fundamentalDiagramLines = new List <VectorLine> ();
        PedestrianLoader pl         = GameObject.Find("PedestrianLoader").GetComponent <PedestrianLoader> ();
        float            maxSpeed   = float.MinValue;
        float            maxDensity = float.MinValue;
        List <Vector2>   points     = new List <Vector2> ();

        foreach (GameObject p in pl.pedestirans)
        {
            Pedestrian ped = p.GetComponent <Pedestrian>();
            if (p.hideFlags != HideFlags.HideInHierarchy)
            {
                float speed   = ped.getSpeed();
                float density = ped.getDensity();
                maxSpeed   = Mathf.Max(speed, maxSpeed);
                maxDensity = Mathf.Max(density, maxDensity);
                points.Add(new Vector2(density, speed));
            }
        }

        if (points.Count == 0)
        {
            fundamental = false;
            return;
        }

        VectorPoints.SetCamera(GameObject.Find("Flycam").GetComponent <Camera>());

        //trendline

        int   steps   = 5;
        float stepper = maxDensity / steps;


        float[] avgSpeed  = new float [steps];
        int[]   avgNumber = new int [steps];
        for (int i = 0; i < points.Count; i++)
        {
            int j = (int)(points[i].y / stepper);
            if (j < avgNumber.Length)
            {
                avgNumber[j]++;
                avgSpeed[j] = avgSpeed[j] + points[i].x;
            }
        }
        List <Vector2> l = new List <Vector2> ();

        for (int i = 0; i < steps; i++)
        {
            avgSpeed[i] = avgSpeed[i] / avgNumber[i];
            Vector2 a = new Vector2((i * stepper + (i + 1) * stepper) / 2, avgSpeed[i]);
            if (avgSpeed[i] > 0)
            {
                l.Add(new Vector2(a.x * position.width / maxDensity + position.x, a.y * position.height / maxSpeed + position.y));
            }
        }
        VectorLine line;

        if (l.Count > 1)
        {
            line = new VectorLine("spline", new Vector2[l.Count], null, 1, LineType.Continuous);
            line.SetColor(Color.red);
            line.MakeSpline(l.ToArray());
            line.depth = 99;
            line.Draw();
            fundamentalDiagramLines.Add(line);
        }


        //data points
        for (int i = 0; i < points.Count; i++)
        {
            points[i] = new Vector2(points[i].x * position.width / maxDensity + position.x, points[i].y * position.height / maxSpeed + position.y);
        }

        fundamentalDiagramPoints       = new Vectrosity.VectorPoints("Data", points.ToArray(), Color.white, null, 3);
        fundamentalDiagramPoints.depth = 99;
        fundamentalDiagramPoints.Draw();



        //frame
        line = VectorLine.SetLine(new Color(1f, 1f, 1f, 0.5f), new Vector2[] {
            new Vector2(position.x - 6, position.y - 2),
            new Vector2(position.x - 6, position.y + 9 + position.height),
            new Vector2(position.x + 5 + position.width, position.y + 9 + position.height),
            new Vector2(position.x + 5 + position.width, position.y - 2),
            new Vector2(position.x - 6, position.y - 2)
        });
        line.depth = 2;
        line.Draw();
        fundamentalDiagramLines.Add(line);

        //lines
        yLabels = new List <Label> ();
        float scaleFactor   = 0.5f;
        int   numberOfLines = (int)(maxSpeed * (1 / scaleFactor));

        if (numberOfLines > 0)
        {
            for (int i = 1; i <= numberOfLines; i++)
            {
                float hy = position.y + i * (position.height / (maxSpeed * (1 / scaleFactor)));
                line = VectorLine.SetLine(new Color(1f, 1f, 1f, 0.5f), new Vector2[] {
                    new Vector2(position.x - 5, hy),
                    new Vector2(position.x + 5 + position.width, hy)
                });
                line.depth = 1;
                line.Draw();
                fundamentalDiagramLines.Add(line);
                yLabels.Add(new Label(new Rect(position.x - 28, Screen.height - hy - 12, 20, 25), "" + i * scaleFactor));
            }
        }

        //lines
        xLabels       = new List <Label> ();
        scaleFactor   = 0.5f;
        numberOfLines = (int)(maxDensity * (1 / scaleFactor));
        if (numberOfLines > 0)
        {
            for (int i = 1; i <= numberOfLines; i++)
            {
                float hx = position.x + i * (position.width / (maxDensity * (1 / scaleFactor)));
                line = VectorLine.SetLine(new Color(1f, 1f, 1f, 0.5f), new Vector2[] {
                    new Vector2(hx, position.y - 2),
                    new Vector2(hx, position.y + 8 + position.height)
                });
                line.depth = 1;
                line.Draw();
                fundamentalDiagramLines.Add(line);
                xLabels.Add(new Label(new Rect(Screen.width - position.x - position.width + hx - 44, Screen.height - position.y, 28, 28), "" + i * scaleFactor));
            }
        }

        //background
        line           = VectorLine.SetLine(new Color(0, 0, 0, 0.7f), new Vector2[] { new Vector2(position.x - 6, position.y + (position.height + 6) / 2), new Vector2(position.x + position.width + 6, position.y + (position.height + 6) / 2) });
        line.lineWidth = position.height + 12;
        line.Draw();

        fundamentalDiagramLines.Add(line);
    }