Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/chris: Messed with the Player class, added stuff here and there, debug world now creates a player and bind IO to it. Added some doxygen tags.

File size: 2.5 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
14CommandNode::
15class Vector {
16
17  public:
18 
19  float x, y, z;
20
21  Vector (float x, float y, float z) : x(x), y(y), z(z) {}  //!< assignment constructor
22  Vector () : x(0), y(0), z(0) {}
23  ~Vector () {}
24
25  Vector operator+ (const Vector& v) const;
26  Vector operator- (const Vector& v) const;
27  float operator* (const Vector& v) const;
28  Vector operator* (float f) const;
29  Vector operator/ (float f) const;
30  float dot (const Vector& v) const;
31  Vector cross (const Vector& v) const;
32  float len() const;
33  void normalize();
34};
35
36float angle_deg (const Vector& v1, const Vector& v2);
37float angle_rad (const Vector& v1, const Vector& v2);
38
39//! 3D rotation
40/**
41  Class to handle 3-dimensional rotations.
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  Rotation operator* (const Rotation& r);
56 
57  glmatrix (float* buffer);
58};
59
60//!< Apply a rotation to a vector
61Vector rotate_vector( const Vector& v, const Rotation& r);
62
63//! 3D line
64/**
65  Class to store Lines in 3-dimensional space
66
67  Supports line-to-line distance measurements and rotation
68*/
69class Line
70{
71  public:
72 
73  Vector r;   //!< Offset
74  Vector a;   //!< Direction
75 
76  Line ( Vector r, Vector a) : r(r), a(a) {}  //!< assignment constructor
77  Line () : r(Vector(0,0,0)), a(Vector (1,1,1)) {}
78  ~Line () {}
79 
80  float distance (const Line& l) const;
81  float distance_point (const Vector& v) const;
82  Vector* footpoints (const Line& l) const;
83  float len () const;
84 
85  void rotate(const Rotation& rot);
86};
87
88//! 3D plane
89/**
90  Class to handle planes in 3-dimensional space
91 
92  Critical for polygon-based collision detection
93*/
94class Plane
95{
96  public:
97 
98  Vector n;   //!< Normal vector
99  float k;    //!< Offset constant
100 
101  Plane (Vector a, Vector b, Vector c);
102  Plane (Vector norm, Vector p);
103  Plane (Vector n, float k) : n(n), k(k) {} //!< assignment constructor
104  Plane () : n(Vector(1,1,1)), k(0) {}
105  ~Plane () {}
106 
107  Vector intersect_line (const Line& l) const;
108  float distance_point (const Vector& p) const;
109  float locate_point (const Vector& p) const;
110};
111
112#endif
Note: See TracBrowser for help on using the repository browser.