/
Helpers.cs
69 lines (61 loc) · 1.33 KB
/
Helpers.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
63
64
65
66
67
68
69
using System;
using GTA;
using GTA.Math;
namespace CommunityRaces
{
public static class Helpers
{
public static Vector3 RotationToDirection(Vector3 rotation)
{
var z = DegToRad(rotation.Z);
var x = DegToRad(rotation.X);
var num = Math.Abs(Math.Cos(x));
return new Vector3
{
X = (float)(-Math.Sin(z) * num),
Y = (float)(Math.Cos(z) * num),
Z = (float)Math.Sin(x)
};
}
public static Vector3 DirectionToRotation(Vector3 direction)
{
direction.Normalize();
var x = Math.Atan2(direction.Z, direction.Y);
var y = 0;
var z = -Math.Atan2(direction.X, direction.Y);
return new Vector3
{
X = (float)RadToDeg(x),
Y = (float)RadToDeg(y),
Z = (float)RadToDeg(z)
};
}
public static double DegToRad(double deg)
{
return deg * Math.PI / 180.0;
}
public static double RadToDeg(double deg)
{
return deg * 180.0 / Math.PI;
}
public static double BoundRotationDeg(double angleDeg)
{
var twoPi = (int)(angleDeg / 360);
var res = angleDeg - twoPi * 360;
if (res < 0) res += 360;
return res;
}
public static Model RequestModel(int hash, int limit = 1000)
{
var tmpModel = new Model(hash);
int counter = 0;
while (!tmpModel.IsLoaded && counter < limit)
{
tmpModel.Request();
Script.Yield();
counter++;
}
return tmpModel;
}
}
}