Pixel-Composer/scripts/point_rotate/point_rotate.gml

27 lines
416 B
Plaintext
Raw Normal View History

2024-01-24 06:19:34 +01:00
function point_rotate(px, py, ox, oy, a, p = undefined) {
2023-11-08 08:38:04 +01:00
INLINE
2023-09-09 13:52:16 +02:00
2024-01-24 06:19:34 +01:00
p ??= [ px, py ];
2023-02-23 07:02:19 +01:00
a = angle_difference(a, 0);
2024-01-24 06:19:34 +01:00
if(a == 0) {
p[0] = px;
p[1] = py;
return p;
}
if(a == 180) {
p[0] = ox + (ox - px);
p[1] = oy + (oy - py);
return p;
}
2023-02-23 07:02:19 +01:00
2022-01-13 05:24:03 +01:00
var cx = px - ox;
var cy = py - oy;
var d = -degtorad(a);
2024-01-24 06:19:34 +01:00
p[0] = ox + cx * cos(d) - cy * sin(d);
p[1] = oy + cx * sin(d) + cy * cos(d);
return p;
2022-01-13 05:24:03 +01:00
}