Beispiel #1
0
    public void showTrajectory()
    {
        List <Vector3> points = new List <Vector3>();

        for (int i = 0; i < positions.Count - 1; i++)
        {
            PedestrianPosition a = (PedestrianPosition)positions.GetByIndex(i);
            points.Add(new Vector3(a.getX(), a.getZ() + 0.01f, a.getY()));
        }

        GameObject myLine = new GameObject(name + " trajectory");

        myLine.transform.position = points[1];
        myLine.AddComponent <LineRenderer>();
        LineRenderer lr = myLine.GetComponent <LineRenderer>();

        lr.material = new Material((Material)Resources.Load("LineMaterial", typeof(Material)));
        lr.material.SetColor("_EmissionColor", myColor);
        lr.material.SetColor("_Color", myColor);
        lr.startColor   = myColor;
        lr.endColor     = myColor;
        lr.startWidth   = 0.08f;
        lr.endWidth     = 0.08f;
        lr.numPositions = points.Count;
        lr.SetPositions(points.ToArray());

        pc.trajectoriesShown = true;
        trajectoryVisible    = true;
    }
    public void addPedestrianPosition(PedestrianPosition p)
    {
        positions.Add(p);
        PlaybackControl pc = GameObject.Find("PlaybackControl").GetComponent <PlaybackControl>();

        if (p.getTime() > pc.total_time)
        {
            pc.total_time = p.getTime();
        }
    }
    public void setPositions(SortedList p)
    {
        positions.Clear();
        foreach (PedestrianPosition ped in p.Values)
        {
            positions.Add(ped.getTime(), ped);
        }
        PedestrianPosition pos = (PedestrianPosition)p.GetByIndex(0);

        transform.position = new Vector3(pos.getX(), 0, pos.getY());
    }
Beispiel #4
0
    public void showTrajectory()
    {
        VectorLine.SetCamera(GameObject.Find("Flycam").camera);

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

        for (int i = 0; i < positions.Count - 1; i++)
        {
            PedestrianPosition a = (PedestrianPosition)positions.GetByIndex(i);
            points.Add(new Vector3(a.getX(), 0.01f, a.getY()));
        }

        trajectory           = VectorLine.SetLine3D(myColor, points.ToArray());
        trajectory.lineWidth = 3.0f;
        pc.trajectoriesShown = true;
        trajectoryVisible    = true;
    }
    // Update is called once per frame
    void Update()
    {
        if (pc.playing)
        {
            GetComponent <Animation>().Play();
        }
        else
        {
            GetComponent <Animation>().Stop();
        }

        int index = _getTrait(positions, pc.current_time);

        if (index < positions.Count - 1 && index > -1)
        {
            r.enabled = true;
            PedestrianPosition pos  = (PedestrianPosition)positions.GetByIndex(index);
            PedestrianPosition pos2 = (PedestrianPosition)positions.GetByIndex(index + 1);
            start  = new Vector3(pos.getX(), 0, pos.getY());
            target = new Vector3(pos2.getX(), 0, pos2.getY());
            float   time = (float)pc.current_time;
            float   movement_percentage = (float)time - (float)pos.getTime();
            Vector3 newPosition         = Vector3.Lerp(start, target, movement_percentage);

            Vector3 relativePos = target - start;
            speed = relativePos.magnitude;

            GetComponent <Animation>()["walking"].speed = getSpeed();
            if (start != target)
            {
                transform.rotation = Quaternion.LookRotation(relativePos);
            }

            if (gp.point1active && gp.point2active)
            {
                if (FasterLineSegmentIntersection(new Vector2(gp.point1.x, gp.point1.z), new Vector2(gp.point2.x, gp.point2.z), new Vector2(transform.position.x, transform.position.z), new Vector2(newPosition.x, newPosition.z)))
                {
                    gp.lineCross(speed);
                }
            }

            if (pc.tileColoringMode != TileColoringMode.TileColoringNone)
            {
                tile.GetComponent <Renderer>().enabled = true;

                if (pc.tileColoringMode == TileColoringMode.TileColoringSpeed)
                {
                    tile.GetComponent <Renderer>().material.color = ColorHelper.ColorForSpeed(getSpeed());
                    it.updateSpeed(speed);
                }
                else if (pc.tileColoringMode == TileColoringMode.TileColoringDensity)
                {
                    densityReload = (densityReload + 1) % densityReloadInterval;
                    if (densityReload == 0)
                    {
                        getDensity();
                    }
                    float density = getDensity();
                    tile.GetComponent <Renderer>().material.color = ColorHelper.ColorForDensity(density);
                }
            }
            else
            {
                tile.GetComponent <Renderer>().enabled = false;
            }

            transform.position   = newPosition;
            gameObject.hideFlags = HideFlags.None;
        }
        else
        {
            r.enabled = false;
            tile.GetComponent <Renderer>().enabled = false;
            gameObject.hideFlags = HideFlags.HideInHierarchy;
        }
    }
 public void addPedestrianPosition(PedestrianPosition p)
 {
     positions.Add (p);
     if (p.getTime () > pc.total_time)
         pc.total_time = p.getTime ();
 }
    // Update is called once per frame
    void Update()
    {
        LinkedListNode<PedestrianPosition> cur;

        /*if (pc.playing) {
            GetComponent<Animation>().Play ();
        /*} else {
            GetComponent<Animation>().Stop ();
        }*/

        //int index = _getTrait(positions, pc.current_time);

        /*
        if(animOn){
            GetComponent<Animation>().Play();
            //r.enabled = true;
        }else{
            GetComponent<Animation>().Stop();
            //r.enabled = false;
        }
        */

        cur = _getTrait2 (pc.current_time);

            //Debug.Log("x:\t" +cur.Value.getX() +"y:\t"+ cur.Value.getY() + "time:\t"+cur.Value.getTime() + "id:\t" + id);
            if (cur != null && cur != last) {

                iterator = cur;

            //r.enabled = true;

            if(!isActive()){
                active = true;
                r.enabled = true;
            }

                //bool necessaryToTransform = false;

                //Not On Trigger
                //if(!animOn){

                    //same with ray

            //var heading = new Vector3(cur.Value.getX(),cam.transform.position.y,cur.Value.getY()) - cam.transform.position;
            //if(Vector3.Dot(heading,cam.transform.forward)> 40){

            /*

            int dist =(int)Vector3.Distance(new Vector3(cur.Value.getX(),cam.transform.position.y,cur.Value.getY()),cam.transform.position);

            if(dist > 30){
                GetComponent<Animation>().Stop();

            }

            GetComponent<Animation>().Play();

            */

                //r.enabled = true;
                //if(animOn){
                //bool necessaryToTransform = (pc.current_time - lastTime) > reducedStepTime;

                            //GetComponent<Animation>().Play ();
                            //lastTime = pc.current_time;
                            //if (index < positions.Count - 1 && index > -1){

                            //PedestrianPosition pos = (PedestrianPosition) positions.GetByIndex (index);
                            //PedestrianPosition pos2 = (PedestrianPosition) positions.GetByIndex (index+1);

            PedestrianPosition pos = (PedestrianPosition)cur.Value;
            PedestrianPosition pos2 = (PedestrianPosition)cur.Next.Value;
            start = new Vector3 (pos.getX (), 0, pos.getY ());
            target = new Vector3 (pos2.getX (), 0, pos2.getY ());
            float time = pc.current_time;
            float timeStepLength = Mathf.Clamp (pos2.getTime () - pos.getTime (), 0.1f, 50f); // We don't want to divide by zero. OTOH, this results in pedestrians never standing still.
            float movement_percentage = (time - pos.getTime ()) / timeStepLength;
            Vector3 newPosition = Vector3.Lerp (start, target, movement_percentage);
            //Debug.Log("Pos:/tx:" + newPosition.x +"y:/t" +newPosition.z + "id:/t" + id);

            gameObject.hideFlags = HideFlags.None;
            transform.position = newPosition;

            if (pos != lastPos) {

                lastPos = pos;

                Vector3 relativePos = target - start;

                speed = relativePos.magnitude;
                //if (start != target)
                transform.rotation = Quaternion.LookRotation (relativePos);
                genderBasedAnim.speed = getSpeed () / timeStepLength;

            }

                    /*}else {
                        if(GetComponent<Animation>().isPlaying)
                        GetComponent<Animation> ().Stop ();

                    }*/

            } else {
            //Debug.Log("hide");
                //currentTrait = 0;

            //TODO search an better stantment for looping
                if(pc.current_time < 1)
                iterator = positions.First;
            //Debug.Log(iterator.Value.getTime());
                active = false;
                r.enabled = false;
                gameObject.hideFlags = HideFlags.HideInHierarchy;
            }
    }