00001
00002
00003
00004 #include "stdafx.h"
00005 #include "Asc2Map.h"
00006 #include "Asc2MapDlg.h"
00007
00008 #ifdef _DEBUG
00009 #define new DEBUG_NEW
00010 #endif
00011
00012
00013
00014
00015 class CAboutDlg : public CDialog
00016 {
00017 public:
00018 CAboutDlg();
00019
00020
00021 enum { IDD = IDD_ABOUTBOX };
00022
00023 protected:
00024 virtual void DoDataExchange(CDataExchange* pDX);
00025
00026
00027 protected:
00028 DECLARE_MESSAGE_MAP()
00029 };
00030
00031 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
00032 {
00033 }
00034
00035 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
00036 {
00037 CDialog::DoDataExchange(pDX);
00038 }
00039
00040 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
00041 END_MESSAGE_MAP()
00042
00043
00044
00045
00046
00047
00048 CAsc2MapDlg::CAsc2MapDlg(CWnd* pParent )
00049 : CDialog(CAsc2MapDlg::IDD, pParent)
00050 , m_SAscFileName(_T(""))
00051 , m_SMapFile(_T(""))
00052 , m_STextureName(_T("NONE"))
00053 , m_STextureNameBottom(_T("NONE"))
00054 , m_STextureNameFront(_T("NONE"))
00055 , m_STextureNameBack(_T("NONE"))
00056 , m_STextureNameLeft(_T("NONE"))
00057 , m_STextureNameRight(_T("NONE"))
00058 {
00059 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
00060 }
00061
00062 void CAsc2MapDlg::DoDataExchange(CDataExchange* pDX)
00063 {
00064 CDialog::DoDataExchange(pDX);
00065 DDX_Text(pDX, IDC_EDITASCFILE, m_SAscFileName);
00066 DDX_Text(pDX, IDC_EDITMAPFILE, m_SMapFile);
00067 DDX_Text(pDX, IDC_EDITTEXTURE, m_STextureName);
00068 DDX_Control(pDX, IDC_EDITASCFILE, m_CAscFile);
00069 DDX_Text(pDX, IDC_EDIT4, m_STextureNameBottom);
00070 DDX_Text(pDX, IDC_EDIT5, m_STextureNameFront);
00071 DDX_Text(pDX, IDC_EDIT6, m_STextureNameBack);
00072 DDX_Text(pDX, IDC_EDIT7, m_STextureNameLeft);
00073 DDX_Text(pDX, IDC_EDIT8, m_STextureNameRight);
00074 }
00075
00076 BEGIN_MESSAGE_MAP(CAsc2MapDlg, CDialog)
00077 ON_WM_SYSCOMMAND()
00078 ON_WM_PAINT()
00079 ON_WM_QUERYDRAGICON()
00080
00081 ON_BN_CLICKED(IDOK, OnBnClickedOk)
00082 ON_BN_CLICKED(IDC_BUTBROWSEASC, OnBnClickedButbrowseasc)
00083 ON_BN_CLICKED(IDC_BUTBROWSETEXTTOP, OnBnClickedButbrowsetexttop)
00084 ON_BN_CLICKED(IDC_BUTBROWSETEXTBOTTOM, OnBnClickedButbrowsetextbottom)
00085 ON_BN_CLICKED(IDC_BUTBROWSETEXTFRONT, OnBnClickedButbrowsetextfront)
00086 ON_BN_CLICKED(IDC_BUTBROWSETEXTBACK, OnBnClickedButbrowsetextback)
00087 ON_BN_CLICKED(IDC_BUTBROWSETEXTLEFT, OnBnClickedButbrowsetextleft)
00088 ON_BN_CLICKED(IDC_BUTBROWSETEXTRIGHT, OnBnClickedButbrowsetextright)
00089 ON_BN_CLICKED(IDC_BUTBROWSEMAPFILE, OnBnClickedButbrowsemapfile)
00090 END_MESSAGE_MAP()
00091
00092
00093
00094
00095 BOOL CAsc2MapDlg::OnInitDialog()
00096 {
00097 CDialog::OnInitDialog();
00098
00099
00100
00101
00102 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
00103 ASSERT(IDM_ABOUTBOX < 0xF000);
00104
00105 CMenu* pSysMenu = GetSystemMenu(FALSE);
00106 if (pSysMenu != NULL)
00107 {
00108 CString strAboutMenu;
00109 strAboutMenu.LoadString(IDS_ABOUTBOX);
00110 if (!strAboutMenu.IsEmpty())
00111 {
00112 pSysMenu->AppendMenu(MF_SEPARATOR);
00113 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
00114 }
00115 }
00116
00117
00118
00119 SetIcon(m_hIcon, TRUE);
00120 SetIcon(m_hIcon, FALSE);
00121
00122
00123
00124 return TRUE;
00125 }
00126
00127 void CAsc2MapDlg::OnSysCommand(UINT nID, LPARAM lParam)
00128 {
00129 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
00130 {
00131 CAboutDlg dlgAbout;
00132 dlgAbout.DoModal();
00133 }
00134 else
00135 {
00136 CDialog::OnSysCommand(nID, lParam);
00137 }
00138 }
00139
00140
00141
00142
00143
00144 void CAsc2MapDlg::OnPaint()
00145 {
00146 if (IsIconic())
00147 {
00148 CPaintDC dc(this);
00149
00150 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
00151
00152
00153 int cxIcon = GetSystemMetrics(SM_CXICON);
00154 int cyIcon = GetSystemMetrics(SM_CYICON);
00155 CRect rect;
00156 GetClientRect(&rect);
00157 int x = (rect.Width() - cxIcon + 1) / 2;
00158 int y = (rect.Height() - cyIcon + 1) / 2;
00159
00160
00161 dc.DrawIcon(x, y, m_hIcon);
00162 }
00163 else
00164 {
00165 CDialog::OnPaint();
00166 }
00167 }
00168
00169
00170
00171 HCURSOR CAsc2MapDlg::OnQueryDragIcon()
00172 {
00173 return static_cast<HCURSOR>(m_hIcon);
00174 }
00175
00176 void CAsc2MapDlg::OnBnClickedOk()
00177 {
00178
00179 UpdateData(true);
00180
00181 if(m_SAscFileName.IsEmpty())
00182 {
00183 AfxMessageBox("You must select a model file");
00184 return;
00185 }
00186 if(m_SMapFile.IsEmpty())
00187 {
00188 AfxMessageBox("You must select a file to save the map");
00189 return;
00190 }
00191
00192 CreateMapFile();
00193
00194
00195 }
00196
00197 void CAsc2MapDlg::OnBnClickedButbrowseasc()
00198 {
00199
00200 char szFilters[]="Asc Model Files (*.asc)|*.asc|All Files (*.*)|*.*||";
00201 CFileDialog fileDlg(true,"*.asc",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters,this);
00202 if(fileDlg.DoModal()==IDOK)
00203 {
00204 m_SAscFileName=fileDlg.GetPathName();
00205 }
00206 UpdateData(false);
00207 }
00208
00209
00210 void CAsc2MapDlg::OnBnClickedButbrowsetexttop()
00211 {
00212
00213 char szFilters[]="Texture Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
00214 CFileDialog fileDlg(true,"*.bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters,this);
00215 if(fileDlg.DoModal()==IDOK)
00216 {
00217 m_STextureName = fileDlg.GetFileName ();
00218
00219 }
00220 UpdateData(false);
00221 }
00222
00223 void CAsc2MapDlg::OnBnClickedButbrowsetextbottom()
00224 {
00225
00226 char szFilters[]="Texture Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
00227 CFileDialog fileDlg(true,"*.bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters,this);
00228 if(fileDlg.DoModal()==IDOK)
00229 {
00230 m_STextureNameBottom = fileDlg.GetFileName ();
00231 }
00232 UpdateData(false);
00233 }
00234
00235 void CAsc2MapDlg::OnBnClickedButbrowsetextfront()
00236 {
00237
00238 char szFilters[]="Texture Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
00239 CFileDialog fileDlg(true,"*.bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters,this);
00240 if(fileDlg.DoModal()==IDOK)
00241 {
00242 m_STextureNameFront = fileDlg.GetFileName ();
00243 }
00244 UpdateData(false);
00245 }
00246
00247 void CAsc2MapDlg::OnBnClickedButbrowsetextback()
00248 {
00249
00250 char szFilters[]="Texture Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
00251 CFileDialog fileDlg(true,"*.bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters,this);
00252 if(fileDlg.DoModal()==IDOK)
00253 {
00254 m_STextureNameBack = fileDlg.GetFileName ();
00255 }
00256 UpdateData(false);
00257 }
00258
00259 void CAsc2MapDlg::OnBnClickedButbrowsetextleft()
00260 {
00261
00262 char szFilters[]="Texture Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
00263 CFileDialog fileDlg(true,"*.bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters,this);
00264 if(fileDlg.DoModal()==IDOK)
00265 {
00266 m_STextureNameLeft = fileDlg.GetFileName ();
00267 }
00268 UpdateData(false);
00269 }
00270
00271 void CAsc2MapDlg::OnBnClickedButbrowsetextright()
00272 {
00273
00274 char szFilters[]="Texture Files (*.bmp)|*.bmp|All Files (*.*)|*.*||";
00275 CFileDialog fileDlg(true,"*.bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters,this);
00276 if(fileDlg.DoModal()==IDOK)
00277 {
00278 m_STextureNameRight = fileDlg.GetFileName ();
00279 }
00280 UpdateData(false);
00281 }
00282
00283 void CAsc2MapDlg::OnBnClickedButbrowsemapfile()
00284 {
00285
00286 char szFilters[]="Texture Files (*.map)|*.map|All Files (*.*)|*.*||";
00287 CFileDialog fileDlg(false,"*.map",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters,this);
00288 if(fileDlg.DoModal()==IDOK)
00289 {
00290 m_SMapFile = fileDlg.GetPathName();
00291 }
00292 UpdateData(false);
00293 }
00294
00295 void CAsc2MapDlg::CreateMapFile(void)
00296 {
00297
00298 bool endfile=false;
00299 int FileSize;
00300 size_t RetVal;
00301 int TmpFilePosition;
00302 int i,j,k;
00303 int TotalMash=0;
00304 int TotalNumberofVertex=0;
00305 int TotalNumberofFace=0;
00306 std::vector<SVertex> m_VecVertex;
00307 std::vector<SVertex>::iterator m_ItVecVertex;
00308 std::vector<SMesh> m_VecMesh;
00309 std::vector<SMesh>::iterator m_ItVecMesh;
00310
00311 AscFile=fopen (m_SAscFileName,"r");
00312
00313 if(!AscFile)
00314 {
00315 AfxMessageBox("Error opening asc file");
00316 return;
00317 }
00318
00319 fseek(AscFile,0,SEEK_END);
00320 FileSize=ftell(AscFile);
00321
00322
00323 fseek(AscFile,0,SEEK_SET);
00324 do
00325 {
00326 bool Textured=false;
00327 char ch;
00328 CString SName;
00329 CString SNumber;
00330 int NumberofVertex;
00331 int NumberofFace;
00332 SVertex VertexBuff;
00333 SMesh MeshBuff;
00334
00335
00336
00337 do
00338 {
00339 RetVal=fread(&ch,sizeof(char),1,AscFile);
00340 }while(ch!=34);
00341 TmpFilePosition=ftell(AscFile);
00342 i=0;
00343 do
00344 {
00345 RetVal=fread(&ch,sizeof(char),1,AscFile);i++;
00346 }while(ch!=34);
00347 fseek(AscFile,TmpFilePosition,SEEK_SET);
00348 for(j=0;j<i-1;j++)
00349 {
00350 RetVal=fread(&ch,sizeof(char),1,AscFile);
00351 SName=SName+ch;
00352 }
00353
00354
00355
00356
00357 do
00358 {
00359 RetVal=fread(&ch,sizeof(char),1,AscFile);
00360 }while(ch!=':');
00361 RetVal=fread(&ch,sizeof(char),1,AscFile);
00362 do
00363 {
00364 RetVal=fread(&ch,sizeof(char),1,AscFile);
00365 SNumber=SNumber+ch;
00366 }while(ch!=' ');
00367 NumberofVertex=(atol(SNumber));
00368
00369 SNumber.Delete(0,SNumber.GetLength());
00370 do
00371 {
00372 RetVal=fread(&ch,sizeof(char),1,AscFile);
00373 }while(ch!=':');
00374 RetVal=fread(&ch,sizeof(char),1,AscFile);
00375 do
00376 {
00377 RetVal=fread(&ch,sizeof(char),1,AscFile);
00378 SNumber=SNumber+ch;
00379 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00380 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00381 NumberofFace=(atol(SNumber));
00382
00383
00384
00385
00386
00387
00388 for(j=0;j<NumberofVertex;j++)
00389 {
00390 SNumber.Delete(0,SNumber.GetLength());
00391 do
00392 {
00393 RetVal=fread(&ch,sizeof(char),1,AscFile);
00394 }while(ch!='X');
00395 RetVal=fread(&ch,sizeof(char),1,AscFile);
00396 do
00397 {
00398 RetVal=fread(&ch,sizeof(char),1,AscFile);
00399 SNumber=SNumber+ch;
00400 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00401 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00402 try
00403 {
00404 VertexBuff.x=atof(SNumber);
00405 }catch(...)
00406 {
00407 VertexBuff.x=(0.0f);
00408 }
00409
00410 SNumber.Delete(0,SNumber.GetLength());
00411 do
00412 {
00413 RetVal=fread(&ch,sizeof(char),1,AscFile);
00414 }while(ch!='Y');
00415 RetVal=fread(&ch,sizeof(char),1,AscFile);
00416 do
00417 {
00418 RetVal=fread(&ch,sizeof(char),1,AscFile);
00419 SNumber=SNumber+ch;
00420 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00421 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00422 try
00423 {
00424 VertexBuff.y=atof(SNumber);
00425 }catch(...)
00426 {
00427 VertexBuff.y=0.0f;
00428 }
00429
00430 SNumber.Delete(0,SNumber.GetLength());
00431 do
00432 {
00433 RetVal=fread(&ch,sizeof(char),1,AscFile);
00434 }while(ch!='Z');
00435 RetVal=fread(&ch,sizeof(char),1,AscFile);
00436 do
00437 {
00438 RetVal=fread(&ch,sizeof(char),1,AscFile);
00439 SNumber=SNumber+ch;
00440 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00441 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00442 try
00443 {
00444 VertexBuff.z=atof(SNumber);
00445 }catch(...)
00446 {
00447 VertexBuff.z=0.0f;
00448 }
00449
00450 RetVal=fread(&ch,sizeof(char),1,AscFile);
00451 if(ch==' ')
00452 {
00453 Textured=true;
00454
00455 SNumber.Delete(0,SNumber.GetLength());
00456 do
00457 {
00458 RetVal=fread(&ch,sizeof(char),1,AscFile);
00459 }while(ch!='U');
00460 RetVal=fread(&ch,sizeof(char),1,AscFile);
00461 do
00462 {
00463 RetVal=fread(&ch,sizeof(char),1,AscFile);
00464 SNumber=SNumber+ch;
00465 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00466 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00467 VertexBuff.u=atof(SNumber);
00468
00469 SNumber.Delete(0,SNumber.GetLength());
00470 do
00471 {
00472 RetVal=fread(&ch,sizeof(char),1,AscFile);
00473 }while(ch!='V');
00474 RetVal=fread(&ch,sizeof(char),1,AscFile);
00475 do
00476 {
00477 RetVal=fread(&ch,sizeof(char),1,AscFile);
00478 SNumber=SNumber+ch;
00479 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00480 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00481 VertexBuff.v=atof(SNumber);
00482
00483 }else
00484 {
00485 VertexBuff.u=0;
00486 VertexBuff.v=0;
00487 }
00488 m_VecVertex.push_back(VertexBuff);
00489
00490 }
00491
00492
00493
00494 TotalMash=TotalMash+NumberofFace;
00495 for(j=0;j<NumberofFace;j++)
00496 {
00497 SNumber.Delete(0,SNumber.GetLength());
00498 do
00499 {
00500 RetVal=fread(&ch,sizeof(char),1,AscFile);
00501 }while(ch!='A');
00502 RetVal=fread(&ch,sizeof(char),1,AscFile);
00503
00504 do
00505 {
00506 RetVal=fread(&ch,sizeof(char),1,AscFile);
00507 SNumber=SNumber+ch;
00508 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00509 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00510 MeshBuff.A=(atoi(SNumber)+TotalNumberofVertex);
00511
00512
00513 SNumber.Delete(0,SNumber.GetLength());
00514 do
00515 {
00516 RetVal=fread(&ch,sizeof(char),1,AscFile);
00517 }while(ch!='B');
00518 RetVal=fread(&ch,sizeof(char),1,AscFile);
00519 do
00520 {
00521 RetVal=fread(&ch,sizeof(char),1,AscFile);
00522 SNumber=SNumber+ch;
00523 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00524 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00525 MeshBuff.B=(atoi(SNumber)+TotalNumberofVertex);
00526
00527 SNumber.Delete(0,SNumber.GetLength());
00528 do
00529 {
00530 RetVal=fread(&ch,sizeof(char),1,AscFile);
00531 }while(ch!='C');
00532 RetVal=fread(&ch,sizeof(char),1,AscFile);
00533 do
00534 {
00535 RetVal=fread(&ch,sizeof(char),1,AscFile);
00536 SNumber=SNumber+ch;
00537 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00538 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00539 MeshBuff.C=(atoi(SNumber)+TotalNumberofVertex);
00540
00541 do
00542 {
00543 RetVal=fread(&ch,sizeof(char),1,AscFile);
00544 }while(ch!='B');
00545 RetVal=fread(&ch,sizeof(char),1,AscFile);
00546 SNumber.Delete(0,SNumber.GetLength());
00547 do
00548 {
00549 RetVal=fread(&ch,sizeof(char),1,AscFile);
00550 SNumber=SNumber+ch;
00551 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00552 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00553 MeshBuff.AB=atoi(SNumber);
00554 do
00555 {
00556 RetVal=fread(&ch,sizeof(char),1,AscFile);
00557 }while(ch!='C');
00558 RetVal=fread(&ch,sizeof(char),1,AscFile);
00559 SNumber.Delete(0,SNumber.GetLength());
00560 do
00561 {
00562 RetVal=fread(&ch,sizeof(char),1,AscFile);
00563 SNumber=SNumber+ch;
00564 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00565 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00566 MeshBuff.BC=atoi(SNumber);
00567 do
00568 {
00569 RetVal=fread(&ch,sizeof(char),1,AscFile);
00570 }while(ch!='A');
00571 RetVal=fread(&ch,sizeof(char),1,AscFile);
00572 SNumber.Delete(0,SNumber.GetLength());
00573 do
00574 {
00575 RetVal=fread(&ch,sizeof(char),1,AscFile);
00576 SNumber=SNumber+ch;
00577 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00578 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00579 MeshBuff.CA=atoi(SNumber);
00580 if(Textured)
00581 {
00582
00583
00584
00585 CString Material;
00586 do
00587 {
00588 RetVal=fread(&ch,sizeof(char),1,AscFile);
00589 }while(ch!=34);
00590 TmpFilePosition=ftell(AscFile);
00591 i=0;
00592 do
00593 {
00594 RetVal=fread(&ch,sizeof(char),1,AscFile);i++;
00595 }while(ch!=34);
00596 fseek(AscFile,TmpFilePosition,SEEK_SET);
00597 for(k=0;k<i-1;k++)
00598 {
00599 RetVal=fread(&ch,sizeof(char),1,AscFile);
00600 Material=Material+ch;
00601 }
00602
00603 memset(MeshBuff.Texture,256,0);
00604 sprintf(MeshBuff.Texture,"%s",Material);
00605 }else
00606 {
00607 memset(MeshBuff.Texture,255,0);
00608 sprintf(MeshBuff.Texture,"NONE");
00609 }
00610
00611
00612
00613 do
00614 {
00615 RetVal=fread(&ch,sizeof(char),1,AscFile);
00616 }while(ch!=':');
00617 RetVal=fread(&ch,sizeof(char),1,AscFile);
00618 SNumber.Delete(0,SNumber.GetLength());
00619 do
00620 {
00621 RetVal=fread(&ch,sizeof(char),1,AscFile);
00622 SNumber=SNumber+ch;
00623 }while(ch=='0'||ch=='1'||ch=='2'||ch=='3'||ch=='4'||ch=='5'||
00624 ch=='6'||ch=='7'||ch=='8'||ch=='9'||ch=='.'||ch=='-');
00625 MeshBuff.S=atoi(SNumber);
00626
00627 m_VecMesh.push_back(MeshBuff);
00628 }
00629
00630
00631 TotalNumberofVertex=TotalNumberofVertex+NumberofVertex;
00632 TotalNumberofFace=TotalNumberofFace+NumberofFace;
00633
00634 TmpFilePosition=ftell(AscFile);
00635 if(TmpFilePosition+100>FileSize)
00636 {
00637 endfile=true;
00638 }else
00639 {
00640 endfile=false;
00641 }
00642 }while(!endfile);
00643 fclose(AscFile);
00644
00645
00646 MapFile=fopen(m_SMapFile,"w+");
00647 if(!MapFile)
00648 {
00649 AfxMessageBox("Error creating map file");
00650 return;
00651 }
00652 char Buff[255];
00653 memset(Buff,0,255);
00654 sprintf(Buff,"#map#\n");
00655 sprintf(Buff,"<filetype>map<#filetype>\n");
00656 fwrite(Buff,strlen(Buff),1,MapFile);
00657
00658 memset(Buff,0,255);
00659 sprintf(Buff,"<skybox_top>%s<#skybox_top>\n",m_STextureName);
00660 fwrite(Buff,strlen(Buff),1,MapFile);
00661
00662 memset(Buff,0,255);
00663 sprintf(Buff,"<skybox_bottom>%s<#skybox_bottom>\n",m_STextureNameBottom);
00664 fwrite(Buff,strlen(Buff),1,MapFile);
00665
00666 memset(Buff,0,255);
00667 sprintf(Buff,"<skybox_front>%s<#skybox_front>\n",m_STextureNameFront);
00668 fwrite(Buff,strlen(Buff),1,MapFile);
00669
00670 memset(Buff,0,255);
00671 sprintf(Buff,"<skybox_back>%s<#skybox_back>\n",m_STextureNameBack);
00672 fwrite(Buff,strlen(Buff),1,MapFile);
00673
00674 memset(Buff,0,255);
00675 sprintf(Buff,"<skybox_left>%s<#skybox_left>\n",m_STextureNameLeft);
00676 fwrite(Buff,strlen(Buff),1,MapFile);
00677
00678 memset(Buff,0,255);
00679 sprintf(Buff,"<skybox_right>%s<#skybox_right>\n",m_STextureNameRight);
00680 fwrite(Buff,strlen(Buff),1,MapFile);
00681
00682
00683 memset(Buff,0,255);
00684 sprintf(Buff,"<number_vertex>%d<#number_vertex>\n",TotalNumberofVertex);
00685 fwrite(Buff,strlen(Buff),1,MapFile);
00686
00687 for(m_ItVecVertex=m_VecVertex.begin();m_ItVecVertex!=m_VecVertex.end();m_ItVecVertex++)
00688 {
00689 memset(Buff,0,255);
00690 sprintf(Buff,"<vertex_data><X>%f<#X><Y>%f<#Y><Z>%f<#Z><U>%f<#U><V>%f<#V><#vertex_data>\n",m_ItVecVertex->x,m_ItVecVertex->y,m_ItVecVertex->z,m_ItVecVertex->u,m_ItVecVertex->v);
00691 fwrite(Buff,strlen(Buff),1,MapFile);
00692 }
00693
00694 memset(Buff,0,255);
00695 sprintf(Buff,"<number_mesh>%d<#number_mesh>\n",TotalNumberofFace);
00696 fwrite(Buff,strlen(Buff),1,MapFile);
00697
00698 SMesh MeshBuf;
00699 for(m_ItVecMesh=m_VecMesh.begin();m_ItVecMesh!=m_VecMesh.end();m_ItVecMesh++)
00700 {
00701 memset(Buff,0,255);
00702 sprintf(Buff,"<mesh_data><A>%d<#A><B>%d<#B><C>%d<C#><AB>%d<#AB><CA>%d<#CA><BC>%d<#BC><texture>%s<#texture><smothing>%d<#smothing><#mesh_data>\n",
00703 m_ItVecMesh->A,
00704 m_ItVecMesh->B,
00705 m_ItVecMesh->C,
00706 m_ItVecMesh->AB,
00707 m_ItVecMesh->CA,
00708 m_ItVecMesh->BC,
00709 m_ItVecMesh->Texture,
00710 m_ItVecMesh->S);
00711 fwrite(Buff,strlen(Buff),1,MapFile);
00712 }
00713 AfxMessageBox("Map file ok");
00714 fclose(MapFile);
00715 }