Terrain.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:51k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. // Terrain.cpp: implementation of the CTerrain class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include <stdio.h>
  6. #include "Terrain.h"
  7. #include "Texture.h"
  8. #include "cmath.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CTerrain::CTerrain()
  13. {
  14. for(int i=0;i<128;i++)
  15. for(int j=0;j<128;j++)
  16. {
  17. Skinmap[i][j].TextureIndex=0;
  18. Skinmap[i][j].TextureOrder=0;
  19. }
  20. for( i=0;i<256;i++)
  21. for(int j=0;j<256;j++)
  22. {
  23. m_cHmap.m_pMovemap[i*256+j].xpos=0;
  24. m_cHmap.m_pMovemap[i*256+j].zpos=0;
  25.             NormalIndex[i*256+j]=0;
  26. }
  27. }
  28. bool CTerrain::InitTerrain()
  29. {
  30.  CTexture cTex;
  31.  //////////////read blend skin texture
  32.  int i;
  33.  char filename[64];
  34.  for(i=0;i<4;i++)
  35.  {
  36.  wsprintf(filename,"Terrains/TerrainSkin/TerSkin%d.skn",i+1);
  37.  if(!cTex.MakeSkinTextureBind(filename,&Blend[i]))
  38.  {
  39.      MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
  40.      return false;
  41.  }  
  42.  }
  43.  /////////////////////read base skin and cover skin texture
  44.      for(i=0;i<TEX_TYPE;i++)
  45.  {
  46.  wsprintf(filename,"Terrains/TerrainSkin/A%d.bmp",i+1);
  47.  if(!cTex.MakeTextureBind(filename,&BaseA[i]))
  48.  {
  49.      MessageBox(NULL,"Read A Skin error","ERROR",MB_OK|MB_ICONSTOP);
  50.      return false;
  51.  } 
  52.  wsprintf(filename,"Terrains/TerrainSkin/B%d.bmp",i+1);
  53.  if(!cTex.MakeTextureBind(filename,&BaseB[i]))
  54.  {
  55.      MessageBox(NULL,"Read B Skin error","ERROR",MB_OK|MB_ICONSTOP);
  56.      return false;
  57.  }  
  58.  }
  59.  /*
  60.  ///////////read detail map
  61.      for(i=0;i<2;i++)
  62.  {
  63.  wsprintf(filename,"Terrains/detail%d.bmp",i+1);
  64.  if(!cTex.MakeTextureBind(filename,&Detail[i]))
  65.  {
  66.      MessageBox(NULL,"Read A Skin error","ERROR",MB_OK|MB_ICONSTOP);
  67.      return false;
  68.  } 
  69.  }*/
  70.     //////////////////////init terrain skin
  71.     /////construct texture index 
  72. unsigned char index[64][64];
  73. FILE *fp;
  74. fp=fopen("Terrains/texindex_64.bmp","rb");
  75. if(!fp)return false;
  76. fseek(fp,1078,SEEK_SET);
  77. for(int z=63;z>-1;z--)
  78. for(int x=0;x<64;x++)
  79. {
  80. fread(&index[z][x],sizeof(unsigned char),1,fp);
  81. }
  82.     fclose(fp); 
  83.     /////////////////get texture index ,texture order 
  84. for( z=0;z<64;z++)
  85. for(int x=0;x<64;x++)
  86. {
  87. int  name=0;
  88. int addz=z+1;
  89. int addx=x+1;
  90. if(addx==64)addx=0;
  91. if(addz==64)addz=0;
  92. if(index[z][x]>64)    name+=8;
  93. if(index[z][addx]>64)  name+=4;
  94. if(index[addz][addx]>64)name+=2;
  95. if(index[addz][x]>64)  name+=1;
  96. ////////////////////////////////////
  97. if(name==15)//第一种贴图
  98. {   
  99. Skinmap[z][x].TextureIndex=BaseA[rand()%TEX_TYPE];
  100.           Skinmap[z][x].TextureOrder=rand()%4;
  101. }
  102. else if(name==0)//第二种贴图
  103. {
  104. Skinmap[z][x].TextureIndex=BaseB[rand()%TEX_TYPE];
  105.           Skinmap[z][x].TextureOrder=rand()%4;
  106. }
  107. else  //过渡贴图
  108. {
  109. if(name==8 || name==4 || name==2 || name==1 )
  110. Skinmap[z][x].TextureIndex=Blend[0];
  111. if(name==7 || name==11|| name==13|| name==14)
  112. Skinmap[z][x].TextureIndex=Blend[1];
  113. if(name==12|| name==6 || name==3 || name==9 )
  114. Skinmap[z][x].TextureIndex=Blend[2];
  115. if(name==10|| name==5  )
  116. Skinmap[z][x].TextureIndex=Blend[3];
  117. /////////////////// get order
  118. if(name==8 || name==7 || name==10|| name==12)
  119. Skinmap[z][x].TextureOrder=0;
  120. if(name==4 || name==11|| name==5 || name==6 )
  121. Skinmap[z][x].TextureOrder=1;
  122. if(name==2 || name==13|| name==3 )
  123. Skinmap[z][x].TextureOrder=2;
  124. if(name==1 || name==14|| name==9 )
  125. Skinmap[z][x].TextureOrder=3;
  126. }
  127. }
  128.     //////////////read lodmap.lod
  129. fp=fopen("Terrains/lodmap.lod","rb");
  130. if(!fp)return false;
  131. for( z=255;z>-1;z--)
  132. for(int x=0;x<256;x++)
  133. {
  134. fread(&LODmap[z][x],sizeof(unsigned char),1,fp);
  135. }
  136. ///////////////////////////////////////////////
  137.     cFrustumCull.InitFrustumCull(40,60);
  138. ///////////////////////////////////////////////
  139. ///////////////Calculate light normal and lighting color
  140. CMath math;
  141. NORMAL na1,na2,na;
  142. NORMAL nb1,nb2,nb;
  143.     NORMAL normal;
  144. float  xz;
  145. float  xrot,yrot;
  146. for( z=0;z<256;z++)
  147. for(int x=0;x<256;x++)
  148. {
  149. int addz=z+1;   if(addz==256)addz=0;
  150. int subz=z-1;   if(subz==-1)subz=255;
  151. int addx=x+1;   if(addx==256)addx=0;
  152. int subx=x-1;   if(subx==-1)subx=255;
  153. na1=NORMAL(0, float(m_cHmap.m_pTmap[(addz)*256+x] -m_cHmap.m_pTmap[z*256+x] ),6);
  154. na2=NORMAL(6,float(m_cHmap.m_pTmap[z*256+addx] -m_cHmap.m_pTmap[z*256+x] ),0 );
  155. nb1=NORMAL(0, float(m_cHmap.m_pTmap[(subz)*256+x] -m_cHmap.m_pTmap[z*256+x] ),-6);
  156. nb2=NORMAL(-6,float(m_cHmap.m_pTmap[z*256+subx] -m_cHmap.m_pTmap[z*256+x] ),0 );
  157. na=math.GetTwoNormalProduct(na1,na2);
  158. nb=math.GetTwoNormalProduct(nb1,nb2);
  159.             //////////////////////////////////
  160.             normal.nx=na.nx+nb.nx;
  161.             normal.ny=na.ny+nb.ny;
  162.             normal.nz=na.nz+nb.nz;
  163. normal=math.Normalization(normal);
  164.             ///////////////////Init Lighting normal////////
  165. if(normal.ny>1)normal.ny=1;
  166. if(normal.ny<-1)normal.ny=-1;
  167. xrot=asinf(normal.ny)*57.29578f;
  168. xz=(float)sqrt(normal.nx*normal.nx+normal.nz*normal.nz);
  169. yrot=acosf(-normal.nz/xz)*57.29578f;
  170. if(normal.nx>0)yrot=360-yrot;
  171. NormalIndex[z*256+x]=int(xrot/10) * 36+ int(yrot/10);
  172. if(NormalIndex[z*256+x]>359)NormalIndex[z*256+x]=359;
  173.             ///////////////////Init Lighting Color////////
  174. /*
  175. float Aglcos=math.GetTwoVectorAngleCosine(NORMAL(-1.0f,0.5f,1.0f),normal);            
  176. if(Aglcos>0 && Aglcos<=1)ColorIndex[z*256+x]=int(Aglcos*255);
  177. else ColorIndex[z*256+x]=0;*/
  178. }
  179.     ////////// Init Lighting color
  180.             
  181. //////////////////end
  182. return true;
  183. }
  184. void CTerrain::FillMovemap()
  185. {
  186. offsetx=int(m_cHmap.m_pViewPos->xpos*0.025f);
  187. if(offsetx<0)offsetx-=1;
  188. biasX=m_cHmap.m_pViewPos->xpos*0.025f-offsetx;
  189. offsetz=int(m_cHmap.m_pViewPos->zpos*0.025f);
  190. if(offsetz<0)offsetz-=1;
  191. biasZ=m_cHmap.m_pViewPos->zpos*0.025f-offsetz;
  192. int startz=((cFrustumCull.m_MinZ+offsetz)*4)%256;
  193. if(startz<0)startz=256+startz;
  194.     int startx=((cFrustumCull.m_MinX+offsetx)*4)%256;
  195. if(startx<0)startx=256+startx;
  196. int zpos=startz;
  197. for(int z=cFrustumCull.m_MinZ;z<cFrustumCull.m_MaxZ;z++)
  198. {
  199.         int xpos=startx;
  200. for(int x=cFrustumCull.m_MinX;x<cFrustumCull.m_MaxX;x++)
  201. {          
  202. m_cHmap.m_pMovemap[(128+z)*256+128+x].xpos=xpos;
  203. m_cHmap.m_pMovemap[(128+z)*256+128+x].zpos=zpos;
  204. xpos+=4;
  205. if(xpos>252)xpos=0;
  206. }
  207. zpos+=4;
  208. if(zpos>252)zpos=0;
  209. }
  210. offsetx=offsetx*40;
  211. offsetz=offsetz*40;
  212. }
  213. void CTerrain::UpdateTerrainmap()
  214. {
  215.     cFrustumCull.UpdateFrustumCull(*m_cHmap.m_pViewRotY);
  216.     numTriangles=0;
  217.     FillMovemap();
  218.     UpdateLODmap();
  219. ///// Update boundary
  220.     m_cHmap.m_rect.minx=cFrustumCull.m_MinX+128;
  221.     m_cHmap.m_rect.maxx=cFrustumCull.m_MaxX+128;
  222.     m_cHmap.m_rect.minz=cFrustumCull.m_MinZ+128;
  223.     m_cHmap.m_rect.maxz=cFrustumCull.m_MaxZ+128;
  224. }
  225. ////////////////////////////////////////////////////////
  226. void  CTerrain::UpdateLODmap()
  227. {
  228.     int leftX,leftZ;
  229.     int rightX, rightZ;
  230.     int foucsX, foucsZ;
  231. int step=1;
  232. /////////////////////////////////////////////////
  233. ////////////////////////Left
  234. if(cFrustumCull.m_LeftArray[127]==0) //X
  235. {
  236.     leftX=cFrustumCull.m_LeftArray[125];
  237.         foucsX=cFrustumCull.m_LeftArray[126];
  238.     leftZ=cFrustumCull.m_LeftArray[0];
  239.         foucsZ=cFrustumCull.m_LeftArray[cFrustumCull.m_LeftArray[124]-1];
  240. int num=cFrustumCull.m_LeftArray[124];
  241. if(leftX<foucsX)
  242.             for(int i=0;i<num;i+=step)
  243.                 ProcessLine(leftX+i,cFrustumCull.m_LeftArray[i]);
  244. else
  245.             for(int i=0;i<num;i+=step)
  246.                 ProcessLine(leftX-i,cFrustumCull.m_LeftArray[i]);
  247. }else        //Z
  248. {
  249.     leftX=cFrustumCull.m_LeftArray[0];
  250.         foucsX=cFrustumCull.m_LeftArray[cFrustumCull.m_LeftArray[124]-1];
  251.     leftZ=cFrustumCull.m_LeftArray[125];
  252.         foucsZ=cFrustumCull.m_LeftArray[126];
  253. int num=cFrustumCull.m_LeftArray[124];
  254. if(leftZ<foucsZ)
  255.             for(int i=0;i<num;i+=step)
  256.                 ProcessLine(cFrustumCull.m_LeftArray[i],leftZ+i);
  257. else
  258.             for(int i=0;i<num;i+=step)
  259.                 ProcessLine(cFrustumCull.m_LeftArray[i],leftZ-i);
  260. }
  261.     ////////////////////////////////////////////////
  262. ///////////////////////right
  263. if(cFrustumCull.m_RightArray[127]==0) //X
  264. {
  265.     foucsX=cFrustumCull.m_RightArray[125];
  266.         rightX=cFrustumCull.m_RightArray[126];
  267.     foucsZ=cFrustumCull.m_RightArray[0];
  268.         rightZ=cFrustumCull.m_RightArray[cFrustumCull.m_RightArray[124]-1];
  269. int num=cFrustumCull.m_RightArray[124];
  270. if(foucsX<rightX)
  271.             for(int i=0;i<num;i+=step)
  272.                 ProcessLine(foucsX+i,cFrustumCull.m_RightArray[i]);
  273. else
  274.             for(int i=0;i<num;i+=step)
  275.                 ProcessLine(foucsX-i,cFrustumCull.m_RightArray[i]);
  276. }else        //Z
  277. {
  278.     foucsX=cFrustumCull.m_RightArray[0];
  279.         rightX=cFrustumCull.m_RightArray[cFrustumCull.m_RightArray[124]-1];
  280.     foucsZ=cFrustumCull.m_RightArray[125];
  281.         rightZ=cFrustumCull.m_RightArray[126];
  282. int num=cFrustumCull.m_RightArray[124];
  283. if(foucsZ<rightZ)
  284.             for(int i=0;i<num;i+=step)
  285.                 ProcessLine(cFrustumCull.m_RightArray[i],foucsZ+i);
  286. else
  287.             for(int i=0;i<num;i+=step)
  288.                 ProcessLine(cFrustumCull.m_RightArray[i],foucsZ-i);
  289. }
  290. /////////////////////////////////////////
  291. /*
  292. radius=4;
  293. maxx=radius;
  294. minx=-radius;
  295. maxz=radius;
  296. minz=-radius;
  297. if(cFrustumCull.m_MaxX<maxx)maxx=cFrustumCull.m_MaxX;
  298. if(cFrustumCull.m_MinX>minx)minx=cFrustumCull.m_MinX;
  299. if(cFrustumCull.m_MaxZ<maxz)maxz=cFrustumCull.m_MaxZ;
  300. if(cFrustumCull.m_MinZ>minz)minz=cFrustumCull.m_MinZ;
  301. */
  302. for(int z=127;z<130;z++)
  303. for(int x=127;x<130;x++)
  304.         DrawMap[z][x]=1;
  305. /////////////////////
  306. /*
  307. /////////////////
  308. glBegin(GL_LINE_STRIP);
  309.     glVertex3f(pViewerPos->xpos,100,pViewerPos->zpos);
  310. glVertex3f(leftX*20,100,leftZ*20);
  311. glVertex3f(foucsX*20,100,foucsZ*20);
  312. glVertex3f(rightX*20,100,rightZ*20);
  313.     glVertex3f(pViewerPos->xpos,100,pViewerPos->zpos);
  314. glEnd();
  315. */
  316. }
  317. void CTerrain::ProcessLine(int ox,int oz)//处理(X,Y,Z)到视点连线之间的点
  318. {
  319. float x=float(128+ox);
  320. float z=float(128+oz);
  321.     float viewx=128;
  322.     float viewz=128;
  323. float viewy=m_cHmap.m_pViewPos->ypos+10;
  324. float dx=viewx - x;                         //视点与(x,y,z)在x轴之差
  325.     float dz=viewz - z;                         //视点与(x,y,z)在z轴之差
  326. int signx,signz;
  327. if(dx<0)
  328. {dx=-dx; signx=-1;}
  329. else
  330.         signx=1;
  331. if(dz<0)
  332. {dz=-dz; signz=-1;}
  333. else
  334.         signz=1;
  335.     // From viewer to (x,y,z)  position
  336.     if(dz>dx)
  337. {
  338. float bias,deltaX,curX;
  339. if(signz==1)
  340. {
  341. bias=(dx+biasX*signx)*dz*10/((dz+biasZ)*10)-dx;
  342. /*         viewy=m_cHmap.GetHeight(m_cHmap.m_pViewPos->xpos-(biasX-bias)*40,
  343.                         m_cHmap.m_pViewPos->zpos-(biasZ)*40); */ 
  344. }
  345. else
  346. {
  347. bias=(dx+biasX*signx)*(dz-1)*10/((dz-biasZ)*10)-dx;
  348. dz--;
  349. viewz++;
  350. /*         viewy=m_cHmap.GetHeight(m_cHmap.m_pViewPos->xpos-(biasX-bias)*40,
  351.                         m_cHmap.m_pViewPos->zpos+(1-biasZ)*40);  */
  352. }
  353.         deltaX=signx*(dx+bias)/dz;
  354.         curX=viewx+bias*signx;
  355. int   intx;
  356.         float slope=-1000;
  357. float curVH=0; 
  358. float max,min;
  359. for(int i=1;i<dz;i++)
  360. {
  361.             curX-=deltaX;
  362. intx=int(curX);
  363.             float h1=m_cHmap.m_pTmap[GetPos(intx,int(viewz-signz*i))];
  364.             float h2=m_cHmap.m_pTmap[GetPos(intx+1,int(viewz-signz*i))];
  365. if(h2>h1){max=h2;min=h1;}
  366. else {max=h1;min=h2;}
  367.  
  368.             float newSlope=float(max-viewy)/(i);
  369.         if(newSlope>slope) //visible
  370. {
  371. slope=float(min-viewy)/(i);//newSlope*1.01f;
  372.                 DrawMap[int(viewz-signz*i)][intx]=1;
  373.                 DrawMap[int(viewz-signz*i)][intx+1]=1;
  374. }
  375. }
  376. }
  377. else    /////////////// dx>dz
  378. {
  379. float bias,deltaZ,curZ;
  380. if(signx==1)
  381. bias=(dz+biasZ*signz)*dx*10/((dx+biasX)*10)-dz;
  382. else
  383. {
  384. bias=(dz+biasZ*signz)*(dx-1)*10/((dx-biasX)*10)-dz;
  385. dx--;
  386. viewx++;
  387. }
  388.         deltaZ=signz*(dz+bias)/dx;
  389.         curZ=viewz+bias*signz;
  390. int   intz;
  391.         float slope=-1000;
  392. for(int i=1;i<dx;i++)
  393. {
  394.     curZ-=deltaZ;
  395. intz=int(curZ);
  396.             float h1=m_cHmap.m_pTmap[GetPos(int(viewx-signx*i),intz)];
  397.             float h2=m_cHmap.m_pTmap[GetPos(int(viewx-signx*i),intz+1)];
  398. float max,min;
  399. if(h2>h1){max=h2;min=h1;}
  400. else {max=h1;min=h2;}
  401. float newSlope=float(max-viewy)/i;
  402. if(newSlope>slope) //visible
  403. {
  404. slope=float(min-viewy)/i;
  405.                 DrawMap[intz][int(viewx-signx*i)]=1;
  406.                 DrawMap[(intz+1)][int(viewx-signx*i)]=1;
  407. }
  408. }
  409. }
  410. }
  411. void  CTerrain::RestoreDrawMap()
  412. {
  413. for(int z=cFrustumCull.m_MinZ;z<cFrustumCull.m_MaxZ;z++)
  414. for(int x=cFrustumCull.m_MinX;x<cFrustumCull.m_MaxX;x++)
  415.             DrawMap[128+z][128+x]=0; 
  416. for( z=minz;z<maxz;z++)
  417. for(int x=minx;x<maxx;x++)
  418.         DrawMap[128+z][128+x]=0;
  419. }
  420. void CTerrain::RendTerrain()
  421. {
  422.     glEnable(GL_DEPTH_TEST);
  423. for(int x=m_cHmap.m_rect.minx;x<m_cHmap.m_rect.maxx; x++)
  424. {
  425.     for(int z= m_cHmap.m_rect.minz;z<m_cHmap.m_rect.maxz; z++)
  426.             RenderTerrainTile( x, z);
  427. }
  428. }
  429. void CTerrain::RenderTerrainTile(int x,int z)
  430. int level=LODmap[z][x];
  431. if(level==0)return;
  432. /*
  433. if(level==7)
  434. {
  435.         DrawLevel_7(x-128,z-128);
  436. return;
  437. }*/
  438. if(DrawMap[z][x]>0 )
  439. {
  440.     if(level==7 )
  441.        DrawLevel_7(x-128,z-128);
  442.     else if(level==6 )
  443.        DrawLevel_6(x-128,z-128);
  444.     else if(level==5 )
  445.        DrawLevel_5(x-128,z-128);
  446.     else if(level==4)
  447.        DrawLevel_4(x-128,z-128);
  448.     else if(level==3)
  449.        DrawLevel_3(x-128,z-128);
  450.     else if(level==2)
  451.        DrawLevel_2(x-128,z-128);
  452.      else  if(level==1)
  453.        DrawLevel_1(x-128,z-128);
  454. }
  455. else
  456. {
  457. int step=1;
  458. if(LODmap[z][x]>5)step=2;
  459. if(DrawMap[z][x+step]>0)
  460.        LevelChoose(level,x,z);
  461. else if(DrawMap[z+step][x]>0)
  462.        LevelChoose(level,x,z);
  463. else if(DrawMap[z-step][x]>0)
  464.        LevelChoose(level,x,z);
  465. else if(DrawMap[z][x-step]>0)
  466.        LevelChoose(level,x,z);
  467. }
  468. }
  469. void  CTerrain::LevelChoose(int level,int x,int z)
  470. {
  471.     if(level==7 )
  472.        DrawLevel_7(x-128,z-128);
  473.     else if(level==6 )
  474.        DrawLevel_6(x-128,z-128);
  475.     else if(level==5 )
  476.        DrawLevel_5(x-128,z-128);
  477.     else if(level==4)
  478.        DrawLevel_4(x-128,z-128);
  479.     else if(level==3)
  480.        DrawLevel_3(x-128,z-128);
  481.     else if(level==2)
  482.        DrawLevel_2(x-128,z-128);
  483.      else if(level==1)
  484.        DrawLevel_1(x-128,z-128);
  485. }
  486. void CTerrain::DrawLevel_1(int x,int z)
  487. {
  488.             int rx=x*4;
  489.         int rz=z*4;
  490. int base0=GetPos(x+128,z+128);
  491. // int base1=GetPos(x+128-1,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
  492. int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
  493. int base3=GetPos(x+128+1,z+128+1);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
  494. int base4=GetPos(x+128+1,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  495. int base5=GetPos(x+128,z-1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  496.         float ax,az,bx,bz,cx,cz,dx,dz,ex,ez,fx,fz,gx,gz,hx,hz;
  497.             //////////////////////////// 
  498. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  499. glEnable(GL_TEXTURE_2D);
  500. ////////////Get Texture Order////////////////
  501. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  502.             {
  503. case 0:
  504.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  505. case 1:
  506.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  507. case 2:
  508.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  509.      case 3:
  510.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  511. default :
  512.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  513. }
  514. ex=(ax+bx)*0.5f; ez=(az+bz)*0.5f;
  515.             fx=(bx+cx)*0.5f;    fz=(bz+cz)*0.5f;
  516. gx=(cx+dx)*0.5f;    gz=(cz+dz)*0.5f;
  517. hx=(dx+ax)*0.5f;    hz=(dz+az)*0.5f;
  518. ///////////////////////////////////
  519. //////////////////Left_up
  520. ///////////////////////////////////
  521. glBegin(GL_TRIANGLE_FAN);
  522.             //6
  523. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+1]]);
  524. glTexCoord2f((dx+0.5f)*0.5f,(dz+0.5f)*0.5f);
  525.     glVertex3f(float((rx+1)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+256+1] ), float((rz+1)*10+offsetz));
  526.             //0
  527. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  528. glTexCoord2f(dx,dz);
  529.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  530.             //5
  531. if(LODmap[128+z][128+x-1]==1)
  532. {
  533.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256]]);
  534.     glTexCoord2f((dx+hx)*0.5f,(dz+hz)*0.5f);
  535.         glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0+256] ), float(rz+1)*10+offsetz);
  536. }
  537.             //10
  538. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  539. glTexCoord2f(hx,hz);
  540.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+offsetz);
  541. //11
  542.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+1]]);
  543.     glTexCoord2f((hx+0.5f)*0.5f,(hz+0.5f)*0.5f);
  544.         glVertex3f(float((rx+1)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+512+1] ), float(rz+2)*10+offsetz);
  545. //12
  546. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  547. glTexCoord2f(0.5f,0.5f);
  548.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
  549. //7
  550.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+2]]);
  551. glTexCoord2f((gx+0.5f)*0.5f,(gz+0.5f)*0.5f);
  552.     glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+256+2] ), float(rz+1)*10+offsetz);
  553.             //2
  554. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  555. glTexCoord2f(gx,gz);
  556.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
  557.             //1
  558. if(LODmap[128+z-1][128+x]==1)
  559. {
  560.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+1]]);
  561.     glTexCoord2f((gx+dx)*0.5f,(gz+dz)*0.5f);
  562.         glVertex3f(float((rx+1)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+1] ), float(rz)*10+offsetz);
  563. }
  564.             //0
  565. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  566. glTexCoord2f(dx,dz);
  567.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  568. glEnd();
  569. ///////////////////////////////////
  570. //////////////////Left_down
  571. ///////////////////////////////////
  572. glBegin(GL_TRIANGLE_FAN);
  573.             //16
  574. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+1]]);
  575. glTexCoord2f((ax+0.5f)*0.5f,(az+0.5f)*0.5f);
  576.     glVertex3f(float((rx+1)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+768+1] ), float((rz+3)*10+offsetz));
  577.             //10
  578. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  579. glTexCoord2f(hx,hz);
  580.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+offsetz);
  581.             //15
  582. if(LODmap[128+z][128+x-1]==1)
  583. {
  584.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768]]);
  585.     glTexCoord2f((ax+hx)*0.5f,(az+hz)*0.5f);
  586.         glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0+768] ), float(rz+3)*10+offsetz);
  587. }
  588.             //20
  589. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  590. glTexCoord2f(ax,az);
  591.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+offsetz);
  592. //21
  593. if(LODmap[128+z+1][128+x]==1)
  594. {
  595.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+1]]);
  596.     glTexCoord2f((ax+ex)*0.5f,(az+ez)*0.5f);
  597.         glVertex3f(float((rx+1)*10)+offsetx,  float(m_cHmap.m_pTmap[base2+1] ), float(rz+4)*10+offsetz);
  598. }
  599. //22
  600. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  601. glTexCoord2f(ex,ez);
  602.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
  603. //17
  604.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+2]]);
  605.         glTexCoord2f((ex+0.5f)*0.5f,(ez+0.5f)*0.5f);
  606.         glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+768+2] ), float(rz+3)*10+offsetz);
  607. //12
  608. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  609. glTexCoord2f(0.5f,0.5f);
  610.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
  611. //11
  612.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+1]]);
  613.     glTexCoord2f((hx+0.5f)*0.5f,(hz+0.5f)*0.5f);
  614.         glVertex3f(float((rx+1)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+512+1] ), float(rz+2)*10+offsetz);
  615.             //10
  616. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  617. glTexCoord2f(hx,hz);
  618.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+offsetz);
  619. glEnd();
  620. ///////////////////////////////////
  621. //////////////////right_up
  622. ///////////////////////////////////
  623. glBegin(GL_TRIANGLE_FAN);
  624.             //8
  625. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+3]]);
  626. glTexCoord2f((cx+0.5f)*0.5f,(cz+0.5f)*0.5f);
  627.     glVertex3f(float((rx+3)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+256+3] ), float((rz+1)*10+offsetz));
  628.             //2
  629. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  630. glTexCoord2f(gx,gz);
  631.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
  632. //7
  633.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+2]]);
  634.     glTexCoord2f((gx+0.5f)*0.5f,(gz+0.5f)*0.5f);
  635.         glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+256+2] ), float(rz+1)*10+offsetz);
  636. //12
  637. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  638. glTexCoord2f(0.5f,0.5f);
  639.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
  640.             //13
  641. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+3]]);
  642. glTexCoord2f((fx+0.5f)*0.5f,(fz+0.5f)*0.5f);
  643.     glVertex3f(float((rx+3)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+512+3] ), float(rz+2)*10+offsetz);
  644.             //14
  645.         glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  646.         glTexCoord2f(fx,fz);
  647.             glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
  648.             //9
  649. if(LODmap[128+z][128+x+1]==1)
  650. {
  651.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+256]]);
  652.     glTexCoord2f((fx+cx)*0.5f,(fz+cz)*0.5f);
  653.         glVertex3f(float(rx+4)*10+offsetx,  float(m_cHmap.m_pTmap[base4+256]), float(rz+1)*10+offsetz);
  654. }
  655. //4
  656.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  657.     glTexCoord2f(cx,cz);
  658.         glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
  659.             //3
  660. if(LODmap[128+z-1][128+x]==1)
  661. {
  662.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+3]]);
  663.     glTexCoord2f((gx+cx)*0.5f,(gz+cz)*0.5f);
  664.         glVertex3f(float((rx+3)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+3] ), float(rz)*10+offsetz);
  665. }
  666.             //2
  667. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  668. glTexCoord2f(gx,gz);
  669.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
  670. glEnd();
  671. ///////////////////////////////////
  672. //////////////////right_down
  673. ///////////////////////////////////
  674. glBegin(GL_TRIANGLE_FAN);
  675.             //18
  676. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+3]]);
  677. glTexCoord2f((bx+0.5f)*0.5f,(bz+0.5f)*0.5f);
  678.     glVertex3f(float((rx+3)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+768+3] ), float((rz+3)*10+offsetz));
  679. //12
  680. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  681. glTexCoord2f(0.5f,0.5f);
  682.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
  683. //17
  684.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+2]]);
  685.     glTexCoord2f((ex+0.5f)*0.5f,(ez+0.5f)*0.5f);
  686.         glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+768+2] ), float(rz+3)*10+offsetz);
  687. //22
  688. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  689. glTexCoord2f(ex,ez);
  690.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
  691.             //23
  692. if(LODmap[128+z+1][128+x]==1)
  693. {
  694.      glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+3]]);
  695.      glTexCoord2f((ex+bx)*0.5f,(ez+bz)*0.5f);
  696.         glVertex3f(float(rx+3)*10+offsetx,  float(m_cHmap.m_pTmap[base2+3]), float(rz+4)*10+offsetz);
  697. }
  698.             //24
  699.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  700.     glTexCoord2f(bx,bz);
  701.     glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+offsetz);
  702.             //19
  703. if(LODmap[128+z][128+x+1]==1)
  704. {
  705.      glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+768]]);
  706.     glTexCoord2f((bx+fx)*0.5f,(bz+fz)*0.5f);
  707.         glVertex3f(float(rx+4)*10+offsetx,  float(m_cHmap.m_pTmap[base4+768]), float(rz+3)*10+offsetz);
  708. }
  709.             //14
  710.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  711.     glTexCoord2f(fx,fz);
  712.     glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
  713.             //13
  714. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+3]]);
  715. glTexCoord2f((fx+0.5f)*0.5f,(fz+0.5f)*0.5f);
  716.     glVertex3f(float((rx+3)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+512+3] ), float(rz+2)*10+offsetz);
  717. //12
  718. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  719. glTexCoord2f(0.5f,0.5f);
  720.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
  721. glEnd();
  722. numTriangles+=32;
  723. }
  724. void CTerrain::DrawLevel_2(int x,int z)
  725. {
  726.             int rx=x*4;
  727.         int rz=z*4;
  728. int base0=GetPos(x+128,z+128);
  729. // int base1=GetPos(x+128-1,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
  730. int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
  731. int base3=GetPos(x+128+1,z+128+1);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
  732. int base4=GetPos(x+128+1,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  733. int base5=GetPos(x+128,z-1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  734.         float ax,az,bx,bz,cx,cz,dx,dz,ex,ez,fx,fz,gx,gz,hx,hz;
  735.             //////////////////////////// 
  736. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  737. glEnable(GL_TEXTURE_2D);
  738. ////////////Get Texture Order////////////////
  739. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  740.             {
  741. case 0:
  742.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  743. case 1:
  744.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  745. case 2:
  746.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  747.      case 3:
  748.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  749. default :
  750.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  751. }
  752. ex=(ax+bx)*0.5f; ez=(az+bz)*0.5f;
  753.             fx=(bx+cx)*0.5f;    fz=(bz+cz)*0.5f;
  754. gx=(cx+dx)*0.5f;    gz=(cz+dz)*0.5f;
  755. hx=(dx+ax)*0.5f;    hz=(dz+az)*0.5f;
  756. ///////////////////////////////////
  757. //////////////////Left_up
  758. ///////////////////////////////////
  759. glBegin(GL_TRIANGLE_FAN);
  760.             //6
  761. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+1]]);
  762. glTexCoord2f((dx+0.5f)*0.5f,(dz+0.5f)*0.5f);
  763.     glVertex3f(float((rx+1)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+256+1] ), float((rz+1)*10+offsetz));
  764.             //0
  765. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  766. glTexCoord2f(dx,dz);
  767.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  768.             //10
  769. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  770. glTexCoord2f(hx,hz);
  771.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+offsetz);
  772. //12
  773. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  774. glTexCoord2f(0.5f,0.5f);
  775.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
  776.             //2
  777. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  778. glTexCoord2f(gx,gz);
  779.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
  780.             //0
  781. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  782. glTexCoord2f(dx,dz);
  783.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  784. glEnd();
  785. ///////////////////////////////////
  786. //////////////////Left_down
  787. ///////////////////////////////////
  788. glBegin(GL_TRIANGLE_FAN);
  789.             //16
  790. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+1]]);
  791. glTexCoord2f((ax+0.5f)*0.5f,(az+0.5f)*0.5f);
  792.     glVertex3f(float((rx+1)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+768+1] ), float((rz+3)*10+offsetz));
  793.             //10
  794. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  795. glTexCoord2f(hx,hz);
  796.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+offsetz);
  797.             //20
  798. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  799. glTexCoord2f(ax,az);
  800.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+offsetz);
  801. //21
  802. //22
  803. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  804. glTexCoord2f(ex,ez);
  805.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
  806. //12
  807. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  808. glTexCoord2f(0.5f,0.5f);
  809.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
  810.             //10
  811. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  812. glTexCoord2f(hx,hz);
  813.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+offsetz);
  814. glEnd();
  815. ///////////////////////////////////
  816. //////////////////right_up
  817. ///////////////////////////////////
  818. glBegin(GL_TRIANGLE_FAN);
  819.             //8
  820. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+3]]);
  821. glTexCoord2f((cx+0.5f)*0.5f,(cz+0.5f)*0.5f);
  822.     glVertex3f(float((rx+3)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+256+3] ), float((rz+1)*10+offsetz));
  823.             //2
  824. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  825. glTexCoord2f(gx,gz);
  826.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
  827. //12
  828. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  829. glTexCoord2f(0.5f,0.5f);
  830.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
  831.             //14
  832.         glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  833.         glTexCoord2f(fx,fz);
  834.             glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
  835. //4
  836.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  837.     glTexCoord2f(cx,cz);
  838.         glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
  839.             //2
  840. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  841. glTexCoord2f(gx,gz);
  842.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
  843. glEnd();
  844. ///////////////////////////////////
  845. //////////////////right_down
  846. ///////////////////////////////////
  847. glBegin(GL_TRIANGLE_FAN);
  848.             //18
  849. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+3]]);
  850. glTexCoord2f((bx+0.5f)*0.5f,(bz+0.5f)*0.5f);
  851.     glVertex3f(float((rx+3)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+768+3] ), float((rz+3)*10+offsetz));
  852. //12
  853. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  854. glTexCoord2f(0.5f,0.5f);
  855.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
  856.       //22
  857. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  858. glTexCoord2f(ex,ez);
  859.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
  860.             //24
  861.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  862.     glTexCoord2f(bx,bz);
  863.     glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+offsetz);
  864.             //14
  865.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  866.     glTexCoord2f(fx,fz);
  867.     glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
  868. //12
  869. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  870. glTexCoord2f(0.5f,0.5f);
  871.     glVertex3f(float(rx+2)*10+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
  872. glEnd();
  873. numTriangles+=16;
  874. }
  875. void CTerrain::DrawLevel_3(int x,int z)
  876. {
  877.             int rx=x*4;
  878.         int rz=z*4;
  879. int base0=GetPos(x+128,z+128);
  880. // int base1=GetPos(x-1+128,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
  881. int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
  882. int base3=GetPos(x+1+128,z+1+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
  883. int base4=GetPos(x+1+128,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  884. int base5=GetPos(x+128,z-1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  885.         float ax,az,bx,bz,cx,cz,dx,dz;
  886.             //////////////////////////// 
  887. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  888. glEnable(GL_TEXTURE_2D);
  889. ////////////Get Texture Order////////////////
  890. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  891.             {
  892. case 0:
  893.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  894. case 1:
  895.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  896. case 2:
  897.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  898.      case 3:
  899.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  900. default :
  901.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  902. }
  903. glBegin(GL_TRIANGLE_FAN);
  904. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  905. glTexCoord2f(0.5f,0.5f);
  906.     glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float((rz+2)*10+offsetz));
  907. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  908. glTexCoord2f(dx,dz);
  909.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  910.             
  911.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  912. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base0+256]]);
  913.     glTexCoord2f((ax+dx)*0.5f,(az+dz)*0.5f);
  914.         glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0+512] ), float(rz+2)*10+offsetz);
  915. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  916. glTexCoord2f(ax,az);
  917.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+offsetz);
  918.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  919.     glTexCoord2f((ax+bx)*0.5f,(az+bz)*0.5f);
  920.         glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
  921. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  922. glTexCoord2f(bx,bz);
  923.     glVertex3f(float(rx+4)*10+offsetx,  float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+offsetz);
  924.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  925. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4+256]]);
  926.     glTexCoord2f((cx+bx)*0.5f,(cz+bz)*0.5f);
  927.         glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
  928. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  929. glTexCoord2f(cx,cz);
  930.     glVertex3f(float(rx+4)*10+offsetx,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
  931.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  932.     glTexCoord2f((cx+dx)*0.5f,(cz+dz)*0.5f);
  933.         glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
  934. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  935. glTexCoord2f(dx,dz);
  936.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  937. glEnd();
  938. /////////////////////////blend
  939. /*
  940. glBindTexture(GL_TEXTURE_2D, Detail[0]);
  941. glEnable(GL_TEXTURE_2D);
  942. // glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_COLOR);
  943. glBlendFunc(GL_DST_COLOR,GL_SRC_COLOR);
  944. glEnable(GL_BLEND);
  945. glBegin(GL_TRIANGLE_FAN);
  946. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  947. glTexCoord2f(0.5f,0.5f);
  948.     glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float((rz+2)*10+offsetz));
  949. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  950. glTexCoord2f(dx,dz);
  951.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  952.             
  953.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  954. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base0+256]]);
  955.     glTexCoord2f((ax+dx)*0.5f,(az+dz)*0.5f);
  956.         glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0+512] ), float(rz+2)*10+offsetz);
  957. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  958. glTexCoord2f(ax,az);
  959.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+offsetz);
  960.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  961.     glTexCoord2f((ax+bx)*0.5f,(az+bz)*0.5f);
  962.         glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
  963. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  964. glTexCoord2f(bx,bz);
  965.     glVertex3f(float(rx+4)*10+offsetx,  float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+offsetz);
  966.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  967. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4+256]]);
  968.     glTexCoord2f((cx+bx)*0.5f,(cz+bz)*0.5f);
  969.         glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
  970. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  971. glTexCoord2f(cx,cz);
  972.     glVertex3f(float(rx+4)*10+offsetx,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
  973.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  974.     glTexCoord2f((cx+dx)*0.5f,(cz+dz)*0.5f);
  975.         glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
  976. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  977. glTexCoord2f(dx,dz);
  978.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  979. glEnd();
  980. */
  981. glDisable(GL_BLEND);
  982. numTriangles+=8;
  983. }
  984. void CTerrain::DrawLevel_4(int x,int z)
  985. {
  986.             int rx=x*4;
  987.         int rz=z*4;
  988. int base0=GetPos(x+128,z+128);
  989. // int base1=GetPos(x-1+128,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
  990. int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
  991. int base3=GetPos(x+1+128,z+1+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
  992. int base4=GetPos(x+1+128,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  993. // int base5=GetPos(x+128,z-1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  994.         float ax,az,bx,bz,cx,cz,dx,dz;
  995.             //////////////////////////// 
  996. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  997. glEnable(GL_TEXTURE_2D);
  998. ////////////Get Texture Order////////////////
  999. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  1000.             {
  1001. case 0:
  1002.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  1003. case 1:
  1004.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  1005. case 2:
  1006.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  1007.      case 3:
  1008.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  1009. default :
  1010.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  1011. }
  1012. glBegin(GL_TRIANGLE_FAN);
  1013.             //12
  1014. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  1015. glTexCoord2f(0.5f,0.5f);
  1016.     glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+512+2] ), float((rz+2)*10+offsetz));
  1017.             //0
  1018. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  1019. glTexCoord2f(dx,dz);
  1020.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  1021.             //10
  1022. if(LODmap[128+z][128+x-1]<4)
  1023. {
  1024.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  1025.     glTexCoord2f((ax+dx)*0.5f,(az+dz)*0.5f);
  1026.         glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0+512] ), float(rz+2)*10+offsetz);
  1027. }
  1028.             //20
  1029. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  1030. glTexCoord2f(ax,az);
  1031.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+offsetz);
  1032. //22
  1033. if(LODmap[128+z+1][128+x]<4)
  1034. {
  1035.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  1036.     glTexCoord2f((ax+bx)*0.5f,(az+bz)*0.5f);
  1037.         glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
  1038. }
  1039.             //24
  1040. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  1041. glTexCoord2f(bx,bz);
  1042.     glVertex3f(float(rx+4)*10+offsetx,  float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+offsetz);
  1043.             //14
  1044. if(LODmap[128+z][128+x+1]<4)
  1045. {
  1046.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  1047. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4+256]]);
  1048.     glTexCoord2f((cx+bx)*0.5f,(cz+bz)*0.5f);
  1049.         glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
  1050. }
  1051.             //4
  1052. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  1053. glTexCoord2f(cx,cz);
  1054.     glVertex3f(float(rx+4)*10+offsetx,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
  1055.             //2
  1056. if(LODmap[128+z-1][128+x]<4)
  1057. {
  1058.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  1059.     glTexCoord2f((cx+dx)*0.5f,(cz+dz)*0.5f);
  1060.         glVertex3f(float((rx+2)*10)+offsetx,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
  1061. }
  1062. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  1063. glTexCoord2f(dx,dz);
  1064.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  1065. glEnd();
  1066. numTriangles+=4;
  1067. }
  1068. void CTerrain::DrawLevel_5(int x,int z)
  1069. {
  1070.             int rx=x*4;
  1071.         int rz=z*4;
  1072. int base0=GetPos(x+128,z+128);
  1073. // int base1=GetPos(x-1+128,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
  1074. int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
  1075. int base3=GetPos(x+1+128,z+1+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
  1076. int base4=GetPos(x+1+128,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  1077.         float ax,az,bx,bz,cx,cz,dx,dz;
  1078.             //////////////////////////// 
  1079. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  1080. glEnable(GL_TEXTURE_2D);
  1081. ////////////Get Texture Order////////////////
  1082. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  1083.             {
  1084. case 0:
  1085.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  1086. case 1:
  1087.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  1088. case 2:
  1089.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  1090.      case 3:
  1091.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  1092. default :
  1093.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  1094. }
  1095. glBegin(GL_TRIANGLE_FAN);
  1096. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  1097. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base0]]);
  1098. glTexCoord2f(dx,dz);
  1099.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  1100. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  1101. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base2]]);
  1102. glTexCoord2f(ax,az);
  1103.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+offsetz);
  1104. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  1105. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base3]]);
  1106. glTexCoord2f(bx,bz);
  1107.     glVertex3f(float(rx+4)*10+offsetx,  float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+offsetz);
  1108. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  1109. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4]]);
  1110. glTexCoord2f(cx,cz);
  1111.     glVertex3f(float(rx+4)*10+offsetx,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
  1112. glEnd();
  1113. numTriangles+=2;
  1114. }
  1115. void CTerrain::DrawLevel_6(int x,int z)
  1116. {
  1117.             int rx=x*4;
  1118.         int rz=z*4;
  1119. int base0=GetPos(x+128,z+128);
  1120. int base1=GetPos(x+128,z+2+128);
  1121. int base2=GetPos(x+2+128,z+2+128);
  1122. int base3=GetPos(x+2+128,z+128);
  1123. int base4=GetPos(x+1+128,z+1+128);
  1124. int base5=GetPos(x+128,z+1+128);
  1125. int base6=GetPos(x+1+128,z+2+128);
  1126. int base7=GetPos(x+2+128,z+1+128);
  1127. int base8=GetPos(x+1+128,z+128);
  1128.         float ax,az,bx,bz,cx,cz,dx,dz;
  1129.             //////////////////////////// 
  1130. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  1131. glEnable(GL_TEXTURE_2D);
  1132. ////////////Get Texture Order////////////////
  1133. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  1134.             {
  1135. case 0:
  1136.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  1137. case 1:
  1138.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  1139. case 2:
  1140.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  1141.      case 3:
  1142.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  1143. default :
  1144.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  1145. }
  1146. glBegin(GL_TRIANGLE_FAN);
  1147.  
  1148. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  1149. glTexCoord2f(0.5f,0.5f);
  1150.     glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base4] ), float((rz+4)*10+offsetz));
  1151. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  1152. glTexCoord2f(dx,dz);
  1153.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  1154.    
  1155. if(LODmap[128+z][128+x-2]!=7)
  1156. {
  1157.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base5]]);
  1158.     glTexCoord2f((ax+dx)*0.5f,(az+dz)*0.5f);
  1159.         glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base5] ), float(rz+4)*10+offsetz);
  1160. }
  1161. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base1]]);
  1162. glTexCoord2f(ax,az);
  1163.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base1]), float(rz+8)*10+offsetz);
  1164. if(LODmap[128+z+2][128+x]!=7)
  1165. {
  1166.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base6]]);
  1167.     glTexCoord2f((ax+bx)*0.5f,(az+bz)*0.5f);
  1168.         glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base6] ), float(rz+8)*10+offsetz);
  1169. }
  1170.        
  1171. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  1172. glTexCoord2f(bx,bz);
  1173.     glVertex3f(float(rx+8)*10+offsetx,  float(m_cHmap.m_pTmap[base2] ), float(rz+8)*10+offsetz);
  1174.       
  1175. if(LODmap[128+z][128+x+2]!=7)
  1176. {
  1177.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base7]]);
  1178.     glTexCoord2f((cx+bx)*0.5f,(cz+bz)*0.5f);
  1179.         glVertex3f(float((rx+8)*10)+offsetx,  float(m_cHmap.m_pTmap[base7] ), float(rz+4)*10+offsetz);
  1180. }
  1181.     
  1182. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  1183. glTexCoord2f(cx,cz);
  1184.     glVertex3f(float(rx+8)*10+offsetx,  float(m_cHmap.m_pTmap[base3] ), float(rz)*10+offsetz);
  1185.             //2
  1186. if(LODmap[128+z-2][128+x]!=7)
  1187. {
  1188.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base8]]);
  1189.     glTexCoord2f((cx+dx)*0.5f,(cz+dz)*0.5f);
  1190.         glVertex3f(float((rx+4)*10)+offsetx,  float(m_cHmap.m_pTmap[base8] ), float(rz)*10+offsetz);
  1191. }
  1192. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  1193. glTexCoord2f(dx,dz);
  1194.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  1195. glEnd();
  1196. numTriangles+=4;
  1197. }
  1198. void CTerrain::DrawLevel_7(int x,int z)
  1199. {
  1200.             int rx=x*4;
  1201.         int rz=z*4;
  1202. int base0=GetPos(x+128,z+128);
  1203. // int base1=GetPos(x-1+128,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
  1204. int base2=GetPos(x+128,z+2+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
  1205. int base3=GetPos(x+2+128,z+2+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
  1206. int base4=GetPos(x+2+128,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  1207.         float ax,az,bx,bz,cx,cz,dx,dz;
  1208.             //////////////////////////// 
  1209. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  1210. glEnable(GL_TEXTURE_2D);
  1211. ////////////Get Texture Order////////////////
  1212. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  1213.             {
  1214. case 0:
  1215.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  1216. case 1:
  1217.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  1218. case 2:
  1219.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  1220.      case 3:
  1221.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  1222. default :
  1223.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  1224. }
  1225. glBegin(GL_TRIANGLE_FAN);
  1226. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  1227. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base0]]);
  1228. glTexCoord2f(dx,dz);
  1229.     glVertex3f(float(rx*10)+offsetx,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
  1230. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  1231. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base2]]);
  1232. glTexCoord2f(ax,az);
  1233.     glVertex3f(float(rx)*10+offsetx,  float(m_cHmap.m_pTmap[base2]), float(rz+8)*10+offsetz);
  1234. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  1235. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base3]]);
  1236. glTexCoord2f(bx,bz);
  1237.     glVertex3f(float(rx+8)*10+offsetx,  float(m_cHmap.m_pTmap[base3] ), float(rz+8)*10+offsetz);
  1238. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  1239. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4]]);
  1240. glTexCoord2f(cx,cz);
  1241.     glVertex3f(float(rx+8)*10+offsetx,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
  1242. glEnd();
  1243. numTriangles+=2;
  1244. }
  1245. int  CTerrain::GetPos(int x,int z)
  1246. {
  1247. return m_cHmap.m_pMovemap[(z)*256+x].zpos*256+m_cHmap.m_pMovemap[(z)*256+x].xpos;
  1248. }
  1249. int  CTerrain::GetXpos(int x,int z)
  1250. {
  1251. return m_cHmap.m_pMovemap[(128+z)*256+128+x].xpos;
  1252. }
  1253. int  CTerrain::GetZpos(int x,int z)
  1254. {
  1255. return m_cHmap.m_pMovemap[(128+z)*256+128+x].zpos;
  1256. }
  1257. CTerrain::~CTerrain()
  1258. {
  1259. for(int i=0;i<4;i++)
  1260.     glDeleteTextures(1,&Blend[i]);
  1261. for(i=0;i<5;i++)
  1262. {
  1263. glDeleteTextures(1,&BaseA[i]);
  1264. glDeleteTextures(1,&BaseB[i]);
  1265. }
  1266. }
  1267. int CTerrain::GetNumTriangles()
  1268. {
  1269. return numTriangles;
  1270. }