-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVectorExtensions.cs
More file actions
46 lines (38 loc) · 1.25 KB
/
Copy pathVectorExtensions.cs
File metadata and controls
46 lines (38 loc) · 1.25 KB
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
using CounterStrikeSharp.API.Modules.Utils;
public static class VectorExtensions
{
public static float VecLength2DSqr(this Vector vector)
{
return vector.X * vector.X + vector.Y * vector.Y;
}
//Scales a vector
public static Vector Scale(this Vector vector, float scalar)
{
float len = vector.Length();
return len == 0 ? vector : new Vector(vector.X * scalar / len, vector.Y * scalar / len, vector.Z * scalar / len);
}
public static Vector Clone(this Vector vector)
{
Vector vec = new()
{
X = vector.X,
Y = vector.Y,
Z = vector.Z
};
return vec;
}
public static Vector GetForwardVector(this QAngle vector)
{
float pitch = vector.X * (MathF.PI / 180f);
float yaw = vector.Y * (MathF.PI / 180f);
float cp = MathF.Cos(pitch);
float sp = MathF.Sin(pitch);
float cy = MathF.Cos(yaw);
float sy = MathF.Sin(yaw);
return new Vector(cp * cy, cp * sy, -sp);
}
public static float DistanceTo(Vector a, Vector b)
{
return (float)Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2) + Math.Pow(a.Z - b.Z, 2));
}
}