-
Notifications
You must be signed in to change notification settings - Fork 5
/
Helper.cs
31 lines (26 loc) · 1.08 KB
/
Helper.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
namespace glvertexid;
public static class Helper
{
public static Vector3 FromPitchYaw(float pitch, float yaw)
{
var cosPitch = MathF.Cos(pitch);
return new Vector3(cosPitch * MathF.Sin(yaw), MathF.Sin(pitch), cosPitch * MathF.Cos(yaw));
}
public static Matrix4x4 CreateFPSView(Vector3 eye, float pitch, float yaw)
{
// Magic stuff
eye.X = -eye.X;
eye.Y = -eye.Y;
var cosPitch = MathF.Cos(pitch);
var sinPitch = MathF.Sin(pitch);
var cosYaw = MathF.Cos(-yaw);
var sinYaw = MathF.Sin(-yaw);
var xAxis = new Vector3(cosYaw, 0, -sinYaw);
var yAxis = new Vector3(sinYaw * sinPitch, cosPitch, cosYaw * sinPitch);
var zAxis = new Vector3(sinYaw * cosPitch, -sinPitch, cosPitch * cosYaw);
return new Matrix4x4(xAxis.X, yAxis.X, zAxis.X, 0,
xAxis.Y, yAxis.Y, zAxis.Y, 0,
-xAxis.Z, -yAxis.Z, -zAxis.Z, 0,
Vector3.Dot(xAxis, eye), Vector3.Dot(yAxis, eye), Vector3.Dot(zAxis, eye), 1);
}
}