Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/math/vector.h @ 3607

Last change on this file since 3607 was 3541, checked in by bensch, 19 years ago

orxonox/trunk: debug information for class vector and quaternion

File size: 3.7 KB
RevLine 
[2043]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
[3224]8#ifndef _VECTOR_H
9#define _VECTOR_H
[2043]10
11#include <math.h>
[3449]12//! PI the circle-constant
[2043]13#define PI 3.14159265359f
14
[2190]15//! 3D Vector
[2043]16/**
[2190]17        Class to handle 3D Vectors
[2043]18*/
19class Vector {
20
21  public:
22 
[3449]23  float x; //!< The x Coordinate of the Vector.
24  float y; //!< The y Coordinate of the Vector.
25  float z; //!< The z Coordinate of the Vector.
[2043]26
27  Vector (float x, float y, float z) : x(x), y(y), z(z) {}  //!< assignment constructor
28  Vector () : x(0), y(0), z(0) {}
29  ~Vector () {}
30
31  Vector operator+ (const Vector& v) const;
32  Vector operator- (const Vector& v) const;
33  float operator* (const Vector& v) const;
34  Vector operator* (float f) const;
35  Vector operator/ (float f) const;
36  float dot (const Vector& v) const;
37  Vector cross (const Vector& v) const;
[2551]38  void scale(const Vector& v);
[2043]39  float len() const;
40  void normalize();
[2551]41  Vector* getNormalized();
42  Vector abs();
[3541]43
44  void debug();
[2043]45};
46
[3228]47float angleDeg (const Vector& v1, const Vector& v2);
48float angleRad (const Vector& v1, const Vector& v2);
[2043]49
[2190]50//! Quaternion
[2043]51/**
[2190]52        Class to handle 3-dimensional rotation efficiently
53*/
54class Quaternion
55{
56 public:
[3541]57  Vector v;     //!< Imaginary Vector
58  float w;        //!< Real part of the number
59 
60  Quaternion ();
61  Quaternion (float m[4][4]);
62  Quaternion (float angle, const Vector& axis);
63  Quaternion (const Vector& dir, const Vector& up);
64  Quaternion (float roll, float pitch, float yaw);
65 
66  Quaternion operator/ (const float& f) const;
67  Quaternion operator* (const float& f) const;
68  Quaternion operator* (const Quaternion& q) const;
69  Quaternion operator+ (const Quaternion& q) const;
70  Quaternion operator- (const Quaternion& q) const;
71  Quaternion conjugate () const;
72  Quaternion inverse () const;
73  Vector apply (Vector& f) const;
74  float norm () const;
75  void matrix (float m[4][4]) const;
76  void quatSlerp(const Quaternion* from, const Quaternion* to, const float t, Quaternion* res);
77 
78  void debug();
[2551]79 private:
[3541]80  float DELTA;      //!< resolution of calculation
[2551]81
[2190]82};
83
84//! 3D rotation (OBSOLETE)
85/**
[2043]86  Class to handle 3-dimensional rotations.
87  Can create a rotation from several inputs, currently stores rotation using a 3x3 Matrix
88*/
89class Rotation {
90  public:
91 
92  float m[9]; //!< 3x3 Rotation Matrix
93 
94  Rotation ( const Vector& v);
95  Rotation ( const Vector& axis, float angle);
96  Rotation ( float pitch, float yaw, float roll);
97  Rotation ();
98  ~Rotation () {}
99 
[2190]100  Rotation operator* (const Rotation& r);
101 
102  void glmatrix (float* buffer);
[2043]103};
[2551]104
[2043]105//!< Apply a rotation to a vector
[3228]106Vector rotateVector( const Vector& v, const Rotation& r);
[2043]107
108//! 3D line
109/**
110  Class to store Lines in 3-dimensional space
111
112  Supports line-to-line distance measurements and rotation
113*/
114class Line
115{
116  public:
117 
118  Vector r;   //!< Offset
119  Vector a;   //!< Direction
120 
121  Line ( Vector r, Vector a) : r(r), a(a) {}  //!< assignment constructor
122  Line () : r(Vector(0,0,0)), a(Vector (1,1,1)) {}
123  ~Line () {}
124 
125  float distance (const Line& l) const;
[3228]126  float distancePoint (const Vector& v) const;
[2043]127  Vector* footpoints (const Line& l) const;
128  float len () const;
129 
130  void rotate(const Rotation& rot);
131};
132
133//! 3D plane
134/**
135  Class to handle planes in 3-dimensional space
136 
137  Critical for polygon-based collision detection
138*/
139class Plane
140{
141  public:
142 
143  Vector n;   //!< Normal vector
144  float k;    //!< Offset constant
145 
146  Plane (Vector a, Vector b, Vector c);
147  Plane (Vector norm, Vector p);
148  Plane (Vector n, float k) : n(n), k(k) {} //!< assignment constructor
149  Plane () : n(Vector(1,1,1)), k(0) {}
150  ~Plane () {}
151 
[3228]152  Vector intersectLine (const Line& l) const;
153  float distancePoint (const Vector& p) const;
154  float locatePoint (const Vector& p) const;
[2043]155};
156
[3224]157#endif /* _VECTOR_H */
Note: See TracBrowser for help on using the repository browser.