Beispiel #1
0
 public void Update(Vector2 suPos)
 {
     _angle += 0.05f;
     if (_angle > Math.PI * 2)
     {
         _angle = 0f;
     }
     _radarPoints.Update(_angle);
     {
         Map.MapPoint collisionPoint = _map.RdarDetection(suPos, RADAR_RANGE, _angle);
         if (collisionPoint.GetID() != -1)
         {
             _radarPoints.SetPoint(_angle, collisionPoint.GetPos() / RADAR_RANGE * RADAR_DISPLAY_RAD, collisionPoint.GetID());
         }
     }
 }
Beispiel #2
0
        public Map.MapPoint Collision(Vector2 pos, Vector2 direction) //return first Collision Point between strahl and Iland, direction.Length is importend
        {
            pos -= _position;                                         //transform Koordinatensystem, now cenmter iland is center
            float minAngle = VecAngle(pos);
            float maxAngle = VecAngle(pos + direction);
            bool  maxLoMin = maxAngle < minAngle;       //wenn min > max

            int i = 0;

            Map.MapPoint mapPoint;
            Vector2      interceptPoint = Vector2.Zero;
            Vector2      nerstPoint     = direction; //point wih largest distance
            Vector2      delta          = new Vector2(0, 0);

            do
            {
                delta          = _corner[i == 0 ? _corner.Length - 1 : i - 1] - _corner[i];
                interceptPoint = Map_Radar.Algebra.Intercept(_corner[i], delta, pos, direction);
                if (interceptPoint != Vector2.Zero)
                {
                    if ((interceptPoint - pos).Length() < nerstPoint.Length())
                    {
                        nerstPoint = interceptPoint;
                    }
                }
                i++;
            } while (i < _corner.Length);

            if (nerstPoint != direction)
            {
                mapPoint = new Map.MapPoint(_id, nerstPoint - pos);
            }
            else
            {
                mapPoint = new Map.MapPoint();
            }
            return(mapPoint);
        }