00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "K3dVertexWork.h"
00034
00035 K3dVertexWork::K3dVertexWork(K3dGameData *_pGameData)
00036 {
00037 m_pGameData = _pGameData;
00038
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
00122 TVertexArray vResultVertex = _rvVertex ;
00123
00124 for(size_t iV0=0; iV0<_rvVertex.size(); iV0++)
00125 {
00126
00127 K3dVertexObj *pVertex0 = _rvVertex[iV0];
00128 for(size_t iV1=iV0+1; iV1<_rvVertex.size(); iV1++)
00129 {
00130
00131 K3dVertexObj *pVertex1 = _rvVertex[iV1];
00132
00133 if(*pVertex0->GetPosition() == *pVertex1->GetPosition())
00134 {
00135
00136 DeleteVertex(pVertex0, vResultVertex);
00137 break;
00138 }
00139 }
00140 }
00141
00142 _rvVertex = vResultVertex;
00143 }