-
Notifications
You must be signed in to change notification settings - Fork 1
/
vec3.h
49 lines (43 loc) · 1.29 KB
/
vec3.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
#pragma once
#include <iostream>
class vec3
{
private:
double m_vec[3];
public:
vec3(); // Create a zero vector
vec3(double x, double y, double z);
bool operator==(vec3 &rhs);
vec3 operator+(vec3 &rhs);
vec3 operator-(vec3 &rhs);
vec3 operator*(vec3 &rhs);
vec3 operator/(vec3 &rhs);
vec3 operator+(double scalar);
vec3 operator-(double scalar);
vec3 operator*(double scalar);
vec3 operator/(double scalar);
inline void add(vec3 &rhs) {
m_vec[0] += rhs.x();
m_vec[1] += rhs.y();
m_vec[2] += rhs.z();
}
inline void addAndMultiply(vec3 &rhs, double scalar) {
m_vec[0] += rhs.x()*scalar;
m_vec[1] += rhs.y()*scalar;
m_vec[2] += rhs.z()*scalar;
}
vec3 cross(vec3 &rhs);
double dot(vec3 &rhs);
double length();
double lengthSquared();
void normalize();
void setToZero();
void set(double x, double y, double z);
inline double x() const { return m_vec[0]; }
inline double y() const { return m_vec[1]; }
inline double z() const { return m_vec[2]; }
inline double &operator[](int index) { return m_vec[index]; }
inline double operator[](int index) const { return m_vec[index]; }
private:
friend std::ostream& operator<<(std::ostream&stream, vec3 &vec);
};