Ejemplo n.º 1
0
        private void CalcData()
        {
            if (!isLoaded)
            {
                return;
            }
            Random r  = new Random(GLOBALS.SEED);
            double sm = 0;
            double ss = 0;

            for (var i = 0; i < GLOBALS.SUNS_NUM; i++)
            {
                var o = new obj(i, this.Width, this.Height, r, true);
                sm += o.m;
                ss += o.speed();
            }
            double mom = 0;

            for (var i = GLOBALS.SUNS_NUM; i < GLOBALS.NUM_OBJECTS + GLOBALS.SUNS_NUM; i++)
            {
                var o = new obj(i, this.Width, this.Height, r);
                sm += o.m;
                mom = o.m > mom ? o.m : mom;
                ss += o.speed();
            }

            lblMass.Text     = sm.ToString("0,#.###");
            lblMomentum.Text = (sm * ss).ToString("0,#.###");
            lblObjMass.Text  = mom.ToString("0,#.###");
        }
Ejemplo n.º 2
0
        public SolarSystem()
        {
            InitializeComponent();
            this.Width          = Screen.PrimaryScreen.WorkingArea.Width;
            this.Height         = Screen.PrimaryScreen.WorkingArea.Height;
            this.DoubleBuffered = true;

            aTimer          = new System.Timers.Timer(1000 / GLOBALS.FPS);
            aTimer.Elapsed += aTimer_Elapsed;

            Random r = new Random(GLOBALS.SEED);

            for (var i = 0; i < GLOBALS.SUNS_NUM; i++)
            {
                var o = new obj(i, this.Width, this.Height, r, true);
                _objects.Add(o);
            }
            for (var i = GLOBALS.SUNS_NUM; i < GLOBALS.NUM_OBJECTS + GLOBALS.SUNS_NUM; i++)
            {
                var o = new obj(i, this.Width, this.Height, r);
                _objects.Add(o);
            }

            aTimer.Enabled = true;

            _center.set(this.Width / 2, this.Height / 2, (this.Width + this.Height) / 2);
        }
Ejemplo n.º 3
0
        public double distance(obj o)
        {
            double dx = this.p.x - o.p.x;
            double dy = this.p.y - o.p.y;
            double dz = this.p.z - o.p.z;

            return(Math.Sqrt(dx * dx + dy * dy + dz * dz));
        }
Ejemplo n.º 4
0
        public void acc(obj o)
        {
            var d = this.distance(o);

            var force = GLOBALS.GRAVITY * this.m * o.m / Math.Pow(d, 3);

            var accelThis = force / this.m;
            var accelThat = force / o.m;

            double dx = this.p.x - o.p.x;
            double dy = this.p.y - o.p.y;
            double dz = this.p.z - o.p.z;

            this.v.x -= accelThis * dx;
            this.v.y -= accelThis * dy;
            this.v.z -= accelThis * dz;

            o.v.x += accelThat * dx;
            o.v.y += accelThat * dy;
            o.v.z += accelThat * dz;
        }
Ejemplo n.º 5
0
        public bool isCollided(obj o)
        {
            double dx = this.p.x - o.p.x;
            double dy = this.p.y - o.p.y;
            double dz = this.p.z - o.p.z;
            var    d  = dx * dx + dy * dy + dz * dz;

            if (Math.Abs(d) - (this.r + o.r) <= (this.r + o.r) * GLOBALS.COLLISION_THRESHOLD)
            {
                //new mass
                var mass = this.m + o.m;
                this.m += o.m;
                this.r  = Math.Log10(m);
                //find biggest
                //var oo = (this.m > o.m) ? this : o;
                //biggest takes mass
                //oo.m = mass;
                //oo.r = Math.Log10( m );

                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            var m = new List <obj>();

            if (IsMouseDown)
            {
                return;
            }
            FindAndCenter(e);
            iYears++;

            for (var i = 0; i < _objects.Count; i++)
            {
                var oi = _objects[i];
                if (m.Contains(oi))
                {
                    continue;
                }

                //if ( i != 0 && Math.Abs( _objects[i].v.x ) < 0.1 )
                //    MessageBox.Show( "why?" );
                if (i > 0 && oi.isStray())
                {
                    if (!GLOBALS.RESPAWN)
                    {
                        m.Add(oi);
                    }
                    else
                    {
                        _objects[i] = new obj(i, this.Width, this.Height, new Random(GLOBALS.SEED), false);
                    }
                }
                else
                {
                    /*acc*/
                    for (var j = i + 1; j < _objects.Count; j++)
                    {
                        var oj = _objects[j];
                        if (!oi.isCollided(oj))
                        {
                            oi.acc(oj);
                        }
                        else
                        {
                            var oo = (oi.m < oj.m) ? oi : oj; //smallest goes
                            m.Add(oo);
                            var d  = (float)(oo.r * 10);      //smallest times 10, size of explosion
                            var np = new Pen(Color.FromArgb(255, GLOBALS.EXPLOSION_RING.Color.R, GLOBALS.EXPLOSION_RING.Color.G, GLOBALS.EXPLOSION_RING.Color.B), 1);
                            oo.Ellipse(e, GLOBALS.EXPLOSION_INNER, np, (float)oo.p.x - d / 2, (float)oo.p.y - d / 2, d);
                        }
                    }

                    oi.move();
                    oi.friction();
                }

                oi.draw(e);
            }
            foreach (var o in m)
            {
                _objects.Remove(o);
            }

            WriteStats();
        }