Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/chris/src/vector.h @ 2012

Last change on this file since 2012 was 2012, checked in by chris, 21 years ago

orxonox/branches/chris: Improved doxygen compatibility again

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