-
Notifications
You must be signed in to change notification settings - Fork 1
/
vec4.cpp
106 lines (86 loc) · 1.43 KB
/
vec4.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
#include "vec4.h"
vec4::vec4()
{
x = 0.0;
y = 0.0;
z = 0.0;
p = 0.0;
}
vec4::vec4(double _x, double _y, double _z, double _p)
{
x = _x;
y = _y;
z = _z;
p = _p;
}
vec4::~vec4()
{
}
vec4& vec4::operator=(vec4 l){
x = l.x;
y = l.y;
z = l.z;
p = l.p;
return *this;
}
bool operator==(vec4 l, vec4 r){
if (l.x == r.x &&
l.y == r.y &&
l.z == r.z &&
l.p == r.p)
return true;
else
return false;
}
vec4 operator+(vec4 lhs, vec4 rhs){
vec4 res;
res.x = lhs.x + rhs.x;
res.y = lhs.y + rhs.y;
res.z = lhs.z + rhs.z;
res.p = lhs.p + rhs.p;
return res;
};
vec4 operator-(vec4 lhs, vec4 rhs){
vec4 res;
res.x = lhs.x - rhs.x;
res.y = lhs.y - rhs.y;
res.z = lhs.z - rhs.z;
res.p = lhs.p - rhs.p;
return res;
};
vec4 operator/(vec4 lhs, double x){
vec4 res;
res.x = lhs.x / x;
res.y = lhs.y / x;
res.z = lhs.z / x;
res.p = lhs.p / x;
return res;
};
vec4 operator*(vec4 lhs, double x){
vec4 res;
res.x = lhs.x * x;
res.y = lhs.y * x;
res.z = lhs.z * x;
res.p = lhs.p * x;
return res;
};
vec4 operator*(double x, vec4 lhs){
vec4 res;
res.x = lhs.x * x;
res.y = lhs.y * x;
res.z = lhs.z * x;
res.p = lhs.p;
return res;
};
double& vec4::operator[](int indx){
if (indx == 0)
return x;
else if (indx == 1)
return y;
else if (indx == 2)
return z;
else if (indx == 3)
return p;
else
throw;
};