-
Notifications
You must be signed in to change notification settings - Fork 2
/
vector3d.h
60 lines (47 loc) · 1.4 KB
/
vector3d.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
#ifndef VECTOR3D_H
#define VECTOR3D_H
// We don't need more precision than float
typedef float vec_t;
/**
* Vector implementation based on Valve's
* (I know, don't reinvent the well, we have QVector*D...)
*/
class Vector3D {
public:
// Public access to properties
vec_t x, y, z;
// Constructors
Vector3D(void);
Vector3D(vec_t X, vec_t Y, vec_t Z);
Vector3D(const vec_t *array);
// Copy
Vector3D(const Vector3D &other);
Vector3D& operator=(const Vector3D &other);
void toArray(vec_t *dst);
// Access
vec_t& operator[](int index);
// Comparassion
bool operator==(const Vector3D &other) const;
bool operator!=(const Vector3D &other) const;
// Arithmetic assignment
Vector3D& operator+=(const Vector3D &v);
Vector3D& operator-=(const Vector3D &v);
Vector3D& operator*=(const Vector3D &v);
Vector3D& operator*=(vec_t val);
Vector3D& operator/=(const Vector3D &v);
Vector3D& operator/=(vec_t val);
// Arithmetic
Vector3D operator+(const Vector3D &v) const;
Vector3D operator-(const Vector3D &v) const;
Vector3D operator*(const Vector3D &v) const;
Vector3D operator*(vec_t val) const;
Vector3D operator/(const Vector3D &v) const;
Vector3D operator/(vec_t val) const;
// Geometric methods
vec_t length() const;
void normalize();
Vector3D normalized() const;
vec_t dot(const Vector3D &v) const;
Vector3D cross(const Vector3D &v) const;
};
#endif // VECTOR3D_H