コード例 #1
0
ファイル: Program.cs プロジェクト: CaptBrick/Playground
        private void Draw(Box box)
        {
            Gl.glLoadIdentity();
            //            Gl.glTranslatef(box.Position.X, box.Position.Y, -6f);
            var ratio = 0.03f;
            Gl.glTranslatef(box.X * ratio, box.Y * ratio, -6f);

            var color = box.Color;

            this.SetGlColor(color);

            Gl.glRotatef(box.Rotation, 0.0f, 0.0f, 1.0f);
            Gl.glBegin(Gl.GL_QUADS);
            var z = 0.0f;
            var width = box.Width * ratio * 0.5f;
            var height = box.Height * ratio * 0.5f;
            Gl.glVertex3f(-width, height, z);
            Gl.glVertex3f(width, height, z);
            Gl.glVertex3f(width, -height, z);
            Gl.glVertex3f(-width, -height, z);
            Gl.glEnd();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: CaptBrick/Playground
        public void Run()
        {
            this.Initialize();
            this.Reshape();
            this.InitGL();
            this.worldObjects.Add(new Box(60, 120));
            this.worldObjects.Add(new Box(10, 10, 0 - 30 + 5, 0 + 60 - 5));
            this.worldObjects.Add(new Box(10, 10, 10 - 30 + 5, 0 + 60 - 5));
            this.worldObjects.Add(new Box(10, 10, 20 - 30 + 5, 0 + 60 - 5));
            this.worldObjects.Add(new Box(10, 10, 31 - 30 + 5, 0 + 60 - 5));

               // Gene length 2 - just X and Y position
               algorithm = new Algorithm();
               for (int i = 0; i < 10; ++i)
               {
               var box1 = new Box(10, 10);
               algorithm.AddBox(box1);
               }
               algorithm.Run();

            Events.Run();
        }
コード例 #3
0
ファイル: Algorithm.cs プロジェクト: CaptBrick/Playground
 public void AddBox(Box box)
 {
     cargo.Add(box);
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: CaptBrick/Playground
        private void Events_Tick(object sender, TickEventArgs e)
        {
            algorithm.Epoch();
            this.worldObjects.RemoveRange(1, this.worldObjects.Count - 1);
            var ground = (Box)this.worldObjects[0];
            var decode = this.algorithm.Best.Decode();
            for (int i = 0; i < this.algorithm.Cargo.Count; i++)
            {
                var pos = decode[i];
                var box = this.algorithm.Cargo[i];
                var newBox = new Box(box.Width, box.Height);

                newBox.X = pos.X - (ground.Width / 2) + (newBox.Width / 2);
                newBox.Y = -1 * pos.Y + (ground.Height / 2) - (newBox.Height / 2);
                newBox.Color = box.Color;
                this.worldObjects.Add(newBox);
            }

            this.DrawScene();
            Video.GLSwapBuffers();
        }
コード例 #5
0
ファイル: Algorithm.cs プロジェクト: CaptBrick/Playground
        private bool Overlaps(Box box)
        {
            bool result = false;
            foreach (var cargoBox in this.cargo)
            {
                if (cargoBox != box)
                {
                    result = box.Overlaps(cargoBox);
                }
            }

            return result;
        }