setAgentDefaults() 공개 메소드

Sets the default properties for any new agent that is added. *
public setAgentDefaults ( float neighborDist, int maxNeighbors, float timeHorizon, float timeHorizonObst, float radius, float maxSpeed, Vector2 velocity ) : void
neighborDist float The default maximum distance (center point * to center point) to other agents a new agent takes into account in * the navigation. The larger this number, the longer he running time of * the simulation. If the number is too low, the simulation will not be * safe. Must be non-negative.
maxNeighbors int The default maximum number of other agents * a new agent takes into account in the navigation. The larger this * number, the longer the running time of the simulation. If the number * is too low, the simulation will not be safe.
timeHorizon float The default minimal amount of time for * which a new agent's velocities that are computed by the simulation * are safe with respect to other agents. The larger this number, the * sooner an agent will respond to the presence of other agents, but the * less freedom the agent has in choosing its velocities. Must be * positive.
timeHorizonObst float The default minimal amount of time for * which a new agent's velocities that are computed by the simulation * are safe with respect to obstacles. The larger this number, the * sooner an agent will respond to the presence of obstacles, but the * less freedom the agent has in choosing its velocities. Must be * positive.
radius float The default radius of a new agent. Must be * non-negative.
maxSpeed float The default maximum speed of a new agent. Must * be non-negative.
velocity Vector2 The default initial two-dimensional linear * velocity of a new agent.
리턴 void
예제 #1
0
    // Use this for initialization
    void Start()
    {
        units = new List <AIPath>();
        sim   = RVO.Simulator.Instance;

        sim.setAgentDefaults(neighborDist, maxNeighbors, timeHorizon, timeHorizonObst, radius, maxSpeed, new RVO.Vector2(0, 0));

        sim.SetNumWorkers(1);
        //TODO add obstacles?
        //process obstacles
        sim.processObstacles();

        instance = this;
    }
예제 #2
0
 private float _maxSpeed             = 30.0f; //5.0f;
 public void Init()
 {
     m_instance.setAgentDefaults(_neighbourDistance, _maxNeighbours, _timeHorizon, _timeHorizonObstacles, _defaultRadius, _maxSpeed, new RVO.Vector2());
 }
예제 #3
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 = Simulator.Instance;
            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(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);            
        }
예제 #4
0
    /// <summary>Create a number of agents in circle and restart simulation</summary>
    public void CreateAgents(int num)
    {
        this.m_agentCount = num;

        goals      = new Dictionary <int, Vector3>();
        colors     = new List <Color>(m_agentCount);
        m_agentIds = new List <int>(num);

        sim.Clear();
        sim.setTimeStep(m_timeStep);
        sim.setAgentDefaults(neighborDist: m_neighbourDist, maxNeighbors: m_maxNeighbours, radius: m_radius, maxSpeed: m_maxSpeed, timeHorizon: 2, timeHorizonObst: 2, velocity: new RVO.Vector2(1, 1));

        if (type == RVOExampleType.Circle)
        {
            float circleRad = Mathf.Sqrt(m_agentCount * m_radius * m_radius * 4 / Mathf.PI) * exampleScale * 0.05f;

            for (int i = 0; i < m_agentCount; i++)
            {
                Vector3 pos = new Vector3(Mathf.Cos(i * Mathf.PI * 2.0f / m_agentCount), 0, Mathf.Sin(i * Mathf.PI * 2.0f / m_agentCount)) * circleRad * (1 + Random.value * 0.01f);
                var     id  = sim.addAgent(new RVO.Vector2(pos.x, pos.z));
                m_agentIds.Add(id);
                goals.Add(id, -pos);
                colors.Add(ColorUtility.HSVToRGB(i * 360.0f / m_agentCount, 0.8f, 0.6f));
            }
        }
        else if (type == RVOExampleType.Line)
        {
            for (int i = 0; i < m_agentCount; i++)
            {
                Vector3 pos = new Vector3((i % 2 == 0 ? 1 : -1) * exampleScale, 0, (i / 2) * m_radius * 2.5f);
                var     id  = sim.addAgent(new RVO.Vector2(pos.x, pos.z));
                m_agentIds.Add(id);
                goals.Add(id, new Vector3(-pos.x, pos.y, pos.z));
                colors.Add(i % 2 == 0 ? Color.red : Color.blue);
            }
        }
        else if (type == RVOExampleType.Point)
        {
            for (int i = 0; i < m_agentCount; i++)
            {
                Vector3 pos = new Vector3(Mathf.Cos(i * Mathf.PI * 2.0f / m_agentCount), 0, Mathf.Sin(i * Mathf.PI * 2.0f / m_agentCount)) * m_radius;
                var     id  = sim.addAgent(new RVO.Vector2(pos.x, pos.z));
                m_agentIds.Add(id);
                //sim.AddAgent(new Vector2(0, 0));
                goals.Add(id, new Vector3(0, pos.y, 0));
                colors.Add(ColorUtility.HSVToRGB(i * 360.0f / m_agentCount, 0.8f, 0.6f));
            }
        }
        else if (type == RVOExampleType.RandomStreams)
        {
            float circleRad = Mathf.Sqrt(m_agentCount * m_radius * m_radius * 4 / Mathf.PI) * exampleScale * 0.05f;

            for (int i = 0; i < m_agentCount; i++)
            {
                float   angle       = Random.value * Mathf.PI * 2.0f;
                float   targetAngle = Random.value * Mathf.PI * 2.0f;
                Vector3 pos         = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * uniformDistance(circleRad);
                var     id          = sim.addAgent(new RVO.Vector2(pos.x, pos.z));
                m_agentIds.Add(id);
                goals.Add(id, new Vector3(Mathf.Cos(targetAngle), 0, Mathf.Sin(targetAngle)) * uniformDistance(circleRad));
                colors.Add(ColorUtility.HSVToRGB(targetAngle * Mathf.Rad2Deg, 0.8f, 0.6f));
            }
        }
        else if (type == RVOExampleType.Crossing)
        {
            float distanceBetweenGroups = exampleScale * m_radius * 0.5f;
            int   directions            = (int)Mathf.Sqrt(m_agentCount / 25f);
            directions = Mathf.Max(directions, 2);

            const int AgentsPerDistance = 10;
            for (int i = 0; i < m_agentCount; i++)
            {
                float   angle = ((i % directions) / (float)directions) * Mathf.PI * 2.0f;
                var     dist  = distanceBetweenGroups * ((i / (directions * AgentsPerDistance) + 1) + 0.3f * Random.value);
                Vector3 pos   = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * dist;
                var     id    = sim.addAgent(new RVO.Vector2(pos.x, pos.z));
                m_agentIds.Add(id);
                goals.Add(id, -pos.normalized * distanceBetweenGroups * 3);
                colors.Add(ColorUtility.HSVToRGB(angle * Mathf.Rad2Deg, 0.8f, 0.6f));
            }
        }

        verts      = new Vector3[4 * m_agentCount];
        uv         = new Vector2[verts.Length];
        tris       = new int[m_agentCount * 2 * 3];
        meshColors = new Color[verts.Length];
    }