-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector4.cpp
103 lines (102 loc) · 2.15 KB
/
Vector4.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
//
// Created by Andrew on 2/7/2020.
//
Vector4()
{
x = 0;
y = 0;
z = 0;
w = 0;
}
Vector4(float x, float y, float z, float w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
float dot(Vector4 other)
{
return x * other.x + y * other.y + z * other.z + w * other.w;
}
friend Vector4 operator + (Vector4 left, Vector4 right)
{
return Vector4(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
}
friend Vector4 operator - (Vector4 left, Vector4 right)
{
return Vector4(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
}
friend Vector4 operator * (Vector4 left, float factor)
{
return Vector4(left.x * factor, left.y * factor, left.z * factor, left.w * factor);
}
friend Vector4 operator / (Vector4 left, float factor)
{
return Vector4(left.x / factor, left.y / factor, left.z / factor, left.w / factor);
}
friend Vector4 operator += (Vector4 left, Vector4 right)
{
left.x += right.x;
left.y += right.y;
left.z += right.z;
left.w += right.w;
}
friend Vector4 operator -= (Vector4 left, Vector4 right)
{
left.x -= right.x;
left.y -= right.y;
left.z -= right.z;
left.w -= right.w;
}
friend Vector4 operator *= (Vector4 left, float factor)
{
left.x *= factor;
left.y *= factor;
left.z *= factor;
left.w *= factor;
}
friend Vector4 operator /= (Vector4 left, float factor)
{
left.x /= factor;
left.y /= factor;
left.z /= factor;
left.w /= factor;
}
float getValue(int index)
{
switch(index)
{
case 0:
return x;
case 1:
return y;
case 2:
return z;
case 3:
return w;
default:
cout << "Error invalid parameter to getValue." << endl;
return 0;
}
}
void setValue(float val, int index)
{
switch(index)
{
case 0:
x = val;
break;
case 1:
y = val;
break;
case 2:
z = val;
break;
case 3:
w = val;
break;
default:
cout << "Error invalid parameter to setValue." << endl;
}
}