Line | |
---|
1 | #include "vector.hh" |
---|
2 | |
---|
3 | Vector &Vector::operator += (const Vector &other){ |
---|
4 | this->x += other.x; |
---|
5 | this->y += other.y; |
---|
6 | this->z += other.z; |
---|
7 | return *this; |
---|
8 | } |
---|
9 | |
---|
10 | Vector Vector::operator + (const Vector &other) const{ |
---|
11 | return Vector(*this) += other; |
---|
12 | } |
---|
13 | |
---|
14 | Vector &Vector::operator -= (const Vector &other){ |
---|
15 | return *this += other.scale(-1); |
---|
16 | } |
---|
17 | |
---|
18 | Vector Vector::operator - (const Vector &other) const{ |
---|
19 | return Vector(*this) -= other; |
---|
20 | } |
---|
21 | |
---|
22 | Vector Vector::cross(const Vector &other) const{ |
---|
23 | return Vector(this->y * other.z - this->z * other.y, |
---|
24 | this->z * other.x - this->x * other.z, |
---|
25 | this->x * other.y - this->y * other.x); |
---|
26 | } |
---|
27 | |
---|
28 | float Vector::dot(const Vector &other) const{ |
---|
29 | return this->x * other.x + this->y * other.y + this->z * other.z; |
---|
30 | } |
---|
31 | |
---|
32 | float Vector::magnitude(void) const{ |
---|
33 | return this->dot(*this); |
---|
34 | } |
---|
35 | |
---|
36 | Vector Vector::scale(float amount) const{ |
---|
37 | return Vector(this->x * amount, this->y * amount, this->z * amount); |
---|
38 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.