_Vector2.h

Go to the documentation of this file.
00001 #ifndef __VECMATH_VECTOR2_HPP
00002 #define __VECMATH_VECTOR2_HPP
00003 
00004 #ifndef __VECMATH_TUPLE2_HPP
00005 #include <vecmath/_Tuple2.h>
00006 #endif
00007 
00008 //#define DEBUGVECTOR2(d) d
00009 #define DEBUGVECTOR2(d)
00010 
00011 template <class Type> class VECMATH_EXPORT _Vector2 : public _Tuple2<Type> {
00012 public:
00013 
00014     _Vector2<Type>() : _Tuple2<Type>() {}
00015 
00016     // prevent implicit constructors!!!
00017     explicit _Vector2<Type>(Type x , Type y = 0) : _Tuple2<Type>(x, y) {
00018         DEBUGVECTOR3(cout << "_Vector2 constructor x,y " << *this << endl);
00019     }
00020 
00021     _Vector2<Type>(const _Tuple2<double>& v) : _Tuple2<Type>(v) {
00022         DEBUGVECTOR2(cout << "_Vector2 constructor &double " << *this << endl);
00023     }
00024 
00025     _Vector2<Type>(const _Tuple2<float>& v) : _Tuple2<Type>(v) {
00026         DEBUGVECTOR2(cout << "_Vector2 constructor &float " << *this << endl);
00027     }
00028 
00029     _Vector2<Type>(const Type t[2]) : _Tuple2<Type>(t) {
00030         DEBUGVECTOR2(cout << "_Vector2 constructor t[2] " << *this << endl);
00031     }
00032 
00033     Type angle(const _Vector2<Type>& v) const {
00034         double d = dot(v) / (length() * v.lentgh());
00035         if (d < -1)
00036             d = -1;
00037         else if (d > 1)
00038             d = 1;
00039         return (Type) acos(d);
00040     }
00041 
00042     Type dot(const _Vector2<Type>& v) const {
00043         return _Tuple2<Type>::x * v.x + _Tuple2<Type>::y * v.y;
00044     }
00045 
00046     Type lengthSquared() const {
00047         return _Tuple2<Type>::normSquared();
00048     }
00049 
00050     Type length() const {
00051         return _Tuple2<Type>::norm();
00052     }
00053 
00054     void normalize() {
00055         normalize(*this);
00056     }
00057 
00058     void normalize(const _Vector2<Type> &v) {
00059         Type l = length();
00060         this->set(v.x / l, v.y / l);
00061     }
00062 };
00063 
00064 #endif

Generated on Thu Sep 29 13:39:44 2005 for vecmath by  doxygen 1.4.4