-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVec2Utils.cs
41 lines (32 loc) · 1.09 KB
/
Vec2Utils.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
using System.Numerics;
using System;
public static class Vec2Utils
{
public const float Rad2Deg = 180 / MathF.PI;
public const float Deg2Rad = MathF.PI / 180;
/// <summary>method <c>CastToIntVec</c> casts Vec2 values to integers, useful for keeping text sharp.</summary>
public static Vector2 CastToIntVec(Vector2 vec)
{
return new Vector2((int)vec.X, (int)vec.Y);
}
public static float GetAngle(Vector2 me, Vector2 target)
{
return 180 - MathF.Atan2(me.X - target.X, me.Y - target.Y);
//returnreturn Vector2.Normalize((me - target));
}
public static Vector2 CreateVec2(float x, float y)
{
return new Vector2(x,y);
}
/// <summary>method <c>GetDirection</c>gets direction to object.</summary>
public static Vector2 GetDirection(Vector2 me, Vector2 target)
{
float angle = GetAngle(me, target);
return new Vector2(MathF.Cos(angle * Rad2Deg), MathF.Sin(angle * Rad2Deg));
}
//have to do this cuz lua
public static float Length(Vector2 vec)
{
return vec.Length();
}
}