Advertisement
Guest User

Insec

a guest
Jul 1st, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using LeagueSharp;
  8. using SharpDX;
  9. using System.Drawing;
  10. using LeagueSharp.Common;
  11.  
  12. namespace MasterOfInsec
  13. {
  14.     using static Drawing;
  15.  
  16.     class Polygon
  17.     {
  18.         public List<Vector2> Points = new List<Vector2>();
  19.  
  20.         public Polygon()
  21.         {
  22.         }
  23.  
  24.         public Polygon(List<Vector2> P)
  25.         {
  26.             Points = P;
  27.         }
  28.  
  29.         public void add(Vector2 vec)
  30.         {
  31.             Points.Add(vec);
  32.         }
  33.  
  34.         public int Count()
  35.         {
  36.             return Points.Count;
  37.         }
  38.  
  39.         public Vector2 getProjOnPolygon(Vector2 vec)
  40.         {
  41.             Vector2 closest = new Vector2(-1000, -1000);
  42.             Vector2 start = Points[Count() - 1];
  43.             foreach (Vector2 vecPol in Points)
  44.             {
  45.                 Vector2 proj = projOnLine(start, vecPol, vec);
  46.                 closest = ClosestVec(proj, closest, vec);
  47.                 start = vecPol;
  48.             }
  49.             return closest;
  50.         }
  51.  
  52.         public Vector2 ClosestVec(Vector2 vec1, Vector2 vec2, Vector2 to)
  53.         {
  54.             float dist1 = Vector2.DistanceSquared(vec1, to);//133
  55.             float dist2 = Vector2.DistanceSquared(vec2, to);//12
  56.             return (dist1 > dist2) ? vec2 : vec1;
  57.         }
  58.  
  59.         public void Draw(System.Drawing.Color color, int width = 1)
  60.         {
  61.             for (var i = 0; i <= Points.Count - 1; i++)
  62.             {
  63.                 if (Points[i].Distance(MasterOfInsec.Program.Player.Position) < 1500)
  64.                 {
  65.                     var nextIndex = (Points.Count - 1 == i) ? 0 : (i + 1);
  66.                     var from = WorldToScreen(Points[i].To3D());
  67.                     var to = WorldToScreen(Points[nextIndex].To3D());
  68.                     DrawLine(from[0], from[1], to[0], to[1], width, color:;
  69.                 }
  70.             }
  71.         }
  72.  
  73.         private Vector2 projOnLine(Vector2 v, Vector2 w, Vector2 p)
  74.         {
  75.             Vector2 nullVec = new Vector2(-1, -1);
  76.             // Return minimum distance between line segment vw and point p
  77.             float l2 = Vector2.DistanceSquared(v, w);  // i.e. |w-v|^2 -  avoid a sqrt
  78.             if (l2 == 0.0)
  79.                 return nullVec;   // v == w case
  80.             // Consider the line extending the segment, parameterized as v + t (w - v).
  81.             // We find projection of point p onto the line.
  82.             // It falls where t = [(p-v) . (w-v)] / |w-v|^2
  83.             float t = Vector2.Dot(p - v, w - v) / l2;
  84.             if (t < 0.0)
  85.                 return nullVec;       // Beyond the 'v' end of the segment
  86.             else if (t > 1.0)
  87.                 return nullVec;  // Beyond the 'w' end of the segment
  88.             Vector2 projection = v + t * (w - v);  // Projection falls on the segment
  89.             return projection;
  90.         }
  91.  
  92.     }
  93.  
  94.     internal class Program
  95.     {
  96.         internal class Player
  97.         {
  98.             public static Vector2 Position { get; set; }
  99.         }
  100.     }
  101. }
  102.  
  103. namespace System.Drawing
  104. {
  105.     internal class Color
  106.     {
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement