K3dLineWork.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 "K3dLineWork.h"
00034 
00035 K3dLineWork::K3dLineWork(K3dGameData *_pGameData)
00036 {
00037         m_pGameData = _pGameData;
00038 }
00039 
00040 K3dLineWork::~K3dLineWork(void)
00041 {
00042 }
00043 
00045 int K3dLineWork::FindLineId(const char* _strName)
00046 {
00047         K3dString strName(_strName);
00048         for(int i=0; i<m_pGameData->GetLineObjSP().GetNum(); i++)
00049         {
00050                 K3dLineObj *pLine = m_pGameData->GetLineObjSP().Get(i);
00051                 if(strName == pLine->GetName())
00052                 {
00053                         return i;
00054                 }
00055         }
00056         return -1;
00057 }
00058 
00060 void K3dLineWork::UpdateLines()
00061 {
00062         for(int i=0; i<m_pGameData->GetLineObjSP().GetNum(); i++)
00063         {
00064                 m_pGameData->GetLineObjSP().Get(i)->UpdateMatrix();
00065         }
00066 }
00067 
00071 void K3dLineWork::DeleteLine(K3dLineObj *_pLine, TLineArray &_rvLine)
00072 {
00073         TLineArray::iterator it = find(_rvLine.begin(), _rvLine.end(), _pLine);
00074         if(it != _rvLine.end())
00075         {
00076                 _rvLine.erase(it);
00077         }
00078         else
00079         {
00080                 cerr <<  "Error -- void K3dLineWork::DeleteLine() -- Vertex  " << _pLine << " doesn't exists " << endl;
00081         }
00082 }
00083 
00086 void K3dLineWork::DeleteDupLines(TLineArray &_rvLine)
00087 {
00088         // Set result line array
00089         TLineArray vResultLine = _rvLine ;
00090         //Go through arbitrary lines in line array
00091         for(size_t iV0=0; iV0<_rvLine.size(); iV0++)
00092         {
00093                 // Get first line
00094                 K3dLineObj *pLine0 = _rvLine[iV0];
00095                 for(size_t iV1=iV0+1; iV1<_rvLine.size(); iV1++)
00096                 {
00097                         // Get second vertex
00098                         K3dLineObj *pLine1 = _rvLine[iV1];
00099                         // Compare lines
00100                         if(*pLine0->GetOrigin() == *pLine1->GetOrigin())
00101                         {
00102                                 if(*pLine0->GetDirection() == *pLine1->GetDirection())
00103                                 {
00104                                         // Is vertices equal, delete this vertex from result vertex array
00105                                         DeleteLine(pLine0, vResultLine);
00106                                         break;
00107                                 }
00108                         }
00109                         if(*pLine0->GetOrigin() == *pLine1->GetDirection())
00110                         {
00111                                 if(*pLine0->GetDirection() == *pLine1->GetOrigin())
00112                                 {
00113                                         // Is vertices equal, delete this vertex from result vertex array
00114                                         DeleteLine(pLine0, vResultLine);
00115                                         break;
00116                                 }
00117                         }
00118                 }
00119         }
00120         // Set output vertex array
00121         _rvLine = vResultLine;
00122 }
00123 
00126 void K3dLineWork::CheckLineArray(TLineArray &_rvLine)
00127 {
00128         cout << "void K3dLineWork::CheckLineArray(TLineArray &_rvLine)" << endl;
00129         cout << "Number of lines = " << _rvLine.size() << endl;
00130         for(size_t i=0; i<_rvLine.size(); i++)
00131         {
00132                 cout << "Line " << i << endl;
00133                 K3dLineObj *pLine = _rvLine[i];
00134                 cout << "Line id = " << pLine->GetId() <<  endl;
00135         }
00136 }

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