Page principale   Liste des namespaces   Hiérarchie des classes   Liste par ordre alphabétique   Liste des composants   Liste des fichiers   Composants   Déclarations  

ExCVec3D.cpp

Aller à la documentation de ce fichier.
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  * $Id: ExCVec3D.cpp,v 1.6 2002/07/08 23:14:46 data Exp $
00021  *
00022  */
00023 
00024 #include "ExCVec3D.h"
00025 
00026 // Construction/Destruction
00027 
00028 ExCVec3D::ExCVec3D()
00029 {
00030         m_Vector[0]=0;m_Vector[1]=0;m_Vector[2]=0;
00031 }
00032 
00033 ExCVec3D::ExCVec3D(float x,float y,float z)
00034 {
00035         m_Vector[0]=x;m_Vector[1]=y;m_Vector[2]=z;
00036 }
00037 
00038 ExCVec3D::~ExCVec3D()
00039 {
00040 
00041 }
00042 
00043 // Methode
00044 
00045 float ExCVec3D::GetVectorLenght(void)
00046 {
00047         return sqrt((m_Vector[0]*m_Vector[0])+(m_Vector[1]*m_Vector[1])+(m_Vector[2]*m_Vector[2]));
00048 }
00049 ExCVec3D ExCVec3D::GetVecNormale(void)
00050 {
00051         ExCVec3D VecNorm;
00052         VecNorm=*this;
00053         VecNorm=*this/this->GetVectorLenght();
00054         return VecNorm;
00055 }
00056 void ExCVec3D::SetValue(float x,float y,float z)
00057 {
00058         m_Vector[0]=x;
00059         m_Vector[1]=y;
00060         m_Vector[2]=z;
00061 }
00062 
00063 void ExCVec3D::Draw(void)
00064 {
00065         ExCVec3D vx,vy,vz;
00066         ExCVec3D source;
00067 
00068         source.SetValue(0.0f,0.0f,0.0f);
00069 
00070         
00071 
00072         vx.m_Vector[0]=this->m_Vector[0]+1.0f;
00073         vy.m_Vector[1]=this->m_Vector[1]+1.0f;
00074         vz.m_Vector[2]=this->m_Vector[2]+1.0f;
00075 
00076 
00077         glBegin(GL_TRIANGLES);
00078                 glColor3ub(255,255,255);
00079                 glVertex3f(0.0f,0.0f,0.0f);
00080                 glVertex3f(1.0f,1.0f,1.0f);
00081                 glVertex3f(-1.0f,-1.0f,-1.0f);
00082         glEnd();
00083 
00084         glBegin(GL_LINE);
00085                 glColor3ub(255,0,0);
00086                         glVertex3fv(source.m_Vector);
00087                         glVertex3fv(vx.m_Vector);
00088                 glColor3ub(0,255,0);
00089                         glVertex3fv(source.m_Vector);
00090                         glVertex3fv(vy.m_Vector);
00091                 glColor3ub(0,0,255);
00092                         glVertex3fv(source.m_Vector);
00093                         glVertex3fv(vz.m_Vector);
00094         glEnd();
00095 }
00096 
00097 // Operator surcharge
00098 ExCVec3D& ExCVec3D::operator =(const ExCVec3D& Vec)
00099 {
00100         m_Vector[0]=Vec.m_Vector[0];
00101         m_Vector[1]=Vec.m_Vector[1];
00102         m_Vector[2]=Vec.m_Vector[2];
00103         return *this;
00104 }
00105 bool  ExCVec3D::operator==(const ExCVec3D& Vec)
00106 {
00107         if(m_Vector[0]==Vec.m_Vector[0]||m_Vector[1]==Vec.m_Vector[1]||m_Vector[2]==Vec.m_Vector[2]) return true;
00108         else return false;
00109 }
00110 
00111 ExCVec3D  ExCVec3D::operator+(const ExCVec3D& Vec)
00112 {
00113         ExCVec3D RetVec;
00114         RetVec.m_Vector[0]=m_Vector[0]+Vec.m_Vector[0];
00115         RetVec.m_Vector[1]=m_Vector[1]+Vec.m_Vector[1];
00116         RetVec.m_Vector[2]=m_Vector[2]+Vec.m_Vector[2];
00117         return RetVec;
00118 }
00119 
00120 ExCVec3D  ExCVec3D::operator-(const ExCVec3D& Vec)
00121 {
00122         ExCVec3D RetVec;
00123         RetVec.m_Vector[0]=m_Vector[0]-Vec.m_Vector[0];
00124         RetVec.m_Vector[1]=m_Vector[1]-Vec.m_Vector[1];
00125         RetVec.m_Vector[2]=m_Vector[2]-Vec.m_Vector[2];
00126         return RetVec;
00127 }
00128 ExCVec3D  ExCVec3D::operator*(const ExCVec3D& Vec)
00129 {
00130         ExCVec3D RetVec;
00131         RetVec.m_Vector[0]=m_Vector[0]*Vec.m_Vector[0];
00132         RetVec.m_Vector[1]=m_Vector[1]*Vec.m_Vector[1];
00133         RetVec.m_Vector[2]=m_Vector[2]*Vec.m_Vector[2];
00134         return RetVec;
00135 }
00136 ExCVec3D  ExCVec3D::operator*(float scalar)
00137 {
00138         ExCVec3D RetVec;
00139         RetVec.m_Vector[0]=m_Vector[0]*scalar;
00140         RetVec.m_Vector[1]=m_Vector[1]*scalar;
00141         RetVec.m_Vector[2]=m_Vector[2]*scalar;
00142         return RetVec;
00143 }
00144 ExCVec3D  ExCVec3D::operator/(const ExCVec3D& Vec)
00145 {
00146         ExCVec3D RetVec;
00147         RetVec.m_Vector[0]=m_Vector[0]/Vec.m_Vector[0];
00148         RetVec.m_Vector[1]=m_Vector[1]/Vec.m_Vector[1];
00149         RetVec.m_Vector[2]=m_Vector[2]/Vec.m_Vector[2];
00150         return RetVec;
00151 }
00152 ExCVec3D  ExCVec3D::operator/(float scalar)
00153 {
00154         ExCVec3D RetVec;
00155         RetVec.m_Vector[0]=m_Vector[0]/scalar;
00156         RetVec.m_Vector[1]=m_Vector[1]/scalar;
00157         RetVec.m_Vector[2]=m_Vector[2]/scalar;
00158         return RetVec;
00159 }
00160 
00161 // Friends
00162 std::ostream& operator<<(std::ostream& s,const ExCVec3D &vec)
00163 {
00164         s<<"X:"<<(float)vec.m_Vector[0]<<" Y:"<<(float)vec.m_Vector[1]<<" Z:"<<(float)vec.m_Vector[2];
00165         return s;
00166 }
00167 

Généré le Tue Aug 6 20:25:26 2002 pour ExNihilo par doxygen1.2.17