Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. public void drawLine(SpriteBatch spriteBatch, int x0, int y0, int x1, int y1, Color color)
  2.         {
  3.             int xlength = Math.Max(x0, x1) - Math.Min(x0, x1);
  4.             int ylength = Math.Max(y0, y1) - Math.Min(y0, y1);
  5.             double length = Math.Sqrt(xlength * xlength + ylength * ylength);
  6.             float angle;
  7.             if (x0 > x1 & y0 > y1)
  8.             {
  9.                 angle = (float)Math.Acos(xlength / length) + MathHelper.ToRadians(180);
  10.             }
  11.             else if (x0 < x1 & y0 > y1)
  12.             {
  13.                 angle = (float)Math.Asin(-ylength / length);
  14.             }
  15.             else if (x0 > x1 & y0 < y1)
  16.             {
  17.                 angle = (float)Math.Acos(-xlength / length);
  18.             }
  19.             else if (x0 < x1 & y0 < y1)
  20.             {
  21.                 angle = (float)Math.Asin(ylength / length);
  22.             }
  23.             else if (x0 < x1 & y0 == y1)
  24.             {
  25.                 angle = MathHelper.ToRadians(0);
  26.             }
  27.             else if(x0 > x1 & y0 == y1)
  28.             {
  29.                 angle = MathHelper.ToRadians(180);
  30.             }
  31.             else if(x0 == x1 & y0 > y1)
  32.             {
  33.                 angle = MathHelper.ToRadians(270);
  34.             }
  35.             else if (x0 == x1 & y0 < y1)
  36.             {
  37.                 angle = MathHelper.ToRadians(90);
  38.             }
  39.             else
  40.             {
  41.                 angle = 0;
  42.             }
  43.             spriteBatch.Draw(pixel1x1, new Vector2(x0, y0), null, color, angle, new Vector2(0, 0), new Vector2((int)length, 1), SpriteEffects.None, 0);
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement