-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoteCutDirectionExtensions.cs
More file actions
203 lines (189 loc) · 8.53 KB
/
NoteCutDirectionExtensions.cs
File metadata and controls
203 lines (189 loc) · 8.53 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System.Numerics;
namespace MapPostprocessor
{
public static class NoteCutDirectionExtensions {
public static Vector3 Multiply(Quaternion rotation, Vector3 point)
{
float x = rotation.X * 2F;
float y = rotation.Y * 2F;
float z = rotation.Z * 2F;
float xx = rotation.X * x;
float yy = rotation.Y * y;
float zz = rotation.Z * z;
float xy = rotation.X * y;
float xz = rotation.X * z;
float yz = rotation.Y * z;
float wx = rotation.W * x;
float wy = rotation.W * y;
float wz = rotation.W * z;
Vector3 res;
res.X = (1F - (yy + zz)) * point.X + (xy - wz) * point.Y + (xz + wy) * point.Z;
res.Y = (xy + wz) * point.X + (1F - (xx + zz)) * point.Y + (yz - wx) * point.Z;
res.Z = (xz - wy) * point.X + (yz + wx) * point.Y + (1F - (xx + yy)) * point.Z;
return res;
}
public static Vector2 Direction(this NoteCutDirection cutDirection) {
switch ((int)cutDirection)
{
case >= 1000 and <= 1360:
{
var quaternion = Quaternion.CreateFromYawPitchRoll(0f, 0f, 1000 - (int)cutDirection);
Vector3 dir = Multiply(quaternion, new Vector3(0, -1, 0));
return new Vector2(dir.X, dir.Y);
}
case >= 2000 and <= 2360:
{
var quaternion = Quaternion.CreateFromYawPitchRoll(0f, 0f, 2000 - (int)cutDirection);
Vector3 dir = Multiply(quaternion, new Vector3(0, -1, 0));
return new Vector2(dir.X, dir.Y);
}
}
switch (cutDirection) {
case NoteCutDirection.Up:
return new Vector2(0.0f, 1f);
case NoteCutDirection.Down:
return new Vector2(0.0f, -1f);
case NoteCutDirection.Left:
return new Vector2(-1f, 0.0f);
case NoteCutDirection.Right:
return new Vector2(1f, 0.0f);
case NoteCutDirection.UpLeft:
return new Vector2(-0.7071f, 0.7071f);
case NoteCutDirection.UpRight:
return new Vector2(0.7071f, 0.7071f);
case NoteCutDirection.DownLeft:
return new Vector2(-0.7071f, -0.7071f);
case NoteCutDirection.DownRight:
return new Vector2(0.7071f, -0.7071f);
default:
return new Vector2(0.0f, 0.0f);
}
}
public static float RotationAngle(this NoteCutDirection cutDirection) {
switch ((int)cutDirection)
{
case >= 1000 and <= 1360:
return 1000 - (int)cutDirection;
case >= 2000 and <= 2360:
return 2000 - (int)cutDirection;
}
switch (cutDirection) {
case NoteCutDirection.Up:
return -180f;
case NoteCutDirection.Down:
return 0.0f;
case NoteCutDirection.Left:
return -90f;
case NoteCutDirection.Right:
return 90f;
case NoteCutDirection.UpLeft:
return -135f;
case NoteCutDirection.UpRight:
return 135f;
case NoteCutDirection.DownLeft:
return -45f;
case NoteCutDirection.DownRight:
return 45f;
default:
return 0.0f;
}
}
public static bool IsMainDirection(this NoteCutDirection cutDirection) {
switch (cutDirection) {
case NoteCutDirection.Up:
return true;
case NoteCutDirection.Down:
return true;
case NoteCutDirection.Left:
return true;
case NoteCutDirection.Right:
return true;
default:
return false;
}
}
public static NoteCutDirection MainNoteCutDirectionFromCutDirAngle(float angle) {
angle %= 360f;
if ((double)angle < 0.0)
angle += 360f;
if ((double)angle < 45.0 || (double)angle > 315.0)
return NoteCutDirection.Right;
if ((double)angle < 135.0)
return NoteCutDirection.Up;
return (double)angle < 225.0 ? NoteCutDirection.Left : NoteCutDirection.Down;
}
public static NoteCutDirection Mirrored(this NoteCutDirection cutDirection) {
switch (cutDirection) {
case NoteCutDirection.Left:
return NoteCutDirection.Right;
case NoteCutDirection.Right:
return NoteCutDirection.Left;
case NoteCutDirection.UpLeft:
return NoteCutDirection.UpRight;
case NoteCutDirection.UpRight:
return NoteCutDirection.UpLeft;
case NoteCutDirection.DownLeft:
return NoteCutDirection.DownRight;
case NoteCutDirection.DownRight:
return NoteCutDirection.DownLeft;
default:
return cutDirection;
}
}
public static NoteCutDirection Opposite(this NoteCutDirection cutDirection) {
switch (cutDirection) {
case NoteCutDirection.Up:
return NoteCutDirection.Down;
case NoteCutDirection.Down:
return NoteCutDirection.Up;
case NoteCutDirection.Left:
return NoteCutDirection.Right;
case NoteCutDirection.Right:
return NoteCutDirection.Left;
case NoteCutDirection.UpLeft:
return NoteCutDirection.DownRight;
case NoteCutDirection.UpRight:
return NoteCutDirection.DownLeft;
case NoteCutDirection.DownLeft:
return NoteCutDirection.UpRight;
case NoteCutDirection.DownRight:
return NoteCutDirection.UpLeft;
default:
return cutDirection;
}
}
public static bool Approximately(float a, float b) => (double)Math.Abs(b - a) < (double)Math.Max(1E-06f * Math.Max(Math.Abs(a), Math.Abs(b)), 1.17549435E-38f * 8f);
public static bool IsOnSamePlane(
this NoteCutDirection noteCutDirection1,
NoteCutDirection noteCutDirection2) {
float a = Math.Abs(noteCutDirection1.RotationAngle() - noteCutDirection2.RotationAngle());
return Approximately(a, 0.0f) || Approximately(a, 180f);
}
public static float Angle(Vector2 from, Vector2 to) {
float num = (float)Math.Sqrt((double)from.LengthSquared() * (double)to.LengthSquared());
return (double)num < 1.0000000036274937E-15 ? 0.0f : (float)Math.Acos((double)Math.Clamp(Vector2.Dot(from, to) / num, -1f, 1f)) * 57.29578f;
}
public static float SignedAngle(Vector2 from, Vector2 to) {
return Angle(from, to) * Math.Sign((float) ((double) from.X * (double) to.Y - (double) from.Y * (double) to.X));
}
public static NoteCutDirection NoteCutDirectionFromDirection(Vector3 direction) {
float num = Angle(new Vector2(direction.X, direction.Y), new Vector2(0.0f, 1f));
if ((double)direction.X < 0.0) {
if ((double)num <= 22.5)
return NoteCutDirection.Up;
if ((double)num > 22.5 && (double)num <= 67.5)
return NoteCutDirection.UpLeft;
if ((double)num > 67.5 && (double)num <= 112.5)
return NoteCutDirection.Left;
return (double)num > 112.5 && (double)num <= 157.5 ? NoteCutDirection.DownLeft : NoteCutDirection.Down;
}
if ((double)num <= 22.5)
return NoteCutDirection.Up;
if ((double)num > 22.5 && (double)num <= 67.5)
return NoteCutDirection.UpRight;
if ((double)num > 67.5 && (double)num <= 112.5)
return NoteCutDirection.Right;
return (double)num > 112.5 && (double)num <= 157.5 ? NoteCutDirection.DownRight : NoteCutDirection.Down;
}
}
}