Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/chris: First snippet of the totally revamped base system… perhaps a bit confusing at the moment, but when finished theoretically you only have to subclass the worldentity and track classes to create the game content (even the menu will be a WorldEntity I suppose)

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