예제 #1
0
        public Boids(BoidsParameter boidsParameter)
        {
            this.boidsParameter = boidsParameter;

            boidDisplays = new CircleNode[BoidsCount];
            positions    = new Vector2F[BoidsCount];
            directions   = new Vector2F[BoidsCount];

            // Background
            AddChildNode(new RectangleNode {
                Color = new Color(10, 10, 10), RectangleSize = Area
            });

            // Initialize Parameters
            var rand = new Random();

            for (int i = 0; i < BoidsCount; i++)
            {
                boidDisplays[i] = new CircleNode {
                    VertNum = 20, Radius = 5.0f
                };
                AddChildNode(boidDisplays[i]);

                positions[i]  = new Vector2F(Area.X * (float)rand.NextDouble(), Area.Y * (float)rand.NextDouble());
                directions[i] = new Vector2F((float)rand.NextDouble() * 2.0f - 1.0f, (float)rand.NextDouble() * 2.0f - 1.0f);
                if (directions[i].SquaredLength != 0.0f)
                {
                    directions[i] = directions[i].Normal;
                }
                gravityPoint += positions[i];
            }
            gravityPoint /= BoidsCount;

            mouseCircle = new CircleNode {
                VertNum = 20, Radius = 5.0f, Color = new Color(255, 50, 50)
            };
            AddChildNode(mouseCircle);
        }
예제 #2
0
        static void Main(string[] args)
        {
            var config = new Configuration();

            config.ConsoleLoggingEnabled = true;
            config.ToolEnabled           = true;
            config.WaitVSync             = false;

            Engine.Initialize("Boids", 800, 600, config);

            Engine.TargetFPS = 2000.0f;

            var param = new BoidsParameter
            {
                Speed      = 100.0f,
                Separation = 20.0f,
                Alignment  = 30.0f,
                Cohesion   = 0.2f,
                Wall       = 0.001f,
                Mouse      = 1.0f,
            };

            Engine.AddNode(new Boids(param));

            while (Engine.DoEvents())
            {
                if (Engine.Tool.Begin("Boids", ToolWindowFlags.None))
                {
                    float speed      = param.Speed;
                    float separation = param.Separation;
                    float alignment  = param.Alignment;
                    float cohesion   = param.Cohesion;
                    float wall       = param.Wall;
                    float mouse      = param.Mouse;

                    Engine.Tool.Text($"FPS:{Engine.CurrentFPS}");
                    if (Engine.Tool.InputFloat("Speed", ref speed))
                    {
                        param.Speed = speed;
                    }
                    if (Engine.Tool.InputFloat("Separation", ref separation))
                    {
                        param.Separation = separation;
                    }
                    if (Engine.Tool.InputFloat("Alignment", ref alignment))
                    {
                        param.Alignment = alignment;
                    }
                    if (Engine.Tool.InputFloat("Cohesion", ref cohesion))
                    {
                        param.Cohesion = cohesion;
                    }
                    if (Engine.Tool.InputFloat("Wall", ref wall))
                    {
                        param.Wall = wall;
                    }
                    if (Engine.Tool.InputFloat("Mouse", ref mouse))
                    {
                        param.Mouse = mouse;
                    }
                    Engine.Tool.End();
                }

                Engine.Update();
            }

            Engine.Terminate();
        }