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

游戏引擎

开发平台:

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 "Texmanager.h"
  8. #include "GameSetting.h"
  9. #include "cmath.h"
  10. //////////////////////////////////////////////////////////////////////
  11. // Construction/Destruction
  12. //////////////////////////////////////////////////////////////////////
  13. CTerrain::CTerrain()
  14. {
  15. for(int i=0;i<128;i++)
  16. for(int j=0;j<128;j++)
  17. {
  18. Skinmap[i][j].TextureIndex=0;
  19. Skinmap[i][j].TextureOrder=0;
  20. }
  21. for( i=0;i<256;i++)
  22. for(int j=0;j<256;j++)
  23. {
  24.             NormalIndex[i*256+j]=0;
  25. }
  26. }
  27. bool CTerrain::InitTerrain()
  28. {
  29.  CTexManager cTexManager;
  30.  //////////////read blend skin texture
  31.      Blend[0]=cTexManager.GetTextureID(TEX_TERRAIN_SKN1);
  32.      Blend[1]=cTexManager.GetTextureID(TEX_TERRAIN_SKN2);
  33.      Blend[2]=cTexManager.GetTextureID(TEX_TERRAIN_SKN3);
  34.      Blend[3]=cTexManager.GetTextureID(TEX_TERRAIN_SKN4);
  35.  /////////////////////read base skin and cover skin texture
  36.  BaseA[0]=cTexManager.GetTextureID(TEX_TERRAIN_A1);
  37.  BaseA[1]=cTexManager.GetTextureID(TEX_TERRAIN_A2);
  38.  BaseA[2]=cTexManager.GetTextureID(TEX_TERRAIN_A3);
  39.  BaseA[3]=cTexManager.GetTextureID(TEX_TERRAIN_A4);
  40.  BaseA[4]=cTexManager.GetTextureID(TEX_TERRAIN_A5);
  41.  BaseB[0]=cTexManager.GetTextureID(TEX_TERRAIN_B1);
  42.  BaseB[1]=cTexManager.GetTextureID(TEX_TERRAIN_B2);
  43.  BaseB[2]=cTexManager.GetTextureID(TEX_TERRAIN_B3);
  44.  BaseB[3]=cTexManager.GetTextureID(TEX_TERRAIN_B4);
  45.  BaseB[4]=cTexManager.GetTextureID(TEX_TERRAIN_B5);
  46.  
  47.      Detail[0]=cTexManager.GetTextureID(TEX_TERRAIN_DETAIL_0);
  48. //   Detail[1]=cTexManager.GetTextureID(TEX_TERRAIN_DETAIL_1);
  49.      
  50.     //////////////////////init terrain skin
  51.     /////construct texture index 
  52. unsigned char index[64][64];
  53. FILE *fp;
  54. fp=fopen(CGameSetting::m_strTextureIndex,"rb");
  55. // fp=fopen("terrains/64_index.BMP","rb");
  56. if(!fp)return false;
  57. fseek(fp,1078,SEEK_SET);
  58. for(int z=63;z>-1;z--)
  59. for(int x=0;x<64;x++)
  60. {
  61. fread(&index[z][x],sizeof(unsigned char),1,fp);
  62. }
  63.     fclose(fp); 
  64.     /////////////////get texture index ,texture order 
  65. for( z=0;z<64;z++)
  66. for(int x=0;x<64;x++)
  67. {
  68. int  name=0;
  69. int addz=z+1;
  70. int addx=x+1;
  71. if(addx==64)addx=0;
  72. if(addz==64)addz=0;
  73. if(index[z][x]>64)    name+=8;
  74. if(index[z][addx]>64)  name+=4;
  75. if(index[addz][addx]>64)name+=2;
  76. if(index[addz][x]>64)  name+=1;
  77. ////////////////////////////////////
  78. if(name==15)//第一种贴图
  79. {   
  80. Skinmap[z][x].TextureIndex=BaseA[rand()%5];
  81.           Skinmap[z][x].TextureOrder=rand()%4;
  82. }
  83. else if(name==0)//第二种贴图
  84. {
  85. Skinmap[z][x].TextureIndex=BaseB[rand()%5];
  86.           Skinmap[z][x].TextureOrder=rand()%4;
  87. }
  88. else  //过渡贴图
  89. {
  90. if(name==8 || name==4 || name==2 || name==1 )
  91. Skinmap[z][x].TextureIndex=Blend[0];
  92. if(name==7 || name==11|| name==13|| name==14)
  93. Skinmap[z][x].TextureIndex=Blend[1];
  94. if(name==12|| name==6 || name==3 || name==9 )
  95. Skinmap[z][x].TextureIndex=Blend[2];
  96. if(name==10|| name==5  )
  97. Skinmap[z][x].TextureIndex=Blend[3];
  98. /////////////////// get order
  99. if(name==8 || name==7 || name==10|| name==12)
  100. Skinmap[z][x].TextureOrder=0;
  101. if(name==4 || name==11|| name==5 || name==6 )
  102. Skinmap[z][x].TextureOrder=1;
  103. if(name==2 || name==13|| name==3 )
  104. Skinmap[z][x].TextureOrder=2;
  105. if(name==1 || name==14|| name==9 )
  106. Skinmap[z][x].TextureOrder=3;
  107. }
  108. }
  109.     //////////////read lodmap.lod
  110. fp=fopen(CGameSetting::m_strLODmap,"rb");
  111. // fp=fopen("terrains/lodmap.lod","rb");
  112. if(!fp)return false;
  113. for( z=255;z>-1;z--)
  114. for(int x=0;x<256;x++)
  115. {
  116. fread(&LODmap[z][x],sizeof(unsigned char),1,fp);
  117. }
  118. ///////////////////////////////////////////////
  119. ///////////////Calculate light normal and lighting color
  120. CMath math;
  121. NORMAL na1,na2,na;
  122. NORMAL nb1,nb2,nb;
  123.     NORMAL normal;
  124. float  xz;
  125. float  xrot,yrot;
  126. for( z=0;z<256;z++)
  127. for(int x=0;x<256;x++)
  128. {
  129. int addz=z+1;   if(addz==256)addz=0;
  130. int subz=z-1;   if(subz==-1)subz=255;
  131. int addx=x+1;   if(addx==256)addx=0;
  132. int subx=x-1;   if(subx==-1)subx=255;
  133. na1=NORMAL(0, float(m_cHmap.m_pTmap[(addz)*256+x] -m_cHmap.m_pTmap[z*256+x] ),6);
  134. na2=NORMAL(6,float(m_cHmap.m_pTmap[z*256+addx] -m_cHmap.m_pTmap[z*256+x] ),0 );
  135. nb1=NORMAL(0, float(m_cHmap.m_pTmap[(subz)*256+x] -m_cHmap.m_pTmap[z*256+x] ),-6);
  136. nb2=NORMAL(-6,float(m_cHmap.m_pTmap[z*256+subx] -m_cHmap.m_pTmap[z*256+x] ),0 );
  137. na=math.GetTwoNormalProduct(na1,na2);
  138. nb=math.GetTwoNormalProduct(nb1,nb2);
  139.             //////////////////////////////////
  140.             normal.nx=na.nx+nb.nx;
  141.             normal.ny=na.ny+nb.ny;
  142.             normal.nz=na.nz+nb.nz;
  143. normal=math.Normalization(normal);
  144.             ///////////////////Init Lighting normal////////
  145. if(normal.ny>1)normal.ny=1;
  146. if(normal.ny<-1)normal.ny=-1;
  147. xrot=asinf(normal.ny)*57.29578f;
  148. xz=(float)sqrt(normal.nx*normal.nx+normal.nz*normal.nz);
  149. yrot=acosf(-normal.nz/xz)*57.29578f;
  150. if(normal.nx>0)yrot=360-yrot;
  151. NormalIndex[z*256+x]=int(xrot/10) * 36+ int(yrot/10);
  152. if(NormalIndex[z*256+x]>359)NormalIndex[z*256+x]=359;
  153.             ///////////////////Init Lighting Color////////
  154. /*
  155. float Aglcos=math.GetTwoVectorAngleCosine(NORMAL(-1.0f,0.5f,1.0f),normal);            
  156. if(Aglcos>0 && Aglcos<=1)ColorIndex[z*256+x]=int(Aglcos*255);
  157. else ColorIndex[z*256+x]=0;*/
  158. }
  159.     ////////// Init Lighting color
  160.             
  161. //////////////////end
  162. return true;
  163. }
  164. void CTerrain::RenderTerrain()
  165. {
  166. numTriangles=0;
  167.     glEnable(GL_DEPTH_TEST);
  168. int uppos=m_cHmap.m_cFrustumCull.m_upPos;
  169. int downpos=m_cHmap.m_cFrustumCull.m_downPos;
  170. for(int z=m_cHmap.m_cFrustumCull.m_pos[uppos].y;z<m_cHmap.m_cFrustumCull.m_pos[downpos].y;z++)
  171. for(int x=m_cHmap.m_cFrustumCull.m_LeftArray[z];x<m_cHmap.m_cFrustumCull.m_RightArray[z];x++)
  172.             RenderTerrainTile( x, z);
  173. m_cHmap.m_numTriangles +=numTriangles;
  174. }
  175. ////////////////////////////////////////////////////////
  176. void CTerrain::RenderTerrainTile(int x,int z)
  177. int level=LODmap[z][x];
  178. if(level==0)return;
  179.     if(level==7 )
  180.        DrawLevel_7(x-128,z-128);
  181.     else if(level==6 )
  182.        DrawLevel_6(x-128,z-128);
  183.     else if(level==5 )
  184.        DrawLevel_5(x-128,z-128);
  185.     else if(level==4)
  186.        DrawLevel_4(x-128,z-128);
  187.     else if(level==3)
  188.        DrawLevel_3(x-128,z-128);
  189.     else if(level==2)
  190.        DrawLevel_2(x-128,z-128);
  191.      else  if(level==1)
  192.        DrawLevel_1(x-128,z-128);
  193. }
  194. void CTerrain::DrawLevel_1(int x,int z)
  195. {
  196.             int rx=x*4;
  197.         int rz=z*4;
  198. int base0=GetPos(x+128,z+128);
  199. // int base1=GetPos(x+128-1,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
  200. int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
  201. int base3=GetPos(x+128+1,z+128+1);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
  202. int base4=GetPos(x+128+1,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  203. int base5=GetPos(x+128,z-1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  204.         float ax,az,bx,bz,cx,cz,dx,dz,ex,ez,fx,fz,gx,gz,hx,hz;
  205.             //////////////////////////// 
  206. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  207. glEnable(GL_TEXTURE_2D);
  208. ////////////Get Texture Order////////////////
  209. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  210.             {
  211. case 0:
  212.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  213. case 1:
  214.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  215. case 2:
  216.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  217.      case 3:
  218.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  219. default :
  220.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  221. }
  222. ex=(ax+bx)*0.5f; ez=(az+bz)*0.5f;
  223.             fx=(bx+cx)*0.5f;    fz=(bz+cz)*0.5f;
  224. gx=(cx+dx)*0.5f;    gz=(cz+dz)*0.5f;
  225. hx=(dx+ax)*0.5f;    hz=(dz+az)*0.5f;
  226. ///////////////////////////////////
  227. //////////////////Left_up
  228. ///////////////////////////////////
  229. glBegin(GL_TRIANGLE_FAN);
  230.             //6
  231. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+1]]);
  232. glTexCoord2f((dx+0.5f)*0.5f,(dz+0.5f)*0.5f);
  233.     glVertex3f(float((rx+1)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+256+1] ), float((rz+1)*10+m_cHmap.m_ViewOffsetZ));
  234.             //0
  235. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  236. glTexCoord2f(dx,dz);
  237.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  238.             //5
  239. if(LODmap[128+z][128+x-1]==1)
  240. {
  241.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256]]);
  242.     glTexCoord2f((dx+hx)*0.5f,(dz+hz)*0.5f);
  243.         glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+256] ), float(rz+1)*10+m_cHmap.m_ViewOffsetZ);
  244. }
  245.             //10
  246. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  247. glTexCoord2f(hx,hz);
  248.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  249. //11
  250.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+1]]);
  251.     glTexCoord2f((hx+0.5f)*0.5f,(hz+0.5f)*0.5f);
  252.         glVertex3f(float((rx+1)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+1] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  253. //12
  254. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  255. glTexCoord2f(0.5f,0.5f);
  256.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  257. //7
  258.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+2]]);
  259. glTexCoord2f((gx+0.5f)*0.5f,(gz+0.5f)*0.5f);
  260.     glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+256+2] ), float(rz+1)*10+m_cHmap.m_ViewOffsetZ);
  261.             //2
  262. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  263. glTexCoord2f(gx,gz);
  264.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  265.             //1
  266. if(LODmap[128+z-1][128+x]==1)
  267. {
  268.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+1]]);
  269.     glTexCoord2f((gx+dx)*0.5f,(gz+dz)*0.5f);
  270.         glVertex3f(float((rx+1)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+1] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  271. }
  272.             //0
  273. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  274. glTexCoord2f(dx,dz);
  275.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  276. glEnd();
  277. ///////////////////////////////////
  278. //////////////////Left_down
  279. ///////////////////////////////////
  280. glBegin(GL_TRIANGLE_FAN);
  281.             //16
  282. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+1]]);
  283. glTexCoord2f((ax+0.5f)*0.5f,(az+0.5f)*0.5f);
  284.     glVertex3f(float((rx+1)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+768+1] ), float((rz+3)*10+m_cHmap.m_ViewOffsetZ));
  285.             //10
  286. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  287. glTexCoord2f(hx,hz);
  288.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  289.             //15
  290. if(LODmap[128+z][128+x-1]==1)
  291. {
  292.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768]]);
  293.     glTexCoord2f((ax+hx)*0.5f,(az+hz)*0.5f);
  294.         glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+768] ), float(rz+3)*10+m_cHmap.m_ViewOffsetZ);
  295. }
  296.             //20
  297. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  298. glTexCoord2f(ax,az);
  299.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  300. //21
  301. if(LODmap[128+z+1][128+x]==1)
  302. {
  303.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+1]]);
  304.     glTexCoord2f((ax+ex)*0.5f,(az+ez)*0.5f);
  305.         glVertex3f(float((rx+1)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2+1] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  306. }
  307. //22
  308. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  309. glTexCoord2f(ex,ez);
  310.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  311. //17
  312.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+2]]);
  313.         glTexCoord2f((ex+0.5f)*0.5f,(ez+0.5f)*0.5f);
  314.         glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+768+2] ), float(rz+3)*10+m_cHmap.m_ViewOffsetZ);
  315. //12
  316. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  317. glTexCoord2f(0.5f,0.5f);
  318.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  319. //11
  320.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+1]]);
  321.     glTexCoord2f((hx+0.5f)*0.5f,(hz+0.5f)*0.5f);
  322.         glVertex3f(float((rx+1)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+1] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  323.             //10
  324. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  325. glTexCoord2f(hx,hz);
  326.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  327. glEnd();
  328. ///////////////////////////////////
  329. //////////////////right_up
  330. ///////////////////////////////////
  331. glBegin(GL_TRIANGLE_FAN);
  332.             //8
  333. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+3]]);
  334. glTexCoord2f((cx+0.5f)*0.5f,(cz+0.5f)*0.5f);
  335.     glVertex3f(float((rx+3)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+256+3] ), float((rz+1)*10+m_cHmap.m_ViewOffsetZ));
  336.             //2
  337. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  338. glTexCoord2f(gx,gz);
  339.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  340. //7
  341.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+2]]);
  342.     glTexCoord2f((gx+0.5f)*0.5f,(gz+0.5f)*0.5f);
  343.         glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+256+2] ), float(rz+1)*10+m_cHmap.m_ViewOffsetZ);
  344. //12
  345. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  346. glTexCoord2f(0.5f,0.5f);
  347.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  348.             //13
  349. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+3]]);
  350. glTexCoord2f((fx+0.5f)*0.5f,(fz+0.5f)*0.5f);
  351.     glVertex3f(float((rx+3)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+3] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  352.             //14
  353.         glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  354.         glTexCoord2f(fx,fz);
  355.             glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  356.             //9
  357. if(LODmap[128+z][128+x+1]==1)
  358. {
  359.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+256]]);
  360.     glTexCoord2f((fx+cx)*0.5f,(fz+cz)*0.5f);
  361.         glVertex3f(float(rx+4)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4+256]), float(rz+1)*10+m_cHmap.m_ViewOffsetZ);
  362. }
  363. //4
  364.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  365.     glTexCoord2f(cx,cz);
  366.         glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  367.             //3
  368. if(LODmap[128+z-1][128+x]==1)
  369. {
  370.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+3]]);
  371.     glTexCoord2f((gx+cx)*0.5f,(gz+cz)*0.5f);
  372.         glVertex3f(float((rx+3)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+3] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  373. }
  374.             //2
  375. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  376. glTexCoord2f(gx,gz);
  377.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  378. glEnd();
  379. ///////////////////////////////////
  380. //////////////////right_down
  381. ///////////////////////////////////
  382. glBegin(GL_TRIANGLE_FAN);
  383.             //18
  384. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+3]]);
  385. glTexCoord2f((bx+0.5f)*0.5f,(bz+0.5f)*0.5f);
  386.     glVertex3f(float((rx+3)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+768+3] ), float((rz+3)*10+m_cHmap.m_ViewOffsetZ));
  387. //12
  388. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  389. glTexCoord2f(0.5f,0.5f);
  390.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  391. //17
  392.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+2]]);
  393.     glTexCoord2f((ex+0.5f)*0.5f,(ez+0.5f)*0.5f);
  394.         glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+768+2] ), float(rz+3)*10+m_cHmap.m_ViewOffsetZ);
  395. //22
  396. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  397. glTexCoord2f(ex,ez);
  398.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  399.             //23
  400. if(LODmap[128+z+1][128+x]==1)
  401. {
  402.      glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+3]]);
  403.      glTexCoord2f((ex+bx)*0.5f,(ez+bz)*0.5f);
  404.         glVertex3f(float(rx+3)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2+3]), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  405. }
  406.             //24
  407.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  408.     glTexCoord2f(bx,bz);
  409.     glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  410.             //19
  411. if(LODmap[128+z][128+x+1]==1)
  412. {
  413.      glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+768]]);
  414.     glTexCoord2f((bx+fx)*0.5f,(bz+fz)*0.5f);
  415.         glVertex3f(float(rx+4)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4+768]), float(rz+3)*10+m_cHmap.m_ViewOffsetZ);
  416. }
  417.             //14
  418.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  419.     glTexCoord2f(fx,fz);
  420.     glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  421.             //13
  422. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+3]]);
  423. glTexCoord2f((fx+0.5f)*0.5f,(fz+0.5f)*0.5f);
  424.     glVertex3f(float((rx+3)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+3] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  425. //12
  426. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  427. glTexCoord2f(0.5f,0.5f);
  428.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  429. glEnd();
  430. numTriangles+=32;
  431. }
  432. void CTerrain::DrawLevel_2(int x,int z)
  433. {
  434.             int rx=x*4;
  435.         int rz=z*4;
  436. int base0=GetPos(x+128,z+128);
  437. // int base1=GetPos(x+128-1,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
  438. int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
  439. int base3=GetPos(x+128+1,z+128+1);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
  440. int base4=GetPos(x+128+1,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  441. int base5=GetPos(x+128,z-1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  442.         float ax,az,bx,bz,cx,cz,dx,dz,ex,ez,fx,fz,gx,gz,hx,hz;
  443.             //////////////////////////// 
  444. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  445. glEnable(GL_TEXTURE_2D);
  446. ////////////Get Texture Order////////////////
  447. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  448.             {
  449. case 0:
  450.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  451. case 1:
  452.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  453. case 2:
  454.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  455.      case 3:
  456.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  457. default :
  458.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  459. }
  460. ex=(ax+bx)*0.5f; ez=(az+bz)*0.5f;
  461.             fx=(bx+cx)*0.5f;    fz=(bz+cz)*0.5f;
  462. gx=(cx+dx)*0.5f;    gz=(cz+dz)*0.5f;
  463. hx=(dx+ax)*0.5f;    hz=(dz+az)*0.5f;
  464. ///////////////////////////////////
  465. //////////////////Left_up
  466. ///////////////////////////////////
  467. glBegin(GL_TRIANGLE_FAN);
  468.             //6
  469. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+1]]);
  470. glTexCoord2f((dx+0.5f)*0.5f,(dz+0.5f)*0.5f);
  471.     glVertex3f(float((rx+1)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+256+1] ), float((rz+1)*10+m_cHmap.m_ViewOffsetZ));
  472.             //0
  473. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  474. glTexCoord2f(dx,dz);
  475.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  476.             //10
  477. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  478. glTexCoord2f(hx,hz);
  479.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  480. //12
  481. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  482. glTexCoord2f(0.5f,0.5f);
  483.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  484.             //2
  485. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  486. glTexCoord2f(gx,gz);
  487.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  488.             //0
  489. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  490. glTexCoord2f(dx,dz);
  491.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  492. glEnd();
  493. ///////////////////////////////////
  494. //////////////////Left_down
  495. ///////////////////////////////////
  496. glBegin(GL_TRIANGLE_FAN);
  497.             //16
  498. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+1]]);
  499. glTexCoord2f((ax+0.5f)*0.5f,(az+0.5f)*0.5f);
  500.     glVertex3f(float((rx+1)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+768+1] ), float((rz+3)*10+m_cHmap.m_ViewOffsetZ));
  501.             //10
  502. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  503. glTexCoord2f(hx,hz);
  504.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  505.             //20
  506. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  507. glTexCoord2f(ax,az);
  508.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  509. //21
  510. //22
  511. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  512. glTexCoord2f(ex,ez);
  513.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  514. //12
  515. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  516. glTexCoord2f(0.5f,0.5f);
  517.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  518.             //10
  519. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  520. glTexCoord2f(hx,hz);
  521.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  522. glEnd();
  523. ///////////////////////////////////
  524. //////////////////right_up
  525. ///////////////////////////////////
  526. glBegin(GL_TRIANGLE_FAN);
  527.             //8
  528. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+3]]);
  529. glTexCoord2f((cx+0.5f)*0.5f,(cz+0.5f)*0.5f);
  530.     glVertex3f(float((rx+3)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+256+3] ), float((rz+1)*10+m_cHmap.m_ViewOffsetZ));
  531.             //2
  532. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  533. glTexCoord2f(gx,gz);
  534.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  535. //12
  536. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  537. glTexCoord2f(0.5f,0.5f);
  538.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  539.             //14
  540.         glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  541.         glTexCoord2f(fx,fz);
  542.             glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  543. //4
  544.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  545.     glTexCoord2f(cx,cz);
  546.         glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  547.             //2
  548. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  549. glTexCoord2f(gx,gz);
  550.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  551. glEnd();
  552. ///////////////////////////////////
  553. //////////////////right_down
  554. ///////////////////////////////////
  555. glBegin(GL_TRIANGLE_FAN);
  556.             //18
  557. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+3]]);
  558. glTexCoord2f((bx+0.5f)*0.5f,(bz+0.5f)*0.5f);
  559.     glVertex3f(float((rx+3)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+768+3] ), float((rz+3)*10+m_cHmap.m_ViewOffsetZ));
  560. //12
  561. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  562. glTexCoord2f(0.5f,0.5f);
  563.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  564.       //22
  565. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  566. glTexCoord2f(ex,ez);
  567.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  568.             //24
  569.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  570.     glTexCoord2f(bx,bz);
  571.     glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  572.             //14
  573.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  574.     glTexCoord2f(fx,fz);
  575.     glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  576. //12
  577. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  578. glTexCoord2f(0.5f,0.5f);
  579.     glVertex3f(float(rx+2)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  580. glEnd();
  581. numTriangles+=16;
  582. }
  583. void CTerrain::DrawLevel_3(int x,int z)
  584. {
  585.             int rx=x*4;
  586.         int rz=z*4;
  587. int base0=GetPos(x+128,z+128);
  588. // int base1=GetPos(x-1+128,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
  589. int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
  590. int base3=GetPos(x+1+128,z+1+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
  591. int base4=GetPos(x+1+128,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  592. int base5=GetPos(x+128,z-1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  593.         float ax,az,bx,bz,cx,cz,dx,dz;
  594.             //////////////////////////// 
  595. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  596. glEnable(GL_TEXTURE_2D);
  597. ////////////Get Texture Order////////////////
  598. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  599.             {
  600. case 0:
  601.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  602. case 1:
  603.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  604. case 2:
  605.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  606.      case 3:
  607.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  608. default :
  609.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  610. }
  611. glBegin(GL_TRIANGLE_FAN);
  612. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  613. glTexCoord2f(0.5f,0.5f);
  614.     glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float((rz+2)*10+m_cHmap.m_ViewOffsetZ));
  615. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  616. glTexCoord2f(dx,dz);
  617.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  618.             
  619.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  620. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base0+256]]);
  621.     glTexCoord2f((ax+dx)*0.5f,(az+dz)*0.5f);
  622.         glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  623. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  624. glTexCoord2f(ax,az);
  625.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  626.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  627.     glTexCoord2f((ax+bx)*0.5f,(az+bz)*0.5f);
  628.         glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  629. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  630. glTexCoord2f(bx,bz);
  631.     glVertex3f(float(rx+4)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  632.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  633. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4+256]]);
  634.     glTexCoord2f((cx+bx)*0.5f,(cz+bz)*0.5f);
  635.         glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  636. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  637. glTexCoord2f(cx,cz);
  638.     glVertex3f(float(rx+4)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  639.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  640.     glTexCoord2f((cx+dx)*0.5f,(cz+dz)*0.5f);
  641.         glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  642. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  643. glTexCoord2f(dx,dz);
  644.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  645. glEnd();
  646. /////////////////////////blend
  647. /*
  648. glBindTexture(GL_TEXTURE_2D, Detail[0]);
  649. glEnable(GL_TEXTURE_2D);
  650. // glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_COLOR);
  651. glBlendFunc(GL_DST_COLOR,GL_SRC_COLOR);
  652. glEnable(GL_BLEND);
  653. glBegin(GL_TRIANGLE_FAN);
  654. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  655. glTexCoord2f(0.5f,0.5f);
  656.     glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float((rz+2)*10+m_cHmap.m_ViewOffsetZ));
  657. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  658. glTexCoord2f(dx,dz);
  659.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  660.             
  661.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  662. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base0+256]]);
  663.     glTexCoord2f((ax+dx)*0.5f,(az+dz)*0.5f);
  664.         glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  665. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  666. glTexCoord2f(ax,az);
  667.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  668.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  669.     glTexCoord2f((ax+bx)*0.5f,(az+bz)*0.5f);
  670.         glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  671. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  672. glTexCoord2f(bx,bz);
  673.     glVertex3f(float(rx+4)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  674.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  675. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4+256]]);
  676.     glTexCoord2f((cx+bx)*0.5f,(cz+bz)*0.5f);
  677.         glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  678. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  679. glTexCoord2f(cx,cz);
  680.     glVertex3f(float(rx+4)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  681.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  682.     glTexCoord2f((cx+dx)*0.5f,(cz+dz)*0.5f);
  683.         glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  684. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  685. glTexCoord2f(dx,dz);
  686.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  687. glEnd();
  688. */
  689. glDisable(GL_BLEND);
  690. numTriangles+=8;
  691. }
  692. void CTerrain::DrawLevel_4(int x,int z)
  693. {
  694.             int rx=x*4;
  695.         int rz=z*4;
  696. int base0=GetPos(x+128,z+128);
  697. // int base1=GetPos(x-1+128,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
  698. int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
  699. int base3=GetPos(x+1+128,z+1+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
  700. int base4=GetPos(x+1+128,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  701. // int base5=GetPos(x+128,z-1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  702.         float ax,az,bx,bz,cx,cz,dx,dz;
  703.             //////////////////////////// 
  704. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  705. glEnable(GL_TEXTURE_2D);
  706. ////////////Get Texture Order////////////////
  707. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  708.             {
  709. case 0:
  710.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  711. case 1:
  712.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  713. case 2:
  714.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  715.      case 3:
  716.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  717. default :
  718.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  719. }
  720. glBegin(GL_TRIANGLE_FAN);
  721.             //12
  722. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
  723. glTexCoord2f(0.5f,0.5f);
  724.     glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512+2] ), float((rz+2)*10+m_cHmap.m_ViewOffsetZ));
  725.             //0
  726. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  727. glTexCoord2f(dx,dz);
  728.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  729.             //10
  730. if(LODmap[128+z][128+x-1]<4)
  731. {
  732.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
  733.     glTexCoord2f((ax+dx)*0.5f,(az+dz)*0.5f);
  734.         glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+512] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  735. }
  736.             //20
  737. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  738. glTexCoord2f(ax,az);
  739.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  740. //22
  741. if(LODmap[128+z+1][128+x]<4)
  742. {
  743.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
  744.     glTexCoord2f((ax+bx)*0.5f,(az+bz)*0.5f);
  745.         glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  746. }
  747.             //24
  748. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  749. glTexCoord2f(bx,bz);
  750.     glVertex3f(float(rx+4)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  751.             //14
  752. if(LODmap[128+z][128+x+1]<4)
  753. {
  754.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
  755. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4+256]]);
  756.     glTexCoord2f((cx+bx)*0.5f,(cz+bz)*0.5f);
  757.         glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+m_cHmap.m_ViewOffsetZ);
  758. }
  759.             //4
  760. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  761. glTexCoord2f(cx,cz);
  762.     glVertex3f(float(rx+4)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  763.             //2
  764. if(LODmap[128+z-1][128+x]<4)
  765. {
  766.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
  767.     glTexCoord2f((cx+dx)*0.5f,(cz+dz)*0.5f);
  768.         glVertex3f(float((rx+2)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  769. }
  770. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  771. glTexCoord2f(dx,dz);
  772.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  773. glEnd();
  774. numTriangles+=4;
  775. }
  776. void CTerrain::DrawLevel_5(int x,int z)
  777. {
  778.             int rx=x*4;
  779.         int rz=z*4;
  780. int base0=GetPos(x+128,z+128);
  781. // int base1=GetPos(x-1+128,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
  782. int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
  783. int base3=GetPos(x+1+128,z+1+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
  784. int base4=GetPos(x+1+128,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  785.         float ax,az,bx,bz,cx,cz,dx,dz;
  786.             //////////////////////////// 
  787. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  788. glEnable(GL_TEXTURE_2D);
  789. ////////////Get Texture Order////////////////
  790. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  791.             {
  792. case 0:
  793.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  794. case 1:
  795.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  796. case 2:
  797.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  798.      case 3:
  799.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  800. default :
  801.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  802. }
  803. glBegin(GL_TRIANGLE_FAN);
  804. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  805. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base0]]);
  806. glTexCoord2f(dx,dz);
  807.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  808. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  809. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base2]]);
  810. glTexCoord2f(ax,az);
  811.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  812. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  813. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base3]]);
  814. glTexCoord2f(bx,bz);
  815.     glVertex3f(float(rx+4)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  816. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  817. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4]]);
  818. glTexCoord2f(cx,cz);
  819.     glVertex3f(float(rx+4)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  820. glEnd();
  821. numTriangles+=2;
  822. }
  823. void CTerrain::DrawLevel_6(int x,int z)
  824. {
  825.             int rx=x*4;
  826.         int rz=z*4;
  827. int base0=GetPos(x+128,z+128);
  828. int base1=GetPos(x+128,z+2+128);
  829. int base2=GetPos(x+2+128,z+2+128);
  830. int base3=GetPos(x+2+128,z+128);
  831. int base4=GetPos(x+1+128,z+1+128);
  832. int base5=GetPos(x+128,z+1+128);
  833. int base6=GetPos(x+1+128,z+2+128);
  834. int base7=GetPos(x+2+128,z+1+128);
  835. int base8=GetPos(x+1+128,z+128);
  836.         float ax,az,bx,bz,cx,cz,dx,dz;
  837.             //////////////////////////// 
  838. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  839. glEnable(GL_TEXTURE_2D);
  840. ////////////Get Texture Order////////////////
  841. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  842.             {
  843. case 0:
  844.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  845. case 1:
  846.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  847. case 2:
  848.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  849.      case 3:
  850.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  851. default :
  852.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  853. }
  854. glBegin(GL_TRIANGLE_FAN);
  855.  
  856. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  857. glTexCoord2f(0.5f,0.5f);
  858.     glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4] ), float((rz+4)*10+m_cHmap.m_ViewOffsetZ));
  859. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  860. glTexCoord2f(dx,dz);
  861.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  862.    
  863. if(LODmap[128+z][128+x-2]!=7)
  864. {
  865.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base5]]);
  866.     glTexCoord2f((ax+dx)*0.5f,(az+dz)*0.5f);
  867.         glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base5] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  868. }
  869. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base1]]);
  870. glTexCoord2f(ax,az);
  871.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base1]), float(rz+8)*10+m_cHmap.m_ViewOffsetZ);
  872. if(LODmap[128+z+2][128+x]!=7)
  873. {
  874.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base6]]);
  875.     glTexCoord2f((ax+bx)*0.5f,(az+bz)*0.5f);
  876.         glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base6] ), float(rz+8)*10+m_cHmap.m_ViewOffsetZ);
  877. }
  878.        
  879. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  880. glTexCoord2f(bx,bz);
  881.     glVertex3f(float(rx+8)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2] ), float(rz+8)*10+m_cHmap.m_ViewOffsetZ);
  882.       
  883. if(LODmap[128+z][128+x+2]!=7)
  884. {
  885.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base7]]);
  886.     glTexCoord2f((cx+bx)*0.5f,(cz+bz)*0.5f);
  887.         glVertex3f(float((rx+8)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base7] ), float(rz+4)*10+m_cHmap.m_ViewOffsetZ);
  888. }
  889.     
  890. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  891. glTexCoord2f(cx,cz);
  892.     glVertex3f(float(rx+8)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base3] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  893.             //2
  894. if(LODmap[128+z-2][128+x]!=7)
  895. {
  896.     glNormal3fv(cNormal.m_3dENormal[NormalIndex[base8]]);
  897.     glTexCoord2f((cx+dx)*0.5f,(cz+dz)*0.5f);
  898.         glVertex3f(float((rx+4)*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base8] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  899. }
  900. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  901. glTexCoord2f(dx,dz);
  902.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  903. glEnd();
  904. numTriangles+=4;
  905. }
  906. void CTerrain::DrawLevel_7(int x,int z)
  907. {
  908.             int rx=x*4;
  909.         int rz=z*4;
  910. int base0=GetPos(x+128,z+128);
  911. // int base1=GetPos(x-1+128,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
  912. int base2=GetPos(x+128,z+2+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
  913. int base3=GetPos(x+2+128,z+2+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
  914. int base4=GetPos(x+2+128,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
  915.         float ax,az,bx,bz,cx,cz,dx,dz;
  916.             //////////////////////////// 
  917. glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
  918. glEnable(GL_TEXTURE_2D);
  919. ////////////Get Texture Order////////////////
  920. switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
  921.             {
  922. case 0:
  923.                 ax=0; az=0; bx=1;bz=0;  cx=1;cz=1;  dx=0; dz=1; break;
  924. case 1:
  925.                 ax=1; az=0; bx=1;bz=1;  cx=0;cz=1;  dx=0; dz=0; break;
  926. case 2:
  927.                 ax=1; az=1; bx=0;bz=1;  cx=0;cz=0;  dx=1; dz=0; break;
  928.      case 3:
  929.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;
  930. default :
  931.                 ax=0; az=1; bx=0;bz=0;  cx=1;cz=0; dx=1; dz=1; break;   
  932. }
  933. glBegin(GL_TRIANGLE_FAN);
  934. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
  935. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base0]]);
  936. glTexCoord2f(dx,dz);
  937.     glVertex3f(float(rx*10)+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base0] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  938. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
  939. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base2]]);
  940. glTexCoord2f(ax,az);
  941.     glVertex3f(float(rx)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base2]), float(rz+8)*10+m_cHmap.m_ViewOffsetZ);
  942. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
  943. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base3]]);
  944. glTexCoord2f(bx,bz);
  945.     glVertex3f(float(rx+8)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base3] ), float(rz+8)*10+m_cHmap.m_ViewOffsetZ);
  946. glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
  947. //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4]]);
  948. glTexCoord2f(cx,cz);
  949.     glVertex3f(float(rx+8)*10+m_cHmap.m_ViewOffsetX,  float(m_cHmap.m_pTmap[base4] ), float(rz)*10+m_cHmap.m_ViewOffsetZ);
  950. glEnd();
  951. numTriangles+=2;
  952. }
  953. int  CTerrain::GetPos(int x,int z)
  954. {
  955. return m_cHmap.m_pMovemap[(z)*256+x].zpos*256+m_cHmap.m_pMovemap[(z)*256+x].xpos;
  956. }
  957. int  CTerrain::GetXpos(int x,int z)
  958. {
  959. return m_cHmap.m_pMovemap[(128+z)*256+128+x].xpos;
  960. }
  961. int  CTerrain::GetZpos(int x,int z)
  962. {
  963. return m_cHmap.m_pMovemap[(128+z)*256+128+x].zpos;
  964. }
  965. CTerrain::~CTerrain()
  966. {
  967. for(int i=0;i<4;i++)
  968.     glDeleteTextures(1,&Blend[i]);
  969. for(i=0;i<5;i++)
  970. {
  971. glDeleteTextures(1,&BaseA[i]);
  972. glDeleteTextures(1,&BaseB[i]);
  973. }
  974. }
  975. int CTerrain::GetNumTriangles()
  976. {
  977. return numTriangles;
  978. }
  979. void CTerrain::DrawBase()
  980. {
  981.     glPushMatrix();
  982. glTranslatef(m_cHmap.m_ViewPos.xpos,0,m_cHmap.m_ViewPos.zpos);
  983.    glRotatef(m_cHmap.m_ViewRotY,  0.0f,1.0f,0.0f);
  984. // glRotatef(-*m_cHmap.m_pViewRotX,  1.0f,0.0f,0.0f);
  985. glBindTexture(GL_TEXTURE_2D, BaseA[0]);
  986. glEnable(GL_TEXTURE_2D);
  987. glBegin(GL_TRIANGLE_STRIP);
  988. glTexCoord2f(0,0);
  989.         glVertex3f(-12800,0 ,0);
  990. glTexCoord2f(1,0);
  991.         glVertex3f(12800,0 ,0);
  992. glTexCoord2f(0,1);
  993.         glVertex3f(-12800,0 ,-12800);
  994. glTexCoord2f(1,1);
  995.         glVertex3f(12800,0 ,-12800);
  996. glTexCoord2f(0,0);
  997.         glVertex3f(-12800,30 ,-12800);
  998. glTexCoord2f(1,0);
  999.         glVertex3f(12800,30 ,-12800);
  1000. glEnd();
  1001.     glPopMatrix();
  1002. }