コード例 #1
0
ファイル: Program.cs プロジェクト: tpastor/CSharpRVO
        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)));
              }
        }
コード例 #2
0
 void p_OnPickedLeftButton(SegmentInterceptInfo SegmentInterceptInfo)
 {
     destiny = SegmentInterceptInfo.ImpactPosition;
     for (int i = 0; i < Simulator.getNumAgents(); i++)
     {
         Simulator.setAgentPrefVelocity(i, Vector3.Normalize(destiny - Simulator.getAgentPosition(i)));
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: tpastor/CSharpRVO
        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;
        }
コード例 #4
0
ファイル: Class1.cs プロジェクト: tpastor/CSharpRVO
        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);
            }
        }
コード例 #5
0
ファイル: Class1.cs プロジェクト: tpastor/CSharpRVO
        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));
                }
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: tpastor/CSharpRVO
 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) );
       }
 }