-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVec3.cpp
99 lines (79 loc) · 1.88 KB
/
Vec3.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "Vec3.hpp"
Vec3 Vec3::operator+(const Vec3& obj) {
return Vec3((*this).x_ + obj.x_, (*this).y_ + obj.y_, (*this).z_ + obj.z_);
}
Vec3 Vec3::operator-(const Vec3& obj) {
return Vec3((*this).x_ - obj.x_, (*this).y_ - obj.y_, (*this).z_ - obj.z_);
}
Vec3 Vec3::operator*(const Vec3& obj) {
return Vec3((*this).x_ * obj.x_, (*this).y_ * obj.y_, (*this).z_ * obj.z_);
}
Vec3 Vec3::operator/(const Vec3& obj) {
return Vec3((*this).x_ / obj.x_, (*this).y_ / obj.y_, (*this).z_ / obj.z_);
}
Vec3 Vec3::operator+(const float& v) {
return Vec3((*this).x_ + v, (*this).y_ + v, (*this).z_ + v);
}
Vec3 Vec3::operator-(const float& v) {
return Vec3((*this).x_ - v, (*this).y_ -v, (*this).z_ - v);
}
Vec3 Vec3::operator/(const float& v) {
return Vec3((*this).x_ / v, (*this).y_ / v, (*this).z_ / v);
}
Vec3 Vec3::operator+=(const Vec3& obj) {
x_ += obj.x_;
y_ += obj.y_;
z_ += obj.z_;
return (*this);
}
Vec3 Vec3::operator-=(const Vec3& obj) {
x_ -= obj.x_;
y_ -= obj.y_;
z_ -= obj.z_;
return (*this);
}
Vec3 Vec3::operator*=(const Vec3& obj) {
x_ *= obj.x_;
y_ *= obj.y_;
z_ *= obj.z_;
return (*this);
}
Vec3 Vec3::operator/=(const Vec3& obj) {
x_ /= obj.x_;
y_ /= obj.y_;
z_ /= obj.z_;
return (*this);
}
Vec3 Vec3::operator+=(const float& v) {
x_ += v;
y_ += v;
z_ += v;
return (*this);
}
Vec3 Vec3::operator-=(const float& v) {
x_ -= v;
y_ -= v;
z_ -= v;
return (*this);
}
Vec3 Vec3::operator*=(const float& v) {
x_ *= v;
y_ *= v;
z_ *= v;
return (*this);
}
Vec3 Vec3::operator/=(const float& v) {
x_ /= v;
y_ /= v;
z_ /= v;
return (*this);
}
float Vec3::Length() {
return sqrt(x_ * x_ + y_ * y_ + z_ * z_);
}
float Vec3::SquaredLength() {
return x_ * x_ + y_ * y_ + z_ * z_;
}
Vec3 Vec3::Normalized() {
return (*this) / (*this).Length();
}