Changeset 4476 in orxonox.OLD for orxonox/trunk/src/lib/math/vector.h
- Timestamp:
- Jun 2, 2005, 4:03:50 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/math/vector.h
r4372 r4476 20 20 class Vector { 21 21 22 public: 23 24 float x; //!< The x Coordinate of the Vector. 25 float y; //!< The y Coordinate of the Vector. 26 float z; //!< The z Coordinate of the Vector. 27 22 23 public: 28 24 Vector (float x, float y, float z) : x(x), y(y), z(z) {} //!< assignment constructor 29 25 Vector () : x(0), y(0), z(0) {} 30 26 ~Vector () {} 31 27 32 inline Vector operator+ (const Vector& v) const { return Vector(x + v.x, y + v.y, z + v.z); } 33 inline const Vector& operator+= (const Vector& v) {this->x += v.x; this->y += v.y; this->z += v.z; return *this;} 28 /** \param v The vector to add \returns the addition between two vectors (this + v) */ 29 inline Vector operator+ (const Vector& v) const { return Vector(x + v.x, y + v.y, z + v.z); }; 30 /** \param v The vector to add \returns the addition between two vectors (this += v) */ 31 inline const Vector& operator+= (const Vector& v) { this->x += v.x; this->y += v.y; this->z += v.z; return *this; }; 32 /** \param v The vector to substract \returns the substraction between two vectors (this - v) */ 34 33 inline Vector operator- (const Vector& v) const { return Vector(x - v.x, y - v.y, z - v.z); } 35 inline const Vector& operator-= (const Vector& v) {this->x -= v.x; this->y -= v.y; this->z -= v.z; return *this;} 36 inline float operator* (const Vector& v) const { return x * v.x + y * v.y + z * v.z; } 37 inline const Vector& operator*= (const Vector& v) {this->x *= v.x; this->y *= v.y; this->z *= v.z; return *this;} 38 inline Vector operator* (float f) const { return Vector(x * f, y * f, z * f); } 39 inline const Vector& operator*= (float f) {this->x *= f; this->y *= f; this->z *= f; return *this;} 40 Vector operator/ (float f) const; 41 inline const Vector& operator/= (float f) {this->x /= f; this->y /= f; this->z /= f; return *this;} 42 inline const Vector& operator= (const Vector& v) {this->x = v.x; this->y = v.y; this->z = v.z; return *this;} 43 float dot (const Vector& v) const; 34 /** \param v The vector to substract \returns the substraction between two vectors (this -= v) */ 35 inline const Vector& operator-= (const Vector& v) { this->x -= v.x; this->y -= v.y; this->z -= v.z; return *this; }; 36 /** \param v the second vector \returns The dotProduct between two vector (this (dot) v) */ 37 inline float operator* (const Vector& v) const { return x * v.x + y * v.y + z * v.z; }; 38 /** \todo strange */ 39 inline const Vector& operator*= (const Vector& v) { this->x *= v.x; this->y *= v.y; this->z *= v.z; return *this; }; 40 /** \param f a factor to multiply the vector with \returns the vector multiplied by f (this * f) */ 41 inline Vector operator* (float f) const { return Vector(x * f, y * f, z * f); }; 42 /** \param f a factor to multiply the vector with \returns the vector multiplied by f (this *= f) */ 43 inline const Vector& operator*= (float f) { this->x *= f; this->y *= f; this->z *= f; return *this; }; 44 /** \param f a factor to divide the vector with \returns the vector divided by f (this / f) */ 45 inline Vector operator/ (float f) const {if (unlikely(f == 0.0)) return Vector(0,0,0); else return Vector(this->x / f, this->y / f, this->z / f); }; 46 /** \param f a factor to divide the vector with \returns the vector divided by f (this /= f) */ 47 inline const Vector& operator/= (float f) {if (unlikely(f == 0.0)) {this->x=0;this->y=0;this->z=0;} else {this->x /= f; this->y /= f; this->z /= f;} return *this; }; 48 /** \brief copy constructor \todo (i do not know it this is faster) \param v the vector to assign to this vector. \returns the vector v */ 49 inline const Vector& operator= (const Vector& v) { this->x = v.x; this->y = v.y; this->z = v.z; return *this; }; 50 /** \param v: the other vector \return the dot product of the vectors */ 51 float dot (const Vector& v) const { return x*v.x+y*v.y+z*v.z; }; 52 /** \param v: the corss-product partner \returns the cross-product between this and v (this (x) v) */ 44 53 inline Vector cross (const Vector& v) const { return Vector(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); } 45 void scale(const Vector& v); 54 /** \param scales the this vector with v */ 55 void scale(const Vector& v) { x *= v.x; y *= v.y; z *= v.z; }; 56 /** \returns the length of the vector */ 46 57 inline float len() const { return sqrt (x*x+y*y+z*z); } 47 inline void normalize() { 58 /** \brief normalizes the vector */ 59 inline void normalize() { 48 60 float l = len(); 49 61 if( unlikely(l == 0.0)) … … 60 72 61 73 void debug() const; 62 }; 63 64 float angleDeg (const Vector& v1, const Vector& v2); 65 float angleRad (const Vector& v1, const Vector& v2); 74 75 public: 76 float x; //!< The x Coordinate of the Vector. 77 float y; //!< The y Coordinate of the Vector. 78 float z; //!< The z Coordinate of the Vector. 79 }; 80 81 /** 82 \brief calculate the angle between two vectors in radiances 83 \param v1: a vector 84 \param v2: another vector 85 \return the angle between the vectors in radians 86 */ 87 inline float angleDeg (const Vector& v1, const Vector& v2) { return acos( v1 * v2 / (v1.len() * v2.len())); }; 88 /** 89 \brief calculate the angle between two vectors in degrees 90 \param v1: a vector 91 \param v2: another vector 92 \return the angle between the vectors in degrees 93 */ 94 inline float angleRad (const Vector& v1, const Vector& v2) { return acos( v1 * v2 / (v1.len() * v2.len())) * 180/M_PI; }; 95 66 96 67 97 //! Quaternion 68 98 /** 69 99 Class to handle 3-dimensional rotation efficiently 70 100 */ 71 101 class Quaternion 72 102 { 73 103 public: 74 Vector v;//!< Imaginary Vector75 float w; //!< Real part of the number104 Vector v; //!< Imaginary Vector 105 float w; //!< Real part of the number 76 106 77 107 inline Quaternion () { w = 1; v = Vector(0,0,0); }
Note: See TracChangeset
for help on using the changeset viewer.