Beispiel #1
0
        internal void GenerateElectrons()
        {
            electrons.Clear();
            int cur = 8;
            int l   = 0;

            for (int i = 0; i < DrawPath.Count - 1; i++)
            {
                l = (int)(DrawPath[i + 1] - DrawPath[i]).Length();
                while (cur < l)
                {
                    Electron e = new Electron();
                    e.curind    = i;
                    e.lerpSpeed = 1.0f / l;
                    e.lerpState = (float)cur / l;
                    electrons.Add(e);
                    cur += ElectronFrequency;
                }
                cur -= l;
            }
        }
Beispiel #2
0
        internal void StepElectrons()
        {
            if (parent.ID == 189)
            {
                int asf = 0;
            }
            Wire  p   = parent as Wire;
            float mul = Math.Sign(p.J2.Voltage - p.J1.Voltage);

            if (mul == 0)
            {
                return;
            }

            //update
            for (int i = 0; i < electrons.Count; i++)
            {
                electrons[i].lerpState += electrons[i].lerpSpeed * mul;
                if (electrons[i].lerpState < 0)
                {
                    if (electrons[i].curind == 0)
                    {
                        electrons.RemoveAt(i--);
                    }
                    else
                    {
                        //get overshot distance
                        int l = (int)(Vector2.Lerp(DrawPath[electrons[i].curind], DrawPath[electrons[i].curind + 1], electrons[i].lerpState) -
                                      DrawPath[electrons[i].curind]).Length();

                        electrons[i].curind--;
                        float tl = (DrawPath[electrons[i].curind + 1] - DrawPath[electrons[i].curind]).Length();
                        electrons[i].lerpState = (tl - l) / tl;
                        electrons[i].lerpSpeed = 1.0f / tl;
                    }
                }
                else if (electrons[i].lerpState > 1)
                {
                    if (electrons[i].curind == DrawPath.Count - 2)
                    {
                        electrons.RemoveAt(i--);
                    }
                    else
                    {
                        //get overshot distance
                        int l = (int)(Vector2.Lerp(DrawPath[electrons[i].curind], DrawPath[electrons[i].curind + 1], electrons[i].lerpState) -
                                      DrawPath[electrons[i].curind + 1]).Length();

                        electrons[i].curind++;
                        float tl = (DrawPath[electrons[i].curind + 1] - DrawPath[electrons[i].curind]).Length();
                        electrons[i].lerpState = l / tl;
                        electrons[i].lerpSpeed = 1.0f / tl;
                    }
                }
            }

            //add
            float ll = (DrawPath[1] - DrawPath[0]).Length();

            if (electrons[0].curind != 0 || electrons[0].lerpState > (float)ElectronFrequency / ll)
            {
                Electron e = new Electron();
                e.curind    = 0;
                e.lerpSpeed = 1.0f / ll;
                //e.lerpState = electrons[0].lerpState - (float)ElectronFrequency / ll;
                e.lerpState = 0f;
                electrons.Insert(0, e);
            }
            ll = (DrawPath[DrawPath.Count - 1] - DrawPath[DrawPath.Count - 2]).Length();
            if (electrons[electrons.Count - 1].curind != DrawPath.Count - 2 || electrons[electrons.Count - 1].lerpState < (ll - (float)ElectronFrequency) / ll)
            {
                Electron e = new Electron();
                e.curind    = DrawPath.Count - 2;
                e.lerpSpeed = 1.0f / ll;
                //e.lerpState = electrons[electrons.Count - 1].lerpState + (float)ElectronFrequency / ll;
                e.lerpState = 1.0f;
                electrons.Add(e);
            }
        }
Beispiel #3
0
        internal void StepElectrons()
        {
            if (parent.ID == 189)
            {
                int asf = 0;
            }
            Wire p = parent as Wire;
            float mul = Math.Sign(p.J2.Voltage - p.J1.Voltage);
            if (mul == 0)
                return;

            //update
            for (int i = 0; i < electrons.Count; i++)
            {
                electrons[i].lerpState += electrons[i].lerpSpeed * mul;
                if (electrons[i].lerpState < 0)
                {
                    if (electrons[i].curind == 0)
                        electrons.RemoveAt(i--);
                    else
                    {
                        //get overshot distance
                        int l = (int)(Vector2.Lerp(DrawPath[electrons[i].curind], DrawPath[electrons[i].curind + 1], electrons[i].lerpState) -
                            DrawPath[electrons[i].curind]).Length();

                        electrons[i].curind--;
                        float tl = (DrawPath[electrons[i].curind + 1] - DrawPath[electrons[i].curind]).Length();
                        electrons[i].lerpState = (tl - l) / tl;
                        electrons[i].lerpSpeed = 1.0f / tl;
                    }
                }
                else if (electrons[i].lerpState > 1)
                {
                    if (electrons[i].curind == DrawPath.Count - 2)
                        electrons.RemoveAt(i--);
                    else
                    {
                        //get overshot distance
                        int l = (int)(Vector2.Lerp(DrawPath[electrons[i].curind], DrawPath[electrons[i].curind + 1], electrons[i].lerpState) -
                            DrawPath[electrons[i].curind + 1]).Length();

                        electrons[i].curind++;
                        float tl = (DrawPath[electrons[i].curind + 1] - DrawPath[electrons[i].curind]).Length();
                        electrons[i].lerpState = l / tl;
                        electrons[i].lerpSpeed = 1.0f / tl;
                    }
                }
            }

            //add
            float ll = (DrawPath[1] - DrawPath[0]).Length();
            if (electrons[0].curind != 0 || electrons[0].lerpState > (float)ElectronFrequency / ll)
            {
                Electron e = new Electron();
                e.curind = 0;
                e.lerpSpeed = 1.0f / ll;
                //e.lerpState = electrons[0].lerpState - (float)ElectronFrequency / ll;
                e.lerpState = 0f;
                electrons.Insert(0, e);
            }
            ll = (DrawPath[DrawPath.Count - 1] - DrawPath[DrawPath.Count - 2]).Length();
            if (electrons[electrons.Count - 1].curind != DrawPath.Count - 2 || electrons[electrons.Count - 1].lerpState < (ll - (float)ElectronFrequency) / ll)
            {
                Electron e = new Electron();
                e.curind = DrawPath.Count - 2;
                e.lerpSpeed = 1.0f / ll;
                //e.lerpState = electrons[electrons.Count - 1].lerpState + (float)ElectronFrequency / ll;
                e.lerpState = 1.0f;
                electrons.Add(e);
            }
        }
Beispiel #4
0
 internal void GenerateElectrons()
 {
     electrons.Clear();
     int cur = 8;
     int l = 0;
     for (int i = 0; i < DrawPath.Count - 1; i++)
     {
         l = (int)(DrawPath[i + 1] - DrawPath[i]).Length();
         while (cur < l)
         {
             Electron e = new Electron();
             e.curind = i;
             e.lerpSpeed = 1.0f / l;
             e.lerpState = (float)cur / l;
             electrons.Add(e);
             cur += ElectronFrequency;
         }
         cur -= l;
     }
 }