Exemple #1
0
        void obj_OnUpdate(IObject obj, GameTime gt, ICamera cam)
        {
            Vector2 p  = Simulator.getAgentPosition((obj as RVOObject).RVOID);
            Vector3 p3 = new Vector3(p.X, obj.PhysicObject.Position.Y, p.Y);

            obj.PhysicObject.Position = p3;
        }
Exemple #2
0
        static void setPreferredVelocities(RVOSimulator sim)
        {
            /*
               * Set the preferred velocity to be a vector of unit magnitude (speed) in the
               * direction of the goal.
               */
            #pragma omp parallel for
              for (int i = 0; i < sim.getNumAgents(); ++i) {
                Vector2 goalVector = goals[i] - sim.getAgentPosition(i);

                if ((goalVector.LengthSquared()) > 1.0f) {
                  goalVector = Vector2.Normalize(goalVector);
                }

                sim.setAgentPrefVelocity(i, goalVector);

                /*
                 * Perturb a little to avoid deadlocks due to perfect symmetry.
                 */

                float angle = (float)r.NextDouble() * 2.0f * (float)Math.PI ;
                float dist = (float)r.NextDouble() * 0.0001f ;

                sim.setAgentPrefVelocity(i, sim.getAgentPrefVelocity(i) +
                                          dist * new Vector2((float) Math.Cos(angle), (float)Math.Sin(angle)));
              }
        }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (isAbleToStart && agentIndex != -1)
        {
            if (canMove)
            {
                transform.position = toUnityVector(simulator.getAgentPosition(agentIndex));

                /*if (gameObject.name == "IA")
                 * {
                 *  Debug.Log(Simulator.Instance.getAgentPrefVelocity(agentIndex));
                 * }
                 * UnityEngine.Vector2 newVelocity = (toUnityVector(calculateNextStation()) - (UnityEngine.Vector2)transform.position).normalized;
                 * Simulator.Instance.setAgentPrefVelocity(agentIndex, toRVOVector(newVelocity));*/

                if (updatePathtime_tmp >= 0)
                {
                    updatePathtime_tmp -= Time.deltaTime;
                }
                else
                {
                    updatePathtime_tmp = updatePathtime;
                    //if (agentSeeker.IsDone()) StartCoroutine(UpdatePathTarget());
                }
            }
        }
    }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        Vector3 animationPosition = Vector3.zero;


        /*
         * Perturb a little to avoid deadlocks due to perfect symmetry.
         */

        if (destinazioneRaggiunta())
        {
            ChangePosition(1f);
            GetComponent <CharacterAnimator>().Move(animationPosition);

            try
            {
                if (GetComponent <BotVisitData>().destination != null && GetComponent <BotVisitData>().destination.CompareTag("PicturePlane"))
                {
                    Vector3 picturePosition = GetComponent <BotVisitData>().destination.transform.parent.transform.position;
                    GetComponent <CharacterAnimator>().TurnToPicture(picturePosition);
                }
            }
            catch (NullReferenceException e)
            {
                Debug.Log(name + ": la destinazione non è un quadro");
            }
        }
        else
        {
            if (isAbleToStart && agentIndex != -1)
            {
                //System.Random r = new System.Random();

                //float angle = ( float )r.NextDouble() * 2.0f * ( float )Math.PI;
                //float dist = ( float )r.NextDouble() * 0.0001f;

                //simulator.getSimulator().setAgentPrefVelocity( agentIndex, simulator.getSimulator().getAgentPrefVelocity( agentIndex ) +
                //                          dist * new RVO.Vector2( ( float )Math.Cos( angle ), ( float )Math.Sin( angle ) ) );
                //simulator.getSimulator().doStep();

                ChangePosition(2.3f);
                animationPosition = toUnityVector(simulator.getAgentPosition(agentIndex)) - transform.position;
                GetComponent <CharacterAnimator>().Move(animationPosition);
            }
        }
    }
Exemple #5
0
        static bool reachedGoal(RVOSimulator sim)
        {
            /* Check if all agents have reached their goals. */
              for (int i = 0; i < sim.getNumAgents(); ++i) {
                if ((sim.getAgentPosition(i) - goals[i]).LengthSquared() > 20.0f * 20.0f) {
                  return false;
                }
              }

              return true;
        }
Exemple #6
0
        static void setPreferredVelocities(RVOSimulator sim)
        {
            for (int i = 0; i < sim.getNumAgents(); ++i) {
                Vector3 goalVector = goals[i] - sim.getAgentPosition(i);

                if ((goalVector.LengthSquared()) > 1.0f) {
                    goalVector = Vector3.Normalize(goalVector);
                }

                sim.setAgentPrefVelocity(i, goalVector);
            }
        }
Exemple #7
0
        static void setupScenario(RVOSimulator sim)
        {
            /* Specify the global time step of the simulation. */
            sim.setTimeStep(0.125f);

            /* Specify the default parameters for agents that are subsequently added. */
            sim.setAgentDefaults(15.0f, 10, 10.0f, 1.5f, 2.0f,new Vector3());

            /* Add agents, specifying their start position, and store their goals on the opposite side of the environment. */
            for (float a = 0; a < Math.PI; a += 0.1f) {
                float z = 100.0f * (float)Math.Cos(a);
                float r = 100.0f * (float)Math.Sin(a);

                for (int i = 0; i < r / 2.5f; ++i) {
                    float x = r * (float)Math.Cos(i * 2.0f * (float)Math.PI / (r / 2.5f));
                    float y = r * (float)Math.Sin(i * 2.0f * (float)Math.PI / (r / 2.5f));

                    sim.addAgent(new Vector3(x, y, z));
                    goals.Add(sim.getAgentPosition(sim.getNumAgents() - 1));
                }
            }
        }
        void obj_OnUpdate(IObject obj, GameTime gt, ICamera cam)
        {
            Vector3 p = Simulator.getAgentPosition((obj as RVOObject).RVOID);

            obj.PhysicObject.Position = p;
        }
Exemple #9
0
 static void updateVisualization(RVOSimulator sim)
 {
     /* Output the current position of all the agents. */
       for (int i = 0; i < sim.getNumAgents(); ++i) {
         Console.WriteLine(sim.getAgentPosition(i) );
       }
 }