Esempio n. 1
0
    void UpdateSecond()
    {
        if (activeEntry > -1)
        {
            FundamentalDiagram fd = GameObject.Find("FundamentalDiagram").GetComponent <FundamentalDiagram> ();
            fd.removeFundamentalDiagram();

            PlaybackControl pc = GameObject.Find("PlaybackControl").GetComponent <PlaybackControl> ();
            float           tx = ((float)(pc.current_time / pc.total_time)) * diagramPosition.width + diagramPosition.x;
            timeIndicator.points2 = new Vector2[] {
                new Vector2(tx, diagramPosition.y - 2),
                new Vector2(tx, diagramPosition.y + 8 + diagramPosition.height)
            };
            timeIndicator.depth = 100;
            timeIndicator.Draw();

            Vector2[] dp = dataPoints.points2;
            try {
                dp[((int)pc.current_time) - 1] = new Vector2(diagramPosition.x + diagramPosition.width * ((float)(pc.current_time / pc.total_time)), diagramPosition.y + Mathf.Min(1.0f, (infos[activeEntry].value / infos[activeEntry].maxValue)) * diagramPosition.height);
                dataPoints.points2             = dp;
                dataPoints.Draw();
            } catch (System.IndexOutOfRangeException) {
            }
        }
    }
Esempio n. 2
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);
    }