예제 #1
0
    private void drawDiagram(Rect position)
    {
        diagram = true;
        FundamentalDiagram fd = GameObject.Find("FundamentalDiagram").GetComponent <FundamentalDiagram> ();

        if (fd.fundamental)
        {
            fd.removeFundamentalDiagram();
        }

        diagramPosition = position;
        diagramLines    = 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>();
            Renderer   r   = ped.GetComponentInChildren <Renderer>() as Renderer;
            if (r.enabled)
            {
                float speed   = ped.getSpeed();
                float density = ped.getDensity();
                maxSpeed   = Mathf.Max(speed, maxSpeed);
                maxDensity = Mathf.Max(density, maxDensity);
                points.Add(new Vector2(speed, density));
            }
        }


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

        PlaybackControl pc = GameObject.Find("PlaybackControl").GetComponent <PlaybackControl> ();

        //data points
        VectorPoints.SetCamera(GameObject.Find("Flycam").camera);

        Vector2[] dp = new Vector2[(int)pc.total_time];
        for (int i = 0; i < dp.Length; i++)
        {
            dp[i] = new Vector2(position.x + position.width * ((float)(i / pc.total_time)), position.y);
        }
        dataPoints       = VectorLine.SetLine(Color.white, dp);
        dataPoints.depth = 99;
        dataPoints.Draw();
        diagramLines.Add(dataPoints);

        //frame
        VectorLine 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();
        diagramLines.Add(line);


        int maxTime = (int)pc.total_time;

        //lines
        xLabels = new List <Label> ();
        float scaleFactor   = 10f;
        int   numberOfLines = (int)(maxTime * (1 / scaleFactor));

        if (numberOfLines > 0)
        {
            for (int i = 1; i <= numberOfLines; i++)
            {
                float hx = position.x + i * (position.width / (maxTime * (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();
                diagramLines.Add(line);
                xLabels.Add(new Label(new Rect(Screen.width - position.x - position.width + hx - 44, Screen.height - position.y, 28, 28), "" + i * scaleFactor));
            }
        }

        float tx = ((float)(pc.current_time / pc.total_time)) * position.width + position.x;

        timeIndicator = VectorLine.SetLine(Color.red, new Vector2[] {
            new Vector2(tx, position.y - 2),
            new Vector2(tx, position.y + 8 + position.height)
        });

        //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();

        diagramLines.Add(line);
    }
예제 #2
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);
    }