forked from idMysteries/osuAutoBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvec2f.h
More file actions
86 lines (77 loc) · 2.02 KB
/
vec2f.h
File metadata and controls
86 lines (77 loc) · 2.02 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
/*
osu!AutoBot
Copyright (C) 2016 Andrey Tokarev
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
#pragma once
class vec2f {
public:
float x, y;
vec2f(float x, float y) : x(x), y(y) {}
vec2f() : x(0.0f), y(0.0f) {}
vec2f nor() {
auto nx = -y, ny = x;
x = nx;
y = ny;
return *this;
}
vec2f midPoint(const vec2f& o) const
{
return vec2f((x + o.x) / 2.0f, (y + o.y) / 2.0f);
}
vec2f sub(vec2f o) {
x -= o.x;
y -= o.y;
return *this;
}
vec2f cpy() const
{ return vec2f(x, y); }
vec2f add(float nx, float ny) {
x += nx;
y += ny;
return *this;
}
float len() const
{ return sqrtf(x * x + y * y); }
float LengthSquared() const
{ return x*x + y*y; }
vec2f operator+=(const vec2f& alt) {
x += alt.x;
y += alt.y;
return *this;
}
};
inline vec2f rotate(vec2f point, float angle) {
vec2f rotated_point;
rotated_point.x = point.x * cos(angle) - point.y * sin(angle);
rotated_point.y = point.x * sin(angle) + point.y * cos(angle);
return rotated_point;
}
inline vec2f operator + (vec2f a, vec2f b)
{
return vec2f(a.x + b.x, a.y + b.y);
}
inline vec2f operator - (vec2f a, vec2f b) {
return vec2f(a.x - b.x, a.y - b.y);
}
inline vec2f operator * (float s, vec2f a) {
return vec2f(s * a.x, s * a.y);
}
inline vec2f operator * (vec2f a, float s) {
return vec2f(s * a.x, s * a.y);
}
inline vec2f operator / (vec2f a, float s) {
return vec2f(a.x / s, a.y / s);
}
inline bool operator == (vec2f p1, vec2f p2) {
return p1.x == p2.x && p1.y == p2.y;
}