-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvec3.hpp
181 lines (133 loc) · 4.43 KB
/
vec3.hpp
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// File: vec3.hpp
// Author: Samuel McFalls
// Description: Defines the Vec3 class. Geometric 3D vector.
#ifndef VEC3_H
#define VEC3_H
class Vec3 {
public:
// Default constructor
Vec3();
// Construct a Vec3 with specific values
// @param xCon The x value to construct with
// @param yCon the y value to construct with
// @param zCon the z value to construct with
Vec3(double xCon, double yCon, double zCon);
// Sets the x value of the vector
// @param xSet the x value to set
void setX(double xSet);
// Sets the y value of the vector
// @param ySet the x value to set
void setY(double ySet);
// Sets the z value of the vector
// @param zSet the x value to set
void setZ(double zSet);
// Fetches the x value of the vector
// @return The x value of the vector
double getX() const;
// Fetches the y value of the vector
// @return The y value of the vector
double getY() const;
// Fetches the z value of the vector
// @return The z value of the vector
double getZ() const;
// Computes the magnitude of the vector as sqrt(x^2 + y^2 + z^2)
// @return The magnitude of the vector
double magnitude() const;
// Calculates the normalized vector as v/mag(v) where v is the vector
// @return The normalized vector
Vec3 normalize() const;
// Calculates the dot product with the vector and another
// @param rhs The vector to take the dot product with
double dot(const Vec3 &rhs) const;
// Calculates the cross product with the vector and another
// @param rhs The vector to take the cross product with
Vec3 cross(const Vec3 &rhs) const;
// Compares two vectors
// @return true if two vectors have the same x, y, and z values,
// false otherwise
bool operator==(const Vec3 &rhs);
// Compares two vectors
// @return false if two vectors have the same x, y, and z values,
// true otherwise
bool operator!=(const Vec3 &rhs);
// Overloaded Add-Assignment operator
// Adds the components individually
Vec3& operator+=(const Vec3 &rhs);
// Overloaded Add-Assignment operator
// Adds rhs to each component
Vec3& operator+=(int rhs);
// Overloaded Add-Assignment operator
// Adds rhs to each component
Vec3& operator+=(double rhs);
// Overloaded Subtract-Assignment operator
// Subtracts the components individually
Vec3& operator-=(const Vec3 &rhs);
// Overloaded Subtract-Assignmnet operator
// Subtracts rhs from each component
Vec3& operator-=(int rhs);
// Overloaded Subtract-Assignmnet operator
// Subtracts rhs from each component
Vec3& operator-=(double rhs);
// Overloaded Multiply-Assignment operator
// Multiplies each component by rhs
Vec3& operator*=(int rhs);
// Overloaded Multiply-Assignment operator
// Multiplies each component by rhs
Vec3& operator*=(double rhs);
// Overloaded Divide-Assignment operator
// Divides each component by rhs
Vec3& operator/=(int rhs);
// Overloaded Divide-Assignment operator
// Divides each component by rhs
Vec3& operator/=(double rhs);
private:
// X value
double x;
// Y value
double y;
// Z value
double z;
};
// Overloaded Add operator
// Adds the components individually
Vec3 operator+(Vec3 lhs, const Vec3 &rhs);
// Overloaded Add operator
// Adds rhs to each component
Vec3 operator+(Vec3 lhs, int rhs);
// Overloaded Add operator
// Adds lhs to each component
Vec3 operator+(int lhs, const Vec3 &rhs);
// Overloaded Add operator
// Adds rhs to each component
Vec3 operator+(Vec3 lhs, double rhs);
// Overloaded Add operator
// Adds lhs to each component
Vec3 operator+(double lhs, const Vec3 &rhs);
// Overloaded Subtract operator
// Adds the components individually
Vec3 operator-(Vec3 lhs, const Vec3 &rhs);
// Overloaded Subtract operator
// Subtracts rhs from each component
Vec3 operator-(Vec3 lhs, int rhs);
// Overloaded Subtract operator
// Subtracts rhs from each component
Vec3 operator-(Vec3 lhs, double rhs);
// Overloaded Multiply operator
// Multiplies each component by rhs
Vec3 operator*(Vec3 lhs, int rhs);
// Overloaded Multiply operator
// Multiplies each component by lhs
Vec3 operator*(int lhs, const Vec3 &rhs);
// Overloaded Multiply operator
// Multiplies each component by rhs
Vec3 operator*(Vec3 lhs, double rhs);
// Overloaded Multiply operator
// Multiplies each component by lhs
Vec3 operator*(double lhs, const Vec3 &rhs);
// Overloaded Divide operator
// Divides each component by rhs
Vec3 operator/(Vec3 lhs, int rhs);
// Overloaded Divide operator
// Divides each component by rhs
Vec3 operator/(Vec3 lhs, double rhs);
#endif