Exemple #1
0
        void ProgObstacle()
        {
            while (true)
            {
                for (int i = 0; i < Omgr.Count; i++)
                {
                    double   distance;
                    Obstacle obstacle = Omgr.At(i);

                    Vect2D vect = GetVectorToTarget(obstacle.pos, 0);
                    rb.SetV(0);
                    TurnAbsAngle(vect.GetPhiGrad(), 5);

                    do
                    {
                        double dPhi = GetRelAngle(vect.GetPhiGrad()) / 10;
                        rb.Set_dPhi(dPhi);
                        rb.SetV(5);

                        WaitForUpdate();

                        distance = vect.VectLength();
                        vect     = GetVectorToTarget(obstacle.pos, 0);
                    }while (vect.VectLength() < distance);
                }

                WaitForUpdate();
            }
        }
Exemple #2
0
 // rotate picture (Vector-Graphic) of the Robot by aRot
 // aRot should be a Unit-Vector
 void Rotate(Vect2D aRot)
 {
     for (int i = 0; i < _relPoints.Length; i++)
     {
         _relPoints[i].CoMultTo(aRot);
     }
 }
Exemple #3
0
        Vect2D GetVectorToTarget(Vect2D target, double keepDistance)
        {
            double deltaX   = target.X - rb.Pos.X;
            double deltaY   = target.Y - rb.Pos.Y;
            double distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
            double factor   = (distance - keepDistance) / distance;

            return(new Vect2D(deltaX * factor, deltaY * factor, false));
        }
Exemple #4
0
        void SetFollow(Vect2D target, double keepDistance, double speedFactor)
        {
            Vect2D vect = GetVectorToTarget(target, keepDistance);

            double dPhi = GetRelAngle(vect.GetPhiGrad()) * speedFactor * 2;
            double v    = vect.VectLength() * speedFactor;

            if (v < speedFactor * 1.1)
            {
                dPhi = v = 0;
            }

            rb.Set_dPhi(dPhi);
            rb.SetV(v);
        }
Exemple #5
0
        void DriveDistance(double aPow, double aDist)
        {
            rb.SetV(aPow); // Motoren ein
            Vect2D start = rb.Pos;

            while (true)
            {
                // Warten bis die Simulation eine neue Pos berchnet hat
                WaitForUpdate();
                if (start.DistBetweenPoints(rb.Pos) > aDist)
                {
                    break;
                }
            }
            rb.SetV(0); // Motoren aus
        }
Exemple #6
0
 public void UpdatePath()
 {
     if (!showPath)
     {
         return;
     }
     if (Pos.DistBetweenPoints(_oldPos) < 10)
     {
         return;
     }
     _oldPos = Pos;
     if (_path.Count > 50)
     {
         _path.RemoveLast();
     }
     _path.AddFirst(Pos.AsPoint);
 }
Exemple #7
0
 // Bring Positions outside of ScPanel back into ScPanel
 // Pos > Xmax => Xmin; Pos < Xmin = > Xmax ......
 public void CorrigatePosition(ref Vect2D aPos)
 {
     if (aPos.X < -20)
     {
         aPos.X = Width;
     }
     if (aPos.X > Width + 20)
     {
         aPos.X = 0;
     }
     if (aPos.Y < -5)
     {
         aPos.Y = Height;
     }
     if (aPos.Y > Height + 20)
     {
         aPos.Y = 0;
     }
 }
Exemple #8
0
 public void Initialize(Vect2D<int> ind, SushiVersion version,Sprite cellSprite)
 {
     index = ind;
     sushiVersion = version;
     GetComponent<SpriteRenderer>().sprite = cellSprite;
 }