00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00089 TLineArray vResultLine = _rvLine ;
00090
00091 for(size_t iV0=0; iV0<_rvLine.size(); iV0++)
00092 {
00093
00094 K3dLineObj *pLine0 = _rvLine[iV0];
00095 for(size_t iV1=iV0+1; iV1<_rvLine.size(); iV1++)
00096 {
00097
00098 K3dLineObj *pLine1 = _rvLine[iV1];
00099
00100 if(*pLine0->GetOrigin() == *pLine1->GetOrigin())
00101 {
00102 if(*pLine0->GetDirection() == *pLine1->GetDirection())
00103 {
00104
00105 DeleteLine(pLine0, vResultLine);
00106 break;
00107 }
00108 }
00109 if(*pLine0->GetOrigin() == *pLine1->GetDirection())
00110 {
00111 if(*pLine0->GetDirection() == *pLine1->GetOrigin())
00112 {
00113
00114 DeleteLine(pLine0, vResultLine);
00115 break;
00116 }
00117 }
00118 }
00119 }
00120
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 }