-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVec3f.h
85 lines (69 loc) · 1.41 KB
/
Vec3f.h
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
#ifndef VEC3F_H
#define VEC3F_H
struct Vec3f {
float x;
float y;
float z;
Vec3f() : x(0), y(0), z(0) {}
Vec3f(float a) : x(a), y(a), z(a) {}
Vec3f(float x2, float y2, float z2) : x(x2), y(y2), z(z2) {}
Vec3f operator + (const Vec3f v) {
Vec3f result;
result.x = x + v.x;
result.y = y + v.y;
result.z = z + v.z;
return result;
}
Vec3f operator - (const Vec3f v) {
Vec3f result;
result.x = x - v.x;
result.y = y - v.y;
result.z = z - v.z;
return result;
}
Vec3f operator * (const Vec3f v) {
Vec3f result;
result.x = x * v.x;
result.y = y * v.y;
result.z = z * v.z;
return result;
}
Vec3f operator * (const float c) {
Vec3f result;
result.x = x * c;
result.y = y * c;
result.z = z * c;
return result;
}
Vec3f operator / (const float c) {
Vec3f result;
result.x = x / c;
result.y = y / c;
result.z = z / c;
return result;
}
float dot(Vec3f v) {
return (x * v.x) + (y * v.y) + (z * v.z);
}
void normalize() {
float magnitude = sqrt((x*x) + (y*y) + (z*z));
x /= magnitude;
y /= magnitude;
z /= magnitude;
}
float calculateMagnitude() {
float magnitude = sqrt((x*x) + (y*y) + (z*z));
return magnitude;
}
void setAll(float val) {
x = val;
y = val;
z = val;
}
void setEach(float xNew, float yNew, float zNew) {
x = xNew;
y = yNew;
z = zNew;
}
};
#endif