예제 #1
0
파일: Form1.cs 프로젝트: gogasan24ru/oho1.1
        private void drawObjects()
        {
            if (!pictureBox1.Focused)
            {
                pictureBox1.Focus();
            }
            gr.Clear(Color.White);
            Pen pen = new Pen(Color.Black, 1);

            if (checkBox5.Checked)
            {
                int step = trackBar2.Value;
                for (int i = 0; i < pictureBox1.Width; i += step)
                {
                    gr.DrawLine(pen, i, 0, i, pictureBox1.Height);
                }
                for (int k = 0; k < pictureBox1.Height; k += step)
                {
                    gr.DrawLine(pen, 0, k, pictureBox1.Width, k);
                }
            }
            gr.DrawString("SCALE=" + (int)(scale * 100) + "%", new Font(Font, new FontStyle()), new HatchBrush(HatchStyle.Shingle, Color.Black), 0, 0);
            if (checkBox3.Checked)
            {
                int step = trackBar2.Value;
                for (int i = 0; i < pictureBox1.Height; i += step)
                {
                    for (int k = 0; k < pictureBox1.Width; k += step)
                    {
                        field temp = null;

                        obj a = new obj(new vector(k, i), new vector(0, 0), 1, true);
                        foreach (var o in objects)
                        {
                            double currForce  = gravity(a, o);
                            vector gravVector = new vector(a.pos.X - o.pos.X, a.pos.Y - o.pos.Y);
                            double angleX     = gravVector.X / gravVector.lenght();
                            double angleY     = gravVector.Y / gravVector.lenght();
                            a.force.X += currForce * angleX;
                            a.force.Y += currForce * angleY;


                            temp = new field(a.pos, a.force);
                            //Field.Add(temp);
                        }
                        pen = new Pen(Color.Green, 1);
                        if (temp != null)
                        {
                            gr.DrawLine(pen, (int)temp.B.X, (int)temp.B.Y,
                                        (int)temp.E.X + (int)temp.B.X, (int)temp.E.Y + (int)temp.B.Y);
                        }
                    }
                }

                //foreach (var field in Field)
                //{
                //}
            }
            foreach (var o in objects)
            {
                try
                {
                    //gr.DrawEllipse(new Pen(Color.Black, 3), (int)o.pos.X - o.mass / 2,
                    //    (int)o.pos.Y - o.mass / 2, o.mass, o.mass);

                    if (!checkBox4.Checked || (o.texture == null))
                    {
                        gr.DrawEllipse(new Pen(Color.Black, 3), (int)o.pos.X - o.mass / 2,
                                       (int)o.pos.Y - o.mass / 2, o.mass, o.mass);
                    }
                    else
                    {
                        gr.DrawImage(o.texture, (int)o.pos.X - o.mass / 2,
                                     (int)o.pos.Y - o.mass / 2);
                    }
                    if (checkBox2.Checked)
                    {
                        gr.DrawLine(new Pen(Color.Red, 2), (int)o.pos.X, (int)o.pos.Y,
                                    (int)(o.pos.X + o.speed.X), (int)(o.pos.Y + o.speed.Y));

                        gr.DrawLine(new Pen(Color.Blue, 2), (int)o.pos.X, (int)o.pos.Y,
                                    (int)(o.pos.X + o.force.X), (int)(o.pos.Y + o.force.Y));
                    }
                    if (checkBox1.Checked && o.avalible)
                    {
                        gr.DrawString(o.ToString(), Font, new HatchBrush(HatchStyle.Shingle, Color.Black),
                                      (float)o.pos.X + o.mass / 2,
                                      (float)o.pos.Y - o.mass / 2);
                    }
                }
                catch (Exception)
                {
                }
            }
            pictureBox1.Invalidate();
            pictureBox1.Update();
        }
예제 #2
0
파일: Form1.cs 프로젝트: gogasan24ru/oho1.1
 public field(vector b, vector e)
 {
     B = b;
     E = e;
 }
예제 #3
0
파일: Form1.cs 프로젝트: gogasan24ru/oho1.1
        private void processObjects()
        {
            objects.RemoveAll(a => !a.avalible);
            if (objects.Count == 0)
            {
                button3_Click(new object(), new EventArgs());
            }
            Text = objects.Count.ToString();
            foreach (var o in objects)
            {
                vector force   = new vector(0, 0);
                var    another = objects.FindAll(a => a != o);
                foreach (var a in another)
                {
                    double currForce  = gravity(a, o);
                    vector gravVector = new vector(a.pos.X - o.pos.X, a.pos.Y - o.pos.Y);
                    double angleX     = gravVector.X / gravVector.lenght();
                    double angleY     = gravVector.Y / gravVector.lenght();
                    force.X += currForce * angleX;
                    force.Y += currForce * angleY;

                    double x        = a.pos.X - o.pos.X;
                    double y        = a.pos.Y - o.pos.Y;
                    double distance = Math.Sqrt(x * x + y * y);
                    //double modifier = 1.5;
                    if ((distance <= (a.mass + o.mass) / 2))
                    {
                        if (a.mass > o.mass)
                        {
                            o.avalible = false;
                            a.mass    += o.mass / 2;
                            if (a.textureIndex != -1)
                            {
                                a.texture = ResizeImg(imgs[a.textureIndex].image, a.mass, a.mass);
                            }
                            if (!a.fix)
                            {
                                a.speed.X = (o.mass * o.speed.X + a.mass * a.speed.X) / (a.mass + o.mass);
                                a.speed.Y = (o.mass * o.speed.Y + a.mass * a.speed.Y) / (a.mass + o.mass);
                            }
                        }
                        else
                        {
                            a.avalible = false;
                            o.mass    += a.mass / 2;
                            if (o.textureIndex != -1)
                            {
                                o.texture = ResizeImg(imgs[o.textureIndex].image, o.mass, o.mass);
                            }
                            if (!o.fix)
                            {
                                o.speed.X = (o.mass * o.speed.X + a.mass * a.speed.X) / (a.mass + o.mass);
                                o.speed.Y = (o.mass * o.speed.Y + a.mass * a.speed.Y) / (a.mass + o.mass);
                            }
                        }
                    }
                }
                double aX = force.X / o.mass;
                double aY = force.Y / o.mass;
                if (!o.fix)
                {
                    o.speed.X += aX * trackBar1.Value / 100;
                    o.speed.Y += aY * trackBar1.Value / 100;
                    o.pos.X   += o.speed.X * trackBar1.Value / 100;
                    o.pos.Y   += o.speed.Y * trackBar1.Value / 100;
                }

                o.force.X = force.X / 10;
                o.force.Y = force.Y / 10;
            }
        }