-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVec3.cpp
More file actions
68 lines (55 loc) · 1.3 KB
/
Vec3.cpp
File metadata and controls
68 lines (55 loc) · 1.3 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
#include "Vec3.h"
#include <cmath>
Vec3 Vec3::operator=(const Vec3 &other) {
x = other.x;
y = other.y;
z = other.z;
return *this;
}
Vec3 Vec3::operator=(const double i) {
x = i;
y = 0;
z = 0;
return *this;
}
Vec3 Vec3::operator+(const Vec3 &other) const {
return Vec3(x + other.x, y + other.y, z + other.z);
}
Vec3 Vec3::operator-(const Vec3 &other) const {
return Vec3(x - other.x, y - other.y, z - other.z);
}
Vec3 Vec3::operator*(const double n) const {
return Vec3(x * n, y * n, z * n);
}
double Vec3::operator*(const Vec3 &other) const {
return x * other.x + y * other.y + z * other.z;
}
Vec3 Vec3::operator^(const Vec3 &other) const {
// y1*z2 - z1*y2 ; -x1*z2 + z1*x2 ; x1*y2 - y1*x2
return Vec3(y * other.z - z * other.y, z * other.x - x * other.z, x * other.y - y * other.x);
}
double Vec3::length() const {
return sqrt(x * x + y * y + z * z);
}
Vec3 Vec3::operator+=(const Vec3 &other) {
x += other.x;
y += other.y;
z += other.z;
return *this;
}
Vec3 Vec3::operator-=(const Vec3 &other) {
x -= other.x;
y -= other.y;
z -= other.z;
return *this;
}
Vec3 Vec3::operator*=(const double n) {
x *= n;
y *= n;
z *= n;
return *this;
}
Vec3 Vec3::operator^=(const Vec3 &other) {
*this = *this ^ other;
return *this;
}