-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector2.h
91 lines (74 loc) · 1.49 KB
/
vector2.h
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
#pragma once
#include <sal.h>
class Vector2 {
public:
Vector2() {
}
Vector2(_In_ const Vector2& v) { // https://www.runoob.com/w3cnote/cpp-const-keyword.html
mX = v.mX;
mY = v.mY;
}
Vector2(_In_ const float x, _In_ const float y) {
mX = x;
mY = y;
}
float GetX() {
return mX;
}
float GetY() {
return mY;
}
void Add(_In_ const Vector2& v, _Out_ Vector2* out) {
out->mX = mX + v.mX;
out->mY = mY + v.mY;
}
Vector2& Add_(_In_ const Vector2& v) {
mX = mX + v.mX;
mY = mY + v.mY;
return *this; // https://blog.csdn.net/daimous/article/details/78618432
}
void Sub(_In_ const Vector2& v, _Out_ Vector2* out) {
out->mX = mX - v.mX;
out->mY = mY - v.mY;
}
Vector2& Sub_(_In_ const Vector2& v) {
mX = mX - v.mX;
mY = mY - v.mY;
return *this;
}
void Scale(_In_ const float v, _Out_ Vector2* out) {
out->mX = mX * v;
out->mY = mY * v;
}
Vector2& Scale_(_In_ const float v) {
mX = mX * v;
mY = mY * v;
return *this;
}
void Multi(_In_ const Vector2& v, _Out_ Vector2* out) {
out->mX = mX * v.mX;
out->mY = mY * v.mY;
}
Vector2& Multi_(_In_ const Vector2& v) {
mX = mX * v.mX;
mY = mY * v.mY;
return *this;
}
void Div(_In_ const Vector2& v, _Out_ Vector2* out) {
out->mX = mX / v.mX;
out->mY = mY / v.mY;
}
Vector2& Div_(_In_ const Vector2& v) {
mX = mX / v.mX;
mY = mY / v.mY;
return *this;
}
Vector2& Copy_(_In_ const Vector2& v) {
mX = v.mX;
mY = v.mY;
return *this;
}
protected:
float mX = 0.;
float mY = 0.;
};