Exemple #1
0
        public void Show(Vector3 Start, Draw3d D, Color Col, float W)
        {
            if (X != 0 || Y != 0 || Z != 0)
            {
                double  S = 5;
                Vector3 V = new Vector3(this) + Start;
                Vector3 X = new Vector3(this);
                X.Norm();
                Vector3 Y = Cross(X, new Vector3(0, 0, 1));
                Vector3 Z = Cross(X, Y);
                if (Y.Equals(Z))
                {
                    Y = new Vector3(0, 1, 0);
                    Z = new Vector3(1, 0, 0);
                }
                X *= S * 2;
                Y.Norm();
                Z.Norm();
                Y *= S;
                Z *= S;
                D.Polygons.Add(new Polygon(D.CMult(Col, 0.9), new Vector3[] { V - X + Y + Z, V - X + Y - Z, V - X - Y - Z, V - X - Y + Z }));
                D.Polygons.Add(new Polygon(D.CMult(Col, 0.8), new Vector3[] { V, V - X + Y + Z, V - X + Y - Z }));
                D.Polygons.Add(new Polygon(D.CMult(Col, 0.7), new Vector3[] { V, V - X + Y + Z, V - X - Y + Z }));
                D.Polygons.Add(new Polygon(D.CMult(Col, 0.8), new Vector3[] { V, V - X - Y + Z, V - X - Y - Z }));
                D.Polygons.Add(new Polygon(D.CMult(Col, 0.7), new Vector3[] { V, V - X + Y - Z, V - X - Y - Z }));

                D.addLine(Col, W, Start, V - X);
            }
        }
 public void Show3D(Draw3d D, Vector3 Sun)
 {
     foreach (var I in Branches)
     {
         I.Show3D(D, Sun);
     }
     foreach (var I in Leaves)
     {
         I.Show3D(D);
         //(Sun * 15*5).Show(I.Center*15,D,Color.Orange,3);
     }
     D.addLine(Tree.BranchColor, Width * SizeScale3d, Base * SizeScale3d, Tip * SizeScale3d);
 }
        void DrawGUI()
        {
            if (UpdateFamily)
            {
                UpdateFamilyList();
            }
            CreatureText.Text = "Creatures:" + UpdateWorld.Creatures.Count.ToString();
            TreeText.Text     = "Trees:" + UpdateWorld.Trees.Count.ToString();
            if (Selected is Creature SelectedCreature)
            {
                Rectangle BrainRect = new Rectangle(20, 70, 190, 350);
                //DrawGuiBox(Brushes.LightGray, BrainRect);


                FamilyButton.Rect.Y = BrainRect.Y + BrainRect.Height + 15;

                if (SelectedCreature.Family != null)
                {
                    if (SelectedFamily)
                    {
                        Graphics.FillRectangle(new SolidBrush(Color.FromArgb(150, Color.Black)), 0, 0, Size.Width, Size.Height);
                        SelectedCreature.Family.Show(this, new Rectangle(BrainRect.Width + BrainRect.X - 50, 0, Form1.PB.Width - (200 + BrainRect.Width + BrainRect.X), Form1.PB.Height));
                    }
                    FamilyButton.Show(this);
                }
                else
                {
                    SelectedFamily = false;
                }

                /*for (int i = 0; i < SelectedElements.Count; i++)
                 * {
                 *  GuiElement E = SelectedElements[i];
                 *  E.Rect.Y= BrainRect.Y + BrainRect.Height + 65+i*50;
                 *  E.Show(this);
                 * }*/
                SelectedCreature.Brain.Show(Graphics, BrainRect);
            }
            if (Selected is Tree T)
            {
                T.Selected = true;
                T.ShowSelected(this, Draw3D);
                double S = 15;
                for (int i = -5; i < 5; i++)
                {
                    for (int j = -5; j < 5; j++)
                    {
                        Draw3D.addLine(Color.Black, 1, Draw3D.CenterPos + new Vector3(i * S, j * S, 0), Draw3D.CenterPos + new Vector3(i * S + S, j * S, 0));
                        Draw3D.addLine(Color.Black, 1, Draw3D.CenterPos + new Vector3(i * S, j * S, 0), Draw3D.CenterPos + new Vector3(i * S, j * S + S, 0));
                    }
                }
                Draw3D.display();
                Pen P = new Pen(Color.Black, 4)
                {
                    LineJoin = System.Drawing.Drawing2D.LineJoin.Round
                };
                Graphics.DrawImage(Bm, Rect3D.Location);
                Graphics.DrawRectangle(P, new Rectangle(Rect3D.Location, Draw3D.Size));
                TreeEnergyText.Rect.Y = Rect3D.Y + Rect3D.Height + 20;
                TreeEnergyText.Text   = "Energy:" + T.Energy.ToString("0");
                TreeEnergyText.Show(this);
                TreeGenerationText.Rect.Y = TreeEnergyText.Rect.Y + 50;
                TreeGenerationText.Text   = "Gen:" + T.Generation.ToString("0");
                TreeGenerationText.Show(this);
                TreeMutationText.Rect.Y = TreeGenerationText.Rect.Y + 50;
                TreeMutationText.Text   = "MutationRate:" + (T.MutationRate * 100).ToString("0") + "%";
                TreeMutationText.Show(this);
                T.NeuralNetwork.Show(Graphics, new Rectangle(20, TreeMutationText.Rect.Y + 50, 200, 350));
            }
            foreach (var E in Elements)
            {
                E.Show(this);
            }
            if (!(FileHandler.LoadState || FileHandler.SaveState))
            {
                int i = -1;
                foreach (var E in FamilyButtons)
                {
                    E.Show(this);
                    if (i >= 0)
                    {
                        E.Text = Families[i].Root.Name + ":" + Families[i].FamilyMembersAlive.ToString();
                    }
                    i++;
                }
            }
            if (!SelectedFamily)
            {
                CreatureGraph.Show(this);
                TreeGraph.Show(this);
                CreatureText.Show(this);
                TreeText.Show(this);
            }
        }