-
Notifications
You must be signed in to change notification settings - Fork 78
/
Quaternion.cs
69 lines (57 loc) · 1.89 KB
/
Quaternion.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.Native;
namespace MapEditor
{
public class Quaternion
{
public float X;
public float Y;
public float Z;
public float W;
public static void SetEntityQuaternion(Entity ent, Quaternion q)
{
Function.Call(Hash.SET_ENTITY_QUATERNION, ent.Handle, q.X, q.Y, q.Z, q.W);
}
public static void SetEntityQuaternion(Entity ent, GTA.Math.Quaternion q)
{
Function.Call(Hash.SET_ENTITY_QUATERNION, ent.Handle, q.X, q.Y, q.Z, q.W);
}
public static Quaternion GetEntityQuaternion(Entity e)
{
var xg = new OutputArgument();
var yg = new OutputArgument();
var zg = new OutputArgument();
var wg = new OutputArgument();
Function.Call(Hash.GET_ENTITY_QUATERNION, e.Handle, xg, yg, zg, wg);
return new Quaternion()
{
X = xg.GetResult<float>(),
Y = yg.GetResult<float>(),
Z = zg.GetResult<float>(),
W = wg.GetResult<float>()
};
}
public static Quaternion RotationYawPitchRoll(float pitch, float roll, float yaw)
{
Quaternion result = new Quaternion();
pitch = (float)VectorExtensions.DegToRad(pitch);
roll = (float)VectorExtensions.DegToRad(roll);
yaw = (float)VectorExtensions.DegToRad(yaw);
float halfRoll = roll*0.5f;
float sinRoll = (float) Math.Sin((double) halfRoll);
float cosRoll = (float) Math.Cos((double) halfRoll);
float halfPitch = pitch*0.5f;
float sinPitch = (float) Math.Sin((double) halfPitch);
float cosPitch = (float) Math.Cos((double) halfPitch);
float halfYaw = yaw*0.5f;
float sinYaw = (float) Math.Sin((double) halfYaw);
float cosYaw = (float) Math.Cos((double) halfYaw);
result.X = (cosYaw*sinPitch*cosRoll) + (sinYaw*cosPitch*sinRoll);
result.Y = (sinYaw*cosPitch*cosRoll) - (cosYaw*sinPitch*sinRoll);
result.Z = (cosYaw*cosPitch*sinRoll) - (sinYaw*sinPitch*cosRoll);
result.W = (cosYaw*cosPitch*cosRoll) + (sinYaw*sinPitch*sinRoll);
return result;
}
}
}