Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2624 was 2141, checked in by chris, 20 years ago

orxonox/branches/chris: added lots and lots of doxygen tags

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