示例#1
0
        //public void CheckOverlap()
        //{
        //	List<Thing2> list = new List<Thing2>();

        //	foreach ( Thing2 t in myField.things )
        //	{
        //		if ( t == this )
        //			continue;

        //		double dist = this.CalculateSpaceBetween( t );
        //		if ( dist < 0 )
        //			list.Add( t );
        //	}

        //	if ( list.Count > 0 )
        //	{
        //		list.Add( this );
        //		myField.ScheduleCombine( list );
        //	}

        //}


        //public decimal CalculateOptimalDeltaT()
        //{
        //	if ( velocity.Length() == 0 )
        //		return Decimal.MaxValue;

        //	return (decimal)(size / velocity.Length());
        //}


        public double CalculateSpaceBetween(Thing2 t2)
        {
            double dist = Location2d.Distance(location, t2.location);

            dist -= size;
            dist -= t2.size;

            return(dist);
        }
示例#2
0
        public Vector2d CalculateForce(Thing2 t)
        {
            if (t != this.a && t != this.b)
            {
                return(new Vector2d(0.0, 0.0));
            }

            double dist = Location2d.Distance(this.a.location, this.b.location);

            Thing2 ot = (t == this.a) ? this.b : this.a;

            Vector2d force = new Vector2d(t.location, ot.location);

            force.Normalize();

            force *= dist * k;

            return(force);
        }
示例#3
0
 public void Attach(Thing2 thing, Orientation orientation)
 {
     if (orientation == Orientation.A)
     {
         // A
         if (this.a != null)
         {
             this.a.DetachRezinochka(this);
         }
         this.a = thing;
         this.a.AttachRezinochka(this);
     }
     else
     {
         // B
         if (this.b != null)
         {
             this.a.DetachRezinochka(this);
         }
         this.b = thing;
         this.b.AttachRezinochka(this);
     }
 }
示例#4
0
        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()