-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vec2.cpp
78 lines (64 loc) · 1.08 KB
/
Vec2.cpp
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
#include "Vec2.h"
Vec2::Vec2() {}
Vec2::Vec2(float xin, float yin) : x(xin), y(yin)
{
}
//basic operations
Vec2 Vec2::operator + (const Vec2& v) const
{
return Vec2(x + v.x, y + v.y);
}
Vec2 Vec2::operator - (const Vec2& v) const
{
return Vec2(x - v.x, y - v.y);
}
Vec2 Vec2::operator * (const float s) const
{
return Vec2(x * s, y * s);
}
Vec2 Vec2::operator / (const float d) const
{
return Vec2(x / d, y / d);
}
//comparator operations
bool Vec2::operator == (const Vec2& v) const
{
return (x == v.x) && (y == v.y);
}
bool Vec2::operator != (const Vec2& v) const
{
return !((x == v.x) && (y == v.y));
}
//base changing operations
void Vec2::operator += (const Vec2& v)
{
x += v.x;
y += v.y;
}
void Vec2::operator -= (const Vec2& v)
{
x -= v.x;
y -= v.y;
}
void Vec2::operator *= (float s)
{
x *= s;
y *= s;
}
void Vec2::operator /= (float d)
{
x /= d;
y /= d;
}
float Vec2::dist(Vec2 v)
{
float xCh = (x - v.x);
float yCh = (y - v.y);
return (xCh * xCh) + (yCh * yCh);
}
float Vec2::angle(Vec2 v)
{
float xCh = (x - v.x);
float yCh = (y - v.y);
return atan2(yCh, xCh);
}