//private void CheckBounds() //{ // double left = size; // double right = myField.size.Width - size; // double top = size; // double bottom = myField.size.Height - size; // // x // if ( location.x < left ) // { // location.x = left - (location.x-left); // velocity.i = -velocity.i; // } // else if ( location.x >= right ) // { // location.x = (right) - (location.x-right); // velocity.i = -velocity.i; // } // // y // if ( location.y < top ) // { // location.y = top - (location.y-top); // velocity.j = -velocity.j; // } // else if ( location.y >= (bottom) ) // { // location.y = (bottom) - (location.y-bottom); // velocity.j = -velocity.j; // } //} //public Thing2 MakeCopy() //{ // Thing2 copy = new Thing2(); // copy.id = this.id; // copy.location = new Location2d( this.location ); // copy.velocity = new Velocity2d( this.velocity ); // copy.size = this.size; // copy.color = Color.FromArgb( this.color.ToArgb() ); // return copy; //} //public static Thing2 Combine( List<Thing2> list ) //{ // if ( list.Count < 2 ) // throw new PhysicsException( "Combine called with <2 items. This does not make sense." ); // AveragerUtil massA = new AveragerUtil(); // AveragerUtil colorR = new AveragerUtil(); // AveragerUtil colorG = new AveragerUtil(); // AveragerUtil colorB = new AveragerUtil(); // AveragerUtil locXM = new AveragerUtil(); // AveragerUtil locYM = new AveragerUtil(); // AveragerUtil velIM = new AveragerUtil(); // AveragerUtil velJM = new AveragerUtil(); // foreach ( Thing2 t in list ) // { // massA.AddMeasurement( t.Mass ); // colorR.AddMeasurement( t.color.R ); // colorG.AddMeasurement( t.color.G ); // colorB.AddMeasurement( t.color.B ); // locXM.AddMeasurement( t.location.x * t.Mass ); // locYM.AddMeasurement( t.location.y * t.Mass ); // velIM.AddMeasurement( t.velocity.i * t.Mass ); // velJM.AddMeasurement( t.velocity.j * t.Mass ); // } // // mass // double size = Math.Sqrt( massA.Sum / Math.PI ); // // color // Color color = Color.FromArgb( (int)colorR.Average, (int)colorG.Average, (int)colorB.Average ); // // location // Location2d loc = new Location2d( locXM.Sum / massA.Sum, locYM.Sum / massA.Sum ); // // velocity // Velocity2d vel = new Velocity2d( velIM.Sum / massA.Sum, velJM.Sum / massA.Sum ); // return new Thing2( list[0].myField, loc, vel, size ); //} public void AttachRezinochka(Rezinochka rezinochka) { if (this.rezinochki.Contains(rezinochka)) { throw new ArgumentException("Rezinochka is already attached to this Thing2"); } this.rezinochki.Add(rezinochka); }
public void DetachRezinochka(Rezinochka rezinochka) { if (!this.rezinochki.Contains(rezinochka)) { throw new ArgumentException("Rezinochka is not attached to this Thing2"); } bool ok = this.rezinochki.Remove(rezinochka); if (!ok) { throw new ArgumentException("Error while detaching Rezinochka from this Thing2"); } }
public void InitItems(int nrThings) { Random r = new Random(); int nrThingsDiscarded = 0; // make things for (int i = 0; i < nrThings;) { double rr = r.NextDouble(); double thingSize = rr * (GlobalConfig.sizeMax - GlobalConfig.sizeMin) + GlobalConfig.sizeMin; // location double left = this.Viewport.Left + thingSize; double right = this.Viewport.Right - thingSize; double top = this.Viewport.Top + thingSize; double bottom = this.Viewport.Bottom - thingSize; double x = r.NextDouble() * (right - left) + left; double y = r.NextDouble() * (bottom - top) + top; Location2d location = new Location2d(x, y); // check for overlap with previous things bool foundOverlap = false; foreach (Thing2 t in things) { double dist = t.CalculateSpaceBetween(location, thingSize); if (dist < 0) { foundOverlap = true; break; } } if (foundOverlap) { nrThingsDiscarded++; continue; } Velocity2d velocity = new Velocity2d(0.0, 0.0); // make the thing Thing2 thing = new Thing2(this, location, velocity, thingSize); things.Add(thing); i++; } Util.Logger.AddMessage("Nr things discarded: " + nrThingsDiscarded); // add rezinochki for (int idThing = 0; idThing < things.Count - 1; idThing += 2) { Thing2 ta = this.things[idThing]; Thing2 tb = this.things[idThing + 1]; Rezinochka rez = new Rezinochka(Color.LightYellow, 1.0); rez.Attach(ta, Rezinochka.Orientation.A); rez.Attach(tb, Rezinochka.Orientation.B); this.rezinochki.Add(rez); } } //InitItems()