-
Notifications
You must be signed in to change notification settings - Fork 0
/
Draw.cs
62 lines (52 loc) · 2.06 KB
/
Draw.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace Monogame1
{
public class Draw
{
private SpriteBatch spritebatch;
public SpriteBatch SpriteBatch {
get {
return this.spritebatch;
}
set { }
}
public Draw(SpriteBatch spriteBatch)
{
this.spritebatch = spriteBatch;
}
public void FillCircle(float radius, Vector2 Mid, Color color, Texture2D Texture)
{
for (int i = 0; i <= 360; i++)
{
float rad = Geometry.AngleToRadian(i);
var point = Geometry.VectorRotation(rad, radius);
DrawLine(Texture, Mid, new Vector2(point.X + Mid.X, point.Y + Mid.Y), color, 1f);
}
}
public void DrawCircle(Vector2 Mid, float Radius, Color color, Texture2D Texture)
{
for (float i = 0; i <= 360f; i += 0.5f)
{
float rad1 = Geometry.AngleToRadian(i);
float rad2 = Geometry.AngleToRadian(i + 0.5f);
float x1 = (float)Math.Cos(rad1) * Radius;
float y1 = (float)Math.Sin(rad1) * Radius;
float x2 = (float)Math.Cos(rad2) * Radius;
float y2 = (float)Math.Sin(rad2) * Radius;
Vector2 point1 = new Vector2(x1 + Mid.X, y1 + Mid.Y);
Vector2 point2 = new Vector2(x2 + Mid.X, y2 + Mid.Y);
DrawLine(Texture, point1, point2, color, 1f);
}
}
public void DrawLine(Texture2D texture, Vector2 Vec1, Vector2 Vec2, Color color, float scale)
{
spritebatch.Draw(texture, Vec1, null, color,
(float)Math.Atan2(Vec2.Y - Vec1.Y, Vec2.X - Vec1.X),
new Vector2(0f, (float)texture.Height / 2),
new Vector2(Vector2.Distance(Vec1, Vec2), scale),
SpriteEffects.None, 0f);
}
}
}