Пример #1
0
        //public override void Execute(AgentBase agent)
        //{
        //    CellGroup cellGroup = agent as CellGroup;
        //    if (!cellGroup.IsActive) return;
        //    CellAgentSystem cellSystem = cellGroup.AgentSystem as CellAgentSystem;

        //    for (int i = 0; i < cellSystem.Agents.Count; i++)
        //    {
        //        CellGroup anotherGroup = cellSystem.Agents[i] as CellGroup;
        //        if (cellGroup == anotherGroup) continue;
        //        // check if the agent can merge with another agnent
        //        foreach (Point3d place in cellGroup.PlaceToConnect())
        //        {
        //            foreach (Plane pose in cellSystem.CellPoses.Branch(i))
        //            {
        //                if (place.DistanceTo(pose.Origin) < 0.75 * cellSystem.GridSize)
        //                {
        //                    cellGroup.Merge(anotherGroup, place, pose);
        //                    cellSystem.Agents.RemoveAt(i);
        //                    goto NextStep;
        //                }
        //            }
        //        }
        //    NextStep: continue;
        //    }
        //}

        public void ExecuteWithSystem(CellGroup cellGroup, CellAgentSystem cellSystem)
        {
            if (!cellGroup.IsActive)
            {
                return;
            }

            //List<int> RemovedIndices = new List<int>(); //for the bug during merging
            for (int i = 0; i < cellSystem.Agents.Count; i++)
            {
                //if (RemovedIndices.Contains(i)) continue; //for the bug during merging
                CellGroup anotherGroup = cellSystem.Agents[i] as CellGroup;
                if (cellGroup == anotherGroup)
                {
                    continue;
                }
                // check if the agent can merge with another agnent
                foreach (Point3d place in cellGroup.PlaceToConnect())
                {
                    foreach (Plane pose in cellSystem.CellPoses.Branch(i))
                    {
                        if (place.DistanceTo(pose.Origin) < 0.75 * cellSystem.GridSize)
                        {
                            cellGroup.Merge(anotherGroup, place, pose);
                            cellSystem.Agents.RemoveAt(i);
                            //RemovedIndices.Add(i); //for the bug during merging
                            goto NextStep;
                        }
                    }
                }
                NextStep : continue;
            }
        }
Пример #2
0
        //public override void Execute(AgentBase agent)
        //{
        //    CellGroup cellGroup = agent as CellGroup;
        //    Vector3d t = new Vector3d(rd.NextDouble()-0.5, rd.NextDouble()-0.5, 0.0);
        //    double r = rd.NextDouble() * Math.PI * 0.05;
        //    cellGroup.Move(t, r);
        //}

        public virtual void ExecutWithSystem(CellGroup cellGroup, CellAgentSystem cellSystem)
        {
            Vector3d t = new Vector3d(rd.NextDouble() - 0.5, rd.NextDouble() - 0.5, 0.0);
            double   r = (rd.NextDouble() - 0.5) * Math.PI * 0.05;

            t += FindNeighor(cellGroup, cellSystem);
            cellGroup.Move(t, r);
        }
Пример #3
0
        internal void ExecuteWithSystem(CellAgentSystem system)
        {
            WanderBehavior b0 = Behaviors[0] as WanderBehavior;

            b0.ExecutWithSystem(this, system);
            MergeBehavior b1 = Behaviors[1] as MergeBehavior;

            b1.ExecuteWithSystem(this, system);
        }
Пример #4
0
        private Vector3d FindNeighor(CellGroup cellGroup, CellAgentSystem cellSystem)
        {
            int    minIndex = -1;
            double minDis   = 999999999999999999;

            for (int i = 0; i < cellSystem.Agents.Count; i++)
            {
                CellGroup g = cellSystem.Agents[i] as CellGroup;
                if (cellGroup.Pose.Origin.DistanceTo(g.Pose.Origin) < 0.01)
                {
                    continue;
                }
                if (minDis > cellGroup.Pose.Origin.DistanceTo(g.Pose.Origin))
                {
                    minIndex = i;
                    minDis   = cellGroup.Pose.Origin.DistanceTo(g.Pose.Origin);
                }
            }
            CellGroup gMin = cellSystem.Agents[minIndex] as CellGroup;
            Vector3d  v    = new Vector3d(gMin.Pose.Origin - cellGroup.Pose.Origin);

            v.Unitize();
            return(v * 0.8);
        }
Пример #5
0
 public MySolver(CellAgentSystem system)
 {
     this.System = system;
 }