-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector3D.h
More file actions
50 lines (34 loc) · 737 Bytes
/
Vector3D.h
File metadata and controls
50 lines (34 loc) · 737 Bytes
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
#pragma once
class Vector3D {
public:
int x_;
int y_;
int z_;
Vector3D()
:x_(0), y_(0), z_(0)
{}
Vector3D(const int& x, const int& y, const int& z)
:x_(x), y_(y), z_(z)
{}
//overloading plus additive operation
Vector3D& operator+(const Vector3D& input)
{
Vector3D vec;
vec.x_ = this->x_ + input.x_;
vec.y_ = this->y_ + input.y_;
vec.z_ = this->z_ + input.z_;
return vec;
}
// dot product
int operator*(const Vector3D& input) {
int ans;
ans = this->x_ * input.x_;
ans += this->y_ * input.y_;
ans += this->z_ * input.z_;
return ans;
}
};
std::ostream& operator<<(std::ostream& os, const Vector3D& vec) {
os << vec.x_ << " " << vec.y_ << " " << vec.z_ << std::endl;
return os;
}