1 | |
---|
2 | #ifndef VECTOR_H |
---|
3 | #define VECTOR_H |
---|
4 | |
---|
5 | #include <math.h> |
---|
6 | #define PI 3.14159265359f |
---|
7 | |
---|
8 | /** |
---|
9 | Class for 3-dimensional vector calculation |
---|
10 | |
---|
11 | Supports all common vector operations (dot, cross, lenght and so on) |
---|
12 | */ |
---|
13 | class Vector { |
---|
14 | |
---|
15 | public: |
---|
16 | |
---|
17 | float x, y, z; |
---|
18 | |
---|
19 | Vector (float x, float y, float z) : x(x), y(y), z(z) {} |
---|
20 | Vector () : x(0), y(0), z(0) {} |
---|
21 | ~Vector () {} |
---|
22 | |
---|
23 | Vector operator+ (const Vector& v) const; |
---|
24 | Vector operator- (const Vector& v) const; |
---|
25 | float operator* (const Vector& v) const; |
---|
26 | Vector operator* (float f) const; |
---|
27 | Vector operator/ (float f) const; |
---|
28 | float dot (const Vector& v) const; |
---|
29 | Vector cross (const Vector& v) const; |
---|
30 | float len() const; |
---|
31 | void normalize(); |
---|
32 | }; |
---|
33 | |
---|
34 | float angle_deg (const Vector& v1, const Vector& v2); |
---|
35 | float angle_rad (const Vector& v1, const Vector& v2); |
---|
36 | |
---|
37 | /** |
---|
38 | Class to handle 3-dimensional rotations |
---|
39 | |
---|
40 | Can create a rotation from several inputs, currently stores rotation using a 3x3 Matrix |
---|
41 | */ |
---|
42 | class Rotation { |
---|
43 | public: |
---|
44 | |
---|
45 | float m[9]; |
---|
46 | |
---|
47 | Rotation ( const Vector& v); |
---|
48 | Rotation ( const Vector& axis, float angle); |
---|
49 | Rotation ( float pitch, float yaw, float roll); |
---|
50 | Rotation (); |
---|
51 | ~Rotation () {} |
---|
52 | |
---|
53 | }; |
---|
54 | |
---|
55 | Vector rotate_vector( const Vector& v, const Rotation& r); |
---|
56 | |
---|
57 | /** |
---|
58 | Class to store Lines in 3-dimensional space |
---|
59 | |
---|
60 | Supports line-to-line distance measurements and rotation |
---|
61 | */ |
---|
62 | class Line |
---|
63 | { |
---|
64 | public: |
---|
65 | |
---|
66 | Vector r, a; |
---|
67 | |
---|
68 | Line ( Vector r, Vector a) : r(r), a(a) {} |
---|
69 | Line () : r(Vector(0,0,0)), a(Vector (1,1,1)) {} |
---|
70 | ~Line () {} |
---|
71 | |
---|
72 | float distance (const Line& l) const; |
---|
73 | float distance_point (const Vector& v) const; |
---|
74 | Vector* footpoints (const Line& l) const; |
---|
75 | float len () const; |
---|
76 | |
---|
77 | void rotate(const Rotation& rot); |
---|
78 | }; |
---|
79 | |
---|
80 | /** |
---|
81 | Class to handle planes in 3-dimensional space |
---|
82 | |
---|
83 | Critical for polygon-based collision detection |
---|
84 | */ |
---|
85 | class Plane |
---|
86 | { |
---|
87 | public: |
---|
88 | |
---|
89 | Vector n; |
---|
90 | float k; |
---|
91 | |
---|
92 | Plane (Vector a, Vector b, Vector c); |
---|
93 | Plane (Vector norm, Vector p); |
---|
94 | Plane (Vector n, float k) : n(n), k(k) {} |
---|
95 | Plane () : n(Vector(1,1,1)), k(0) {} |
---|
96 | ~Plane () {} |
---|
97 | |
---|
98 | Vector intersect_line (const Line& l) const; |
---|
99 | float distance_point (const Vector& p) const; |
---|
100 | float locate_point (const Vector& p) const; |
---|
101 | }; |
---|
102 | |
---|
103 | #endif |
---|