Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void drawLine(SpriteBatch spriteBatch, int x0, int y0, int x1, int y1, Color color)
- {
- int xlength = Math.Max(x0, x1) - Math.Min(x0, x1);
- int ylength = Math.Max(y0, y1) - Math.Min(y0, y1);
- double length = Math.Sqrt(xlength * xlength + ylength * ylength);
- float angle;
- if (x0 > x1 & y0 > y1)
- {
- angle = (float)Math.Acos(xlength / length) + MathHelper.ToRadians(180);
- }
- else if (x0 < x1 & y0 > y1)
- {
- angle = (float)Math.Asin(-ylength / length);
- }
- else if (x0 > x1 & y0 < y1)
- {
- angle = (float)Math.Acos(-xlength / length);
- }
- else if (x0 < x1 & y0 < y1)
- {
- angle = (float)Math.Asin(ylength / length);
- }
- else if (x0 < x1 & y0 == y1)
- {
- angle = MathHelper.ToRadians(0);
- }
- else if(x0 > x1 & y0 == y1)
- {
- angle = MathHelper.ToRadians(180);
- }
- else if(x0 == x1 & y0 > y1)
- {
- angle = MathHelper.ToRadians(270);
- }
- else if (x0 == x1 & y0 < y1)
- {
- angle = MathHelper.ToRadians(90);
- }
- else
- {
- angle = 0;
- }
- spriteBatch.Draw(pixel1x1, new Vector2(x0, y0), null, color, angle, new Vector2(0, 0), new Vector2((int)length, 1), SpriteEffects.None, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement