-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector3d.cpp
151 lines (129 loc) · 2.02 KB
/
vector3d.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
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
// River Raid 2018
// Made by Micha³ Berdzik, AGH, 2018 ©
//------------------------------------------------------------------
#include "vector3d.h"
vector3d::vector3d()
{
x=y=z=0;
}
vector3d::vector3d(float a,float b)
{
x=a;
y=b;
z=0;
}
vector3d::vector3d(float a,float b,float c)
{
x=a;
y=b;
z=c;
}
float vector3d::dotProduct(const vector3d& vec2)
{
return (x*vec2.x+y*vec2.y+z*vec2.z);
}
vector3d vector3d::crossProduct(const vector3d& vec2)
{
return vector3d();
}
float vector3d::length()
{
return sqrt(x*x+y*y+z*z);
}
void vector3d::normalize()
{
float len=length();
if(len!=0)
{
x/=len;
y/=len;
z/=len;
}
}
void vector3d::change(float a,float b,float c)
{
x=a;
y=b;
z=c;
}
void vector3d::change(vector3d vec2)
{
x=vec2.x;
y=vec2.y;
z=vec2.z;
}
void vector3d::changeX(float a)
{
x=a;
}
void vector3d::changeY(float a)
{
y=a;
}
void vector3d::changeZ(float a)
{
z=a;
}
vector3d vector3d::operator+(const vector3d& vec2)
{
return vector3d(x+vec2.x,y+vec2.y,z+vec2.z);
}
vector3d vector3d::operator-(const vector3d& vec2)
{
return vector3d(x-vec2.x,y-vec2.y,z-vec2.z);
}
vector3d vector3d::operator*(float num)
{
return vector3d(x*num,y*num,z*num);
}
vector3d vector3d::operator/(float num)
{
if(num!=0)
return vector3d(x/num,y/num,z/num);
else
return vector3d();
}
vector3d& vector3d::operator+=(const vector3d& vec2)
{
x+=vec2.x;
y+=vec2.y;
z+=vec2.z;
return *this;
}
vector3d& vector3d::operator-=(const vector3d& vec2)
{
x-=vec2.x;
y-=vec2.y;
z-=vec2.z;
return *this;
}
vector3d& vector3d::operator*=(float num)
{
x*=num;
y*=num;
z*=num;
return *this;
}
vector3d& vector3d::operator/=(float num)
{
if(num!=0)
{
x/=num;
y/=num;
z/=num;
}
return *this;
}
bool vector3d::operator==(const vector3d vec2)
{
return (x==vec2.x && y==vec2.y && z==vec2.z);
}
bool vector3d::operator!=(const vector3d vec2)
{
return !(*this==vec2);
}
std::ostream& operator<<(std::ostream& out,const vector3d& vec)
{
out << vec.x << " " << vec.y << " " << vec.z << std::endl;
return out;
}