Пример #1
0
        static void setupScenario(RVOSimulator sim)
        {
            /* Specify the global time step of the simulation. */
              sim.setTimeStep(0.25f);

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

              /*
               * Add agents, specifying their start position, and store their goals on the
               * opposite side of the environment.
               */
              for (int i = 0; i < 5; ++i) {
                for (int j = 0; j < 5; ++j) {
                  sim.addAgent(new Vector2(55.0f + i * 10.0f,  55.0f + j * 10.0f));
                  goals.Add(new Vector2(-75.0f, -75.0f));

                  sim.addAgent(new Vector2(-55.0f - i * 10.0f,  55.0f + j * 10.0f));
                  goals.Add(new Vector2(75.0f, -75.0f));

                  sim.addAgent(new Vector2(55.0f + i * 10.0f, -55.0f - j * 10.0f));
                  goals.Add(new Vector2(-75.0f, 75.0f));

                  sim.addAgent(new Vector2(-55.0f - i * 10.0f, -55.0f - j * 10.0f));
                  goals.Add(new Vector2(75.0f, 75.0f));
                }
              }

              /*
               * Add (polygonal) obstacles, specifying their vertices in counterclockwise
               * order.
               */
                List<Vector2> obstacle1 = new List<Vector2>();
                List<Vector2>  obstacle2= new List<Vector2>();
                List<Vector2>  obstacle3= new List<Vector2>();
                List<Vector2>  obstacle4= new List<Vector2>();

              obstacle1.Add(new Vector2(-10.0f, 40.0f));
              obstacle1.Add(new Vector2(-40.0f, 40.0f));
              obstacle1.Add(new Vector2(-40.0f, 10.0f));
              obstacle1.Add(new Vector2(-10.0f, 10.0f));

              obstacle2.Add(new Vector2(10.0f, 40.0f));
              obstacle2.Add(new Vector2(10.0f, 10.0f));
              obstacle2.Add(new Vector2(40.0f, 10.0f));
              obstacle2.Add(new Vector2(40.0f, 40.0f));

              obstacle3.Add(new Vector2(10.0f, -40.0f));
              obstacle3.Add(new Vector2(40.0f, -40.0f));
              obstacle3.Add(new Vector2(40.0f, -10.0f));
              obstacle3.Add(new Vector2(10.0f, -10.0f));

              obstacle4.Add(new Vector2(-10.0f, -40.0f));
              obstacle4.Add(new Vector2(-10.0f, -10.0f));
              obstacle4.Add(new Vector2(-40.0f, -10.0f));
              obstacle4.Add(new Vector2(-40.0f, -40.0f));

              sim.addObstacle(obstacle1);
              sim.addObstacle(obstacle2);
              sim.addObstacle(obstacle3);
              sim.addObstacle(obstacle4);

              /* Process the obstacles so that they are accounted for in the simulation. */
              sim.processObstacles();
        }
Пример #2
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//block");
                simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Red), TextureType.DIFFUSE);
                BoxObject tmesh = new BoxObject(new Vector3(0), 1, 1, 1, 10, new Vector3(1000, 1, 1000), Matrix.Identity, MaterialDescription.DefaultBepuMaterial());
                tmesh.isMotionLess = true;
                ForwardXNABasicShader shader    = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial       fmaterial = new ForwardMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
            }

            Simulator.setTimeStep(0.25f);
            Simulator.setAgentDefaults(5.0f, 25, 10.0f, 25.0f, 2.0f, 4.0f, new Vector2(0));

            for (int i = 0; i < 20; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    SimpleModel simpleModel = new SimpleModel(factory, "Model//block");
                    simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.White), TextureType.DIFFUSE);
                    BoxObject             tmesh     = new BoxObject(new Vector3(100 + j * 5, 5, i * 5), 1, 1, 1, 10, new Vector3(1, 1, 1), Matrix.Identity, MaterialDescription.DefaultBepuMaterial());
                    ForwardXNABasicShader shader    = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                    ForwardMaterial       fmaterial = new ForwardMaterial(shader);
                    int       id  = Simulator.addAgent(VectorUtils.ToVector2(tmesh.Position));
                    RVOObject obj = new RVOObject(id, fmaterial, simpleModel, tmesh);
                    obj.OnUpdate += new OnUpdate(obj_OnUpdate); /// dummy position update way =p
                    this.World.AddObject(obj);
                }
            }

            ///counterclockwise vertices
            Simulator.addObstacle(
                new List <Vector2>()
            {
                new Vector2(20, 20),
                new Vector2(40, 20),
                new Vector2(40, 40),
                new Vector2(40, 40),
                new Vector2(20, 40),
                new Vector2(20, 20),
            }
                );

            Simulator.processObstacles();

            ///obstacle
            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//block");
                simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Yellow), TextureType.DIFFUSE);
                GhostObject           tmesh     = new GhostObject(new Vector3(30, 0, 30), Matrix.Identity, new Vector3(10));
                ForwardXNABasicShader shader    = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial       fmaterial = new ForwardMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
            }

            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));

            Picking p = new Picking(this, 1000);

            p.OnPickedLeftButton += new OnPicked(p_OnPickedLeftButton);
        }