00001 #ifndef __J2K__Vector2_HPP__ 00002 #define __J2K__Vector2_HPP__ 00003 00004 #include <j2k/Fred/Basic.hpp> 00005 #include <j2k/Fred/Boolean.hpp> 00006 #include <j2k/Fred/StdTypes.hpp> 00007 #include <math.h> 00008 00009 #ifndef __J2K__Vector3_HPP__ 00010 class JVector2; 00011 class JVector3; 00012 #endif 00013 00014 class JVector2 { 00015 public: 00016 00017 JVector2() {} 00018 JVector2(const JVector3& obj); 00019 JVector2(const JVector2& obj); 00020 00021 JVector2(double x, double y) { 00022 v[0] = x; 00023 v[1] = y; 00024 } 00025 00026 virtual ~JVector2() {} 00027 00028 void print(); 00029 JVector2 rotate(double rad); 00030 00031 void add(JVector2); 00032 void subtract(JVector2); 00033 void multiply(double); 00034 void divide(double); 00035 00036 double dot(JVector2); 00037 void cross(JVector2); 00038 00039 void negative(); 00040 double length(); 00041 void unit(); 00042 00043 double comp(JVector2); 00044 JVector2 proj(JVector2); 00045 00046 // operators 00047 double operator[](int); // return index 00048 JVector2 operator()(double, double); // assign doubles 00049 00050 JVector2 operator+(JVector2); // add 00051 JVector2 operator-(JVector2); // subtract 00052 JVector2 operator*(double); // multiply 00053 friend JVector2 operator*(double, JVector2); 00054 JVector2 operator/(double); // divide 00055 friend JVector2 operator/(double, JVector2); 00056 double operator*(JVector2); // dot product 00057 JVector2 operator%(JVector2); // cross product 00058 00059 void operator+=(JVector2 val) { add(val); } 00060 void operator-=(JVector2 val) { subtract(val); } 00061 void operator*=(double val) { multiply(val); } 00062 void operator/=(double val) { divide(val); } 00063 void operator%=(JVector2 val) { cross(val); } 00064 00065 JVector2 operator-(); // negation 00066 double operator!(); // absolute value, length 00067 JVector2 operator~(); // unit vector 00068 00069 BOOL operator==(JVector2 val) 00070 { 00071 if (v[0] == val.v[0]) 00072 if (v[1] == val.v[1]) 00073 if (v[2] == val.v[2]) 00074 return true; 00075 00076 return false; 00077 } 00078 00079 // protected: 00080 double v[2]; 00081 }; 00082 00083 #ifndef __J2K__Vector3_HPP__ 00084 #include <j2k/Fred/Math/Vector/Vector3.hpp> 00085 #include <j2k/Fred/Math/Vector/Vector3.cpp> 00086 #endif 00087 00088 #endif