00001 /* 00002 * ExNihilo 3D Engine 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 * 00018 * Please read AUTHORS file !!! 00019 * 00020 00021 * 00022 */ 00023 00024 #include "ExCVec2D.h" 00025 00026 // Construction/Destruction 00027 00028 ExCVec2D::ExCVec2D() 00029 { 00030 m_Vector[0]=0;m_Vector[1]=0; 00031 } 00032 00033 ExCVec2D::ExCVec2D(float x,float y) 00034 { 00035 m_Vector[0]=x;m_Vector[1]=y; 00036 } 00037 00038 ExCVec2D::~ExCVec2D() 00039 { 00040 00041 } 00042 00043 // Methode 00044 00045 float ExCVec2D::GetVectorLenght(void) 00046 { 00047 return sqrt((m_Vector[0]*m_Vector[0])+(m_Vector[1]*m_Vector[1])); 00048 } 00049 ExCVec2D ExCVec2D::GetVecNormale(void) 00050 { 00051 ExCVec2D VecNorm; 00052 VecNorm=*this; 00053 VecNorm=*this/this->GetVectorLenght(); 00054 return VecNorm; 00055 } 00056 void ExCVec2D::SetValue(float x,float y) 00057 { 00058 m_Vector[0]=x; 00059 m_Vector[1]=y; 00060 00061 } 00062 00063 00064 // Operator surcharge 00065 ExCVec2D& ExCVec2D::operator =(const ExCVec2D& Vec) 00066 { 00067 m_Vector[0]=Vec.m_Vector[0]; 00068 m_Vector[1]=Vec.m_Vector[1]; 00069 return *this; 00070 } 00071 bool ExCVec2D::operator==(const ExCVec2D& Vec) 00072 { 00073 if(m_Vector[0]==Vec.m_Vector[0]||m_Vector[1]==Vec.m_Vector[1]) return true; 00074 else return false; 00075 } 00076 00077 ExCVec2D ExCVec2D::operator+(const ExCVec2D& Vec) 00078 { 00079 ExCVec2D RetVec; 00080 RetVec.m_Vector[0]=m_Vector[0]+Vec.m_Vector[0]; 00081 RetVec.m_Vector[1]=m_Vector[1]+Vec.m_Vector[1]; 00082 return RetVec; 00083 } 00084 00085 ExCVec2D ExCVec2D::operator-(const ExCVec2D& Vec) 00086 { 00087 ExCVec2D RetVec; 00088 RetVec.m_Vector[0]=m_Vector[0]-Vec.m_Vector[0]; 00089 RetVec.m_Vector[1]=m_Vector[1]-Vec.m_Vector[1]; 00090 return RetVec; 00091 } 00092 ExCVec2D ExCVec2D::operator*(const ExCVec2D& Vec) 00093 { 00094 ExCVec2D RetVec; 00095 RetVec.m_Vector[0]=m_Vector[0]*Vec.m_Vector[0]; 00096 RetVec.m_Vector[1]=m_Vector[1]*Vec.m_Vector[1]; 00097 return RetVec; 00098 } 00099 ExCVec2D ExCVec2D::operator*(float scalar) 00100 { 00101 ExCVec2D RetVec; 00102 RetVec.m_Vector[0]=m_Vector[0]*scalar; 00103 RetVec.m_Vector[1]=m_Vector[1]*scalar; 00104 return RetVec; 00105 } 00106 ExCVec2D ExCVec2D::operator/(const ExCVec2D& Vec) 00107 { 00108 ExCVec2D RetVec; 00109 RetVec.m_Vector[0]=m_Vector[0]/Vec.m_Vector[0]; 00110 RetVec.m_Vector[1]=m_Vector[1]/Vec.m_Vector[1]; 00111 return RetVec; 00112 } 00113 ExCVec2D ExCVec2D::operator/(float scalar) 00114 { 00115 ExCVec2D RetVec; 00116 RetVec.m_Vector[0]=m_Vector[0]/scalar; 00117 RetVec.m_Vector[1]=m_Vector[1]/scalar; 00118 return RetVec; 00119 } 00120 00121 // Friends 00122 std::ostream& operator<<(std::ostream& s,const ExCVec2D &vec) 00123 { 00124 s<<"X:"<<(float)vec.m_Vector[0]<<" Y:"<<(float)vec.m_Vector[1]; 00125 return s; 00126 } 00127