Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/chris: Implemented quaternion class… but something is still f up… the camera keeps pointing into the wrong direction… matrix rotation calculation seems not to be my strenght…

File size: 3.2 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
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//! Quaternion
39/**
40        Class to handle 3-dimensional rotation efficiently
41*/
42class Quaternion
43{
44 public:
45        Vector v;
46        float w;
47
48        Quaternion ();
49        Quaternion (float m[4][4]);
50        Quaternion (float angle, const Vector& axis);
51        Quaternion (const Vector& dir, const Vector& up);
52        Quaternion (float roll, float pitch, float yaw);
53       
54        Quaternion operator/ (const float& f) const;
55        Quaternion operator* (const float& f) const;
56        Quaternion operator* (const Quaternion& q) const;
57        Quaternion operator+ (const Quaternion& q) const;
58        Quaternion operator- (const Quaternion& q) const;
59        Quaternion conjugate () const;
60        Quaternion inverse () const;
61        Vector apply (Vector& f) const;
62        float norm () const;
63        void matrix (float m[4][4]) const;
64};
65
66//! 3D rotation (OBSOLETE)
67/**
68  Class to handle 3-dimensional rotations.
69  Can create a rotation from several inputs, currently stores rotation using a 3x3 Matrix
70*/
71class Rotation {
72  public:
73 
74  float m[9]; //!< 3x3 Rotation Matrix
75 
76  Rotation ( const Vector& v);
77  Rotation ( const Vector& axis, float angle);
78  Rotation ( float pitch, float yaw, float roll);
79  Rotation ();
80  ~Rotation () {}
81 
82  Rotation operator* (const Rotation& r);
83 
84  void glmatrix (float* buffer);
85};
86
87//!< Apply a rotation to a vector
88Vector rotate_vector( const Vector& v, const Rotation& r);
89
90//! 3D line
91/**
92  Class to store Lines in 3-dimensional space
93
94  Supports line-to-line distance measurements and rotation
95*/
96class Line
97{
98  public:
99 
100  Vector r;   //!< Offset
101  Vector a;   //!< Direction
102 
103  Line ( Vector r, Vector a) : r(r), a(a) {}  //!< assignment constructor
104  Line () : r(Vector(0,0,0)), a(Vector (1,1,1)) {}
105  ~Line () {}
106 
107  float distance (const Line& l) const;
108  float distance_point (const Vector& v) const;
109  Vector* footpoints (const Line& l) const;
110  float len () const;
111 
112  void rotate(const Rotation& rot);
113};
114
115//! 3D plane
116/**
117  Class to handle planes in 3-dimensional space
118 
119  Critical for polygon-based collision detection
120*/
121class Plane
122{
123  public:
124 
125  Vector n;   //!< Normal vector
126  float k;    //!< Offset constant
127 
128  Plane (Vector a, Vector b, Vector c);
129  Plane (Vector norm, Vector p);
130  Plane (Vector n, float k) : n(n), k(k) {} //!< assignment constructor
131  Plane () : n(Vector(1,1,1)), k(0) {}
132  ~Plane () {}
133 
134  Vector intersect_line (const Line& l) const;
135  float distance_point (const Vector& p) const;
136  float locate_point (const Vector& p) const;
137};
138
139#endif
Note: See TracBrowser for help on using the repository browser.