K3dVertexWork.cpp

Go to the documentation of this file.
00001 
00012 /***************************************************************************
00013  *   Copyright (C) 2007 by Jan Koci   *
00014  *   honza.koci@email.cz   *
00015  *   http://kengine.sourceforge.net/tutorial/
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  *   This program is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00025  *   GNU General Public License for more details.                          *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU General Public License     *
00028  *   along with this program; if not, write to the                         *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00031  ***************************************************************************/
00032 
00033 #include "K3dVertexWork.h"
00034 
00035 K3dVertexWork::K3dVertexWork(K3dGameData *_pGameData)
00036 {
00037         m_pGameData = _pGameData;
00038         // Set this pointer to the game data
00039         m_pGameData->SetVertexWork(this);
00040 }
00041 
00042 K3dVertexWork::~K3dVertexWork(void)
00043 {
00044 }
00045 
00047 int K3dVertexWork::FindVertexId(const char* _strName)
00048 {
00049         K3dString strName(_strName);
00050         for(int i=0; i<m_pGameData->GetVertexObjSP().GetNum(); i++)
00051         {
00052                 K3dVertexObj *pVertex = m_pGameData->GetVertexObjSP().Get(i);
00053                 if(strName == pVertex->GetName())
00054                 {
00055                         return i;
00056                 }
00057         }
00058         return -1;
00059 }
00060 
00062 K3dVertexObj *K3dVertexWork::FindVertex(const char* _strName)
00063 {
00064         K3dString strName(_strName);
00065         for(int i=0; i<m_pGameData->GetVertexObjSP().GetNum(); i++)
00066         {
00067                 K3dVertexObj *pVertex = m_pGameData->GetVertexObjSP().Get(i);
00068                 if(strName == pVertex->GetName())
00069                 {
00070                         return pVertex;
00071                 }
00072         }
00073         return NULL;
00074 }
00075 
00077 void K3dVertexWork::CheckVertexArray(TVertexArray &_rvVertex, ofstream *_pOut)
00078 {
00079         cout << "void K3dVertexBuild::CheckVertexArray(TVertexArray &_rvVertex" << endl;
00080         *_pOut << "Num verts" << _rvVertex.size() << endl;
00081         for(int i=0; i<(int)_rvVertex.size(); i++)
00082         {
00083                 *_pOut << "Vertex " << i << endl;
00084                 *_pOut << "Position X = " << _rvVertex[i]->GetPosition()->GetX() << endl;
00085                 *_pOut << "Position Y = " << _rvVertex[i]->GetPosition()->GetY() << endl;
00086                 *_pOut << "Position Z = " << _rvVertex[i]->GetPosition()->GetZ() << endl;
00087                 *_pOut << "Tex coord X = " << _rvVertex[i]->GetTexCoord()->GetX() << endl;
00088                 *_pOut << "Tex coord Y = " << _rvVertex[i]->GetTexCoord()->GetY() << endl;
00089                 *_pOut << "Normal X = " << _rvVertex[i]->GetNormal()->GetX() << endl;
00090                 *_pOut << "Normal Y = " << _rvVertex[i]->GetNormal()->GetY() << endl;
00091                 *_pOut << "Normal Z = " << _rvVertex[i]->GetNormal()->GetZ() << endl;
00092                 *_pOut << "Color R = " << _rvVertex[i]->GetColor()->GetR() << endl;
00093                 *_pOut << "Color G = " << _rvVertex[i]->GetColor()->GetG() << endl;
00094                 *_pOut << "Color B = " << _rvVertex[i]->GetColor()->GetB() << endl;
00095                 *_pOut << "Size = " << _rvVertex[i]->GetSize() << endl;
00096                 
00097         }
00098 }
00099 
00103 void K3dVertexWork::DeleteVertex(K3dVertexObj *_pVertex, TVertexArray &_rvVertex)
00104 {
00105         TVertexArray::iterator it = find(_rvVertex.begin(), _rvVertex.end(), _pVertex);
00106         if(it != _rvVertex.end())
00107         {
00108                 _rvVertex.erase(it);
00109         }
00110         else
00111         {
00112                 cerr <<  "Error --  K3dPoly::DeleteVertex -- Vertex  " << _pVertex << " doesn't exists " << endl;
00113         }
00114 }
00115 
00116 
00119 void K3dVertexWork::DeleteDupVerts(TVertexArray &_rvVertex)
00120 {
00121         // Set result vertex array
00122         TVertexArray vResultVertex = _rvVertex ;
00123         //Go through arbitrary vertices in vertex array
00124         for(size_t iV0=0; iV0<_rvVertex.size(); iV0++)
00125         {
00126                 // Get first vertex
00127                 K3dVertexObj *pVertex0 = _rvVertex[iV0];
00128                 for(size_t iV1=iV0+1; iV1<_rvVertex.size(); iV1++)
00129                 {
00130                         // Get second vertex
00131                         K3dVertexObj *pVertex1 = _rvVertex[iV1];
00132                         // Compare vertices
00133                         if(*pVertex0->GetPosition() == *pVertex1->GetPosition())
00134                         {
00135                                 // Is vertices equal, delete this vertex from result vertex array
00136                                 DeleteVertex(pVertex0, vResultVertex);
00137                                 break;
00138                         }
00139                 }
00140         }
00141         // Set output vertex array
00142         _rvVertex = vResultVertex;
00143 }

Generated on Thu Aug 16 23:53:29 2007 for K3dEngine by  doxygen 1.5.0