Ejemplo n.º 1
0
    void moveAgents()
    {
        if (!animate)
        {
            return;
        }

        for (int i = 0; i < numAgents_; i++)
        {
            if (!showTargets)
            {
                targetAgents_[i].SetActive(false);
            }

            if (timestep >= agents_[i].pos.Count)
            {
                continue;
            }

            walkerAgents_[i].transform.SetPositionAndRotation(agents_[i].pos[timestep], Quaternion.identity);
            walkerAgents_[i].transform.forward = agents_[i].getForward(timestep);
            targetAgents_[i].transform.SetPositionAndRotation(agents_[i].tar[timestep], Quaternion.identity);

            List <Vector3> poss = new List <Vector3>();

            for (int t = timestep; t >= 0; t--)
            {
                if (poss.Count >= trailLength)
                {
                    break;
                }
                poss.Add(agents_[i].pos[t]);
            }

            walkerAgents_[i].GetComponent <LineRenderer>().positionCount = poss.Count;
            walkerAgents_[i].GetComponent <LineRenderer>().SetPositions(poss.ToArray());
        }

        // number of collisions
        int   collisions   = 0;
        float minDist      = float.MaxValue;
        int   densityCount = 0;


        for (int i = 0; i < numAgents_; i++)
        {
            var di = walkerAgents_[i].transform.position - targetAgents_[i].transform.position;

            // reached
            if (di.magnitude < agents_[i].radius)
            {
                continue;
            }

            for (int j = i + 1; j < numAgents_; j++)
            {
                var dj = walkerAgents_[j].transform.position - targetAgents_[j].transform.position;

                // reached
                if (dj.magnitude < agents_[j].radius)
                {
                    continue;
                }

                var Dij = (walkerAgents_[i].transform.position - walkerAgents_[j].transform.position).magnitude;

                // check collision
                if (Dij < 2 * agents_[i].radius)
                {
                    collisions++;
                    totalCollisions++;
                }

                if (Dij < minDist)
                {
                    minDist = Dij;
                }

                if (Dij < 6 * agents_[i].radius)
                {
                    densityCount++;
                }
            }
        }

        for (int i = 0; i < numAgents_; i++)
        {
            if (timestep >= agents_[i].pos.Count)
            {
                continue;
            }

            var   di     = (targetAgents_[i].transform.position - walkerAgents_[i].transform.position).normalized;
            var   vi     = agents_[i].getForward(timestep).normalized;
            float orient = Vector3.SignedAngle(di, vi, Vector3.up);
            ort_.AddOrientation(orient);
        }


        ScreenCapture.CaptureScreenshot("Screenshots/shot_" + (timestep + 1) + ".png");

        if (!showInfo)
        {
            info_.text = "";
        }
        else
        {
            info_.text = "Timestep : " + (timestep + 1) + "/" + (maxTimeStep + 1) +
                         "\nCollisions : " + collisions + "\nTotal Collisions : " + totalCollisions;
        }

        SW_.WriteLine((timestep + 1) + "," + collisions + "," + densityCount + "," + minDist + "," + ort_.max + "," + ort_.min + "," + ort_.mean + "," + ort_.sd2 + "," + ort_.num);
        timestep = (timestep + 1) % (maxTimeStep + 1);
        if (timestep == 0)
        {
            animate = false;
            SW_.Close();
        }
    }