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
|
#include "math_vector.h"
#include <cmath>
MathVector2::MathVector2() {
}
MathVector2::MathVector2(float x, float y) : x{x}, y{y} {
}
bool MathVector2::operator==(MathVector2 other) const {
return x == other.x && y == other.y;
}
bool MathVector2::operator!=(MathVector2 other) const {
return !(*this == other);
}
MathVector2 MathVector2::operator+() const {
return *this;
}
MathVector2 MathVector2::operator-() const {
return { -x, -y };
}
MathVector2 MathVector2::operator+(MathVector2 other) const {
return { x + other.x, y + other.y };
}
MathVector2 MathVector2::operator-(MathVector2 other) const {
return *this + (-other);
}
float MathVector2::det(MathVector2 other) const {
return this->x * other.y - other.x * this->y;
}
MathVector2 MathVector2::round() const {
return { std::round(x), std::round(y) };
}
MathVector2 operator*(float n, MathVector2 other) {
return { n * other.x, n * other.y };
}
MathVector2 operator*(MathVector2 other, float n) {
return n * other;
}
MathVector2 operator/(MathVector2 other, float n) {
return { other.x / n, other.y / n };
}
MathVector3::MathVector3() {
}
MathVector3::MathVector3(float x, float y, float z) : x{x}, y{y}, z{z} {
}
bool MathVector3::operator==(MathVector3 other) const {
return x == other.x && y == other.y && z == other.z;
}
bool MathVector3::operator!=(MathVector3 other) const {
return !(*this == other);
}
MathVector3 MathVector3::operator+() const {
return *this;
}
MathVector3 MathVector3::operator-() const {
return { -x, -y, -z };
}
MathVector3 MathVector3::operator+(MathVector3 other) const {
return { x + other.x, y + other.y, z + other.z };
}
MathVector3 MathVector3::operator-(MathVector3 other) const {
return *this + (-other);
}
MathVector3 MathVector3::round() const {
return { std::round(x), std::round(y), std::round(z) };
}
MathVector2 MathVector3::xy() const {
return { x, y };
}
MathVector3 MathVector3::cross(MathVector3 other) const {
return {
y * other.z - z * other.y,
z * other.x - x * other.z,
x * other.y - y * other.x
};
}
MathVector3 operator*(float n, MathVector3 other) {
return { n * other.x, n * other.y, n * other.z };
}
MathVector3 operator*(MathVector3 other, float n) {
return n * other;
}
MathVector3 operator/(MathVector3 other, float n) {
return { other.x / n, other.y / n, other.z / n };
}
MathVector4::MathVector4() {
}
MathVector4::MathVector4(float x, float y, float z, float w) : x{x}, y{y}, z{z}, w{w} {
}
MathVector4::MathVector4(float x, float y, float z) : x{x}, y{y}, z{z}, w{1.f} {
}
MathVector4::MathVector4(MathVector3 v, float w) : x{v.x}, y{v.y}, z{v.z}, w{w} {
}
MathVector4::MathVector4(MathVector3 v) : x{v.x}, y{v.y}, z{v.z}, w{1.f} {
}
bool MathVector4::operator==(MathVector4 other) const {
return x == other.x && y == other.y && z == other.z && w == other.w;
}
bool MathVector4::operator!=(MathVector4 other) const {
return !(*this == other);
}
MathVector4 MathVector4::operator+() const {
return *this;
}
MathVector4 MathVector4::operator-() const {
return { -x, -y, -z, -w };
}
MathVector4 MathVector4::operator+(MathVector4 other) const {
return { x + other.x, y + other.y, z + other.z, w + other.w };
}
MathVector4 MathVector4::operator-(MathVector4 other) const {
return *this + (-other);
}
MathVector4 MathVector4::round() const {
return { std::round(x), std::round(y), std::round(z), std::round(w) };
}
MathVector3 MathVector4::xyz() const {
return { x, y, z };
}
MathVector3 MathVector4::div_by_w() const {
return xyz() / w;
}
MathVector4 operator*(float n, MathVector4 other) {
return { n * other.x, n * other.y, n * other.z, n * other.w };
}
MathVector4 operator*(MathVector4 other, float n) {
return n * other;
}
MathVector4 operator/(MathVector4 other, float n) {
return { other.x / n, other.y / n, other.z / n, other.w / n };
}
|