Пример #1
0
        private void btPrep_Click(object sender, EventArgs e)
        {
            int    i;
            double tmp, tmp2;
            float  ArraySize     = Convert.ToSingle(tbTimeInp.Text);
            var    checkedbutton = gbMovingBoundary.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked);

            a                   = 0;
            btPP.Enabled        = false;
            btConfigure.Enabled = false;
            plstArray.Clear();
            CoreEngine = new Game_Engine();
            if (cbGravity.Checked)
            {
                CoreEngine.Gravity = new Vector2(0, -1);
            }
            else
            {
                CoreEngine.Gravity = new Vector2(0, 0);
            }
            CoreEngine.K = (float)Convert.ToDouble(tbSpringK.Text);
            CoreEngine.Smoothing_radius = (float)Convert.ToDouble(tbSRadius.Text);
            CoreEngine.Initialise(200, 200, BmpConfig);
            plstArray.Add(new List <Particle>(CoreEngine.Plst));
            simDisplay1.Refresh();

            //do all calculations for simulation here
            for (i = 1; i <= ArraySize * 25; i++)
            {
                if (i > 25)
                {
                    switch (checkedbutton.Name)
                    {
                    //no movement of boundaries
                    case "rbNoMove":
                        break;

                    //pause for 2 seconds then move for 2 seconds
                    case "rbPauseMove":
                        if (i % 100 < 50)
                        {
                            move_stop = 0;
                        }
                        else
                        {
                            move_stop = 1;
                        }
                        break;

                    //start moving continuously after 1 second has passed
                    case "rbContMove":
                        move_stop = 1;
                        break;
                    }
                }

                //CoreEngine.CalculateSpringsForViscoelasticity(0.01f);
                CoreEngine.InitialisePlasticity();
                CoreEngine.CalculatePlasticity(0.01f);
                CoreEngine.CalculateBoundaryInteraction(0.01f);
                CoreEngine.CalculateDensity(0.01f);
                CoreEngine.CalculatePressureForce(0.01f);
                CoreEngine.UpdateParticleVelocityPosition(0.01f, move_stop);
                List <Particle> listp = new List <Particle>(CoreEngine.Plst.Select(c => c.Copy()));
                plstArray.Add(listp);
                tmp  = (ArraySize * 25);
                tmp2 = i / tmp;
                lblPrepUpdate.Text = string.Format("Performing Calculations:\n{0} particles\n({1:f}%)", listp.Count, tmp2 * 100);
                lblPrepUpdate.Refresh();
            }
            lblPrepUpdate.Text  = "Calculations Complete";
            btPP.Enabled        = true;
            btConfigure.Enabled = true;
            ready            = 1;
            lblSimReady.Text = "Simulation Ready";
        }
Пример #2
0
        private void btPrep_Click(object sender, EventArgs e)
        {
            int i;
            double tmp, tmp2;
            float ArraySize = Convert.ToSingle(tbTimeInp.Text);
            var checkedbutton = gbMovingBoundary.Controls.OfType<RadioButton>().FirstOrDefault(r => r.Checked);
            a = 0;
            btPP.Enabled = false;
            btConfigure.Enabled = false;
            plstArray.Clear();
            CoreEngine = new Game_Engine();
            if (cbGravity.Checked)
                CoreEngine.Gravity = new Vector2(0, -1);
            else
                CoreEngine.Gravity = new Vector2(0, 0);
            CoreEngine.K = (float)Convert.ToDouble(tbSpringK.Text);
            CoreEngine.Smoothing_radius = (float)Convert.ToDouble(tbSRadius.Text);
            CoreEngine.Initialise(200, 200, BmpConfig);
            plstArray.Add(new List<Particle>(CoreEngine.Plst));
            simDisplay1.Refresh();

            //do all calculations for simulation here
            for (i = 1; i <= ArraySize * 25; i++)
            {
                if (i > 25)
                    switch (checkedbutton.Name)
                    {
                        //no movement of boundaries
                        case "rbNoMove":
                            break;

                        //pause for 2 seconds then move for 2 seconds
                        case "rbPauseMove":
                            if (i % 100 < 50)
                                move_stop = 0;
                            else
                                move_stop = 1;
                            break;

                        //start moving continuously after 1 second has passed
                        case "rbContMove":
                            move_stop = 1;
                            break;
                    }

                //CoreEngine.CalculateSpringsForViscoelasticity(0.01f);
                CoreEngine.InitialisePlasticity();
                CoreEngine.CalculatePlasticity(0.01f);
                CoreEngine.CalculateBoundaryInteraction(0.01f);
                CoreEngine.CalculateDensity(0.01f);
                CoreEngine.CalculatePressureForce(0.01f);
                CoreEngine.UpdateParticleVelocityPosition(0.01f, move_stop);
                List<Particle> listp = new List<Particle>(CoreEngine.Plst.Select(c => c.Copy()));
                plstArray.Add(listp);
                tmp = (ArraySize * 25);
                tmp2 = i / tmp;
                lblPrepUpdate.Text = string.Format("Performing Calculations:\n{0} particles\n({1:f}%)", listp.Count, tmp2 * 100);
                lblPrepUpdate.Refresh();
            }
            lblPrepUpdate.Text = "Calculations Complete";
            btPP.Enabled = true;
            btConfigure.Enabled = true;
            ready = 1;
            lblSimReady.Text = "Simulation Ready";
        }