Terrain.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:51k
- // Terrain.cpp: implementation of the CTerrain class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include <stdio.h>
- #include "Terrain.h"
- #include "Texture.h"
- #include "cmath.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CTerrain::CTerrain()
- {
- for(int i=0;i<128;i++)
- for(int j=0;j<128;j++)
- {
- Skinmap[i][j].TextureIndex=0;
- Skinmap[i][j].TextureOrder=0;
- }
- for( i=0;i<256;i++)
- for(int j=0;j<256;j++)
- {
- m_cHmap.m_pMovemap[i*256+j].xpos=0;
- m_cHmap.m_pMovemap[i*256+j].zpos=0;
- NormalIndex[i*256+j]=0;
- }
- }
- bool CTerrain::InitTerrain()
- {
- CTexture cTex;
- //////////////read blend skin texture
- int i;
- char filename[64];
- for(i=0;i<4;i++)
- {
- wsprintf(filename,"Terrains/TerrainSkin/TerSkin%d.skn",i+1);
- if(!cTex.MakeSkinTextureBind(filename,&Blend[i]))
- {
- MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
- return false;
- }
- }
- /////////////////////read base skin and cover skin texture
- for(i=0;i<TEX_TYPE;i++)
- {
- wsprintf(filename,"Terrains/TerrainSkin/A%d.bmp",i+1);
- if(!cTex.MakeTextureBind(filename,&BaseA[i]))
- {
- MessageBox(NULL,"Read A Skin error","ERROR",MB_OK|MB_ICONSTOP);
- return false;
- }
- wsprintf(filename,"Terrains/TerrainSkin/B%d.bmp",i+1);
- if(!cTex.MakeTextureBind(filename,&BaseB[i]))
- {
- MessageBox(NULL,"Read B Skin error","ERROR",MB_OK|MB_ICONSTOP);
- return false;
- }
- }
- /*
- ///////////read detail map
- for(i=0;i<2;i++)
- {
- wsprintf(filename,"Terrains/detail%d.bmp",i+1);
- if(!cTex.MakeTextureBind(filename,&Detail[i]))
- {
- MessageBox(NULL,"Read A Skin error","ERROR",MB_OK|MB_ICONSTOP);
- return false;
- }
- }*/
- //////////////////////init terrain skin
- /////construct texture index
- unsigned char index[64][64];
- FILE *fp;
- fp=fopen("Terrains/texindex_64.bmp","rb");
- if(!fp)return false;
- fseek(fp,1078,SEEK_SET);
- for(int z=63;z>-1;z--)
- for(int x=0;x<64;x++)
- {
- fread(&index[z][x],sizeof(unsigned char),1,fp);
- }
- fclose(fp);
- /////////////////get texture index ,texture order
- for( z=0;z<64;z++)
- for(int x=0;x<64;x++)
- {
- int name=0;
- int addz=z+1;
- int addx=x+1;
- if(addx==64)addx=0;
- if(addz==64)addz=0;
- if(index[z][x]>64) name+=8;
- if(index[z][addx]>64) name+=4;
- if(index[addz][addx]>64)name+=2;
- if(index[addz][x]>64) name+=1;
- ////////////////////////////////////
- if(name==15)//第一种贴图
- {
- Skinmap[z][x].TextureIndex=BaseA[rand()%TEX_TYPE];
- Skinmap[z][x].TextureOrder=rand()%4;
- }
- else if(name==0)//第二种贴图
- {
- Skinmap[z][x].TextureIndex=BaseB[rand()%TEX_TYPE];
- Skinmap[z][x].TextureOrder=rand()%4;
- }
- else //过渡贴图
- {
- if(name==8 || name==4 || name==2 || name==1 )
- Skinmap[z][x].TextureIndex=Blend[0];
- if(name==7 || name==11|| name==13|| name==14)
- Skinmap[z][x].TextureIndex=Blend[1];
- if(name==12|| name==6 || name==3 || name==9 )
- Skinmap[z][x].TextureIndex=Blend[2];
-
- if(name==10|| name==5 )
- Skinmap[z][x].TextureIndex=Blend[3];
- /////////////////// get order
- if(name==8 || name==7 || name==10|| name==12)
- Skinmap[z][x].TextureOrder=0;
- if(name==4 || name==11|| name==5 || name==6 )
- Skinmap[z][x].TextureOrder=1;
- if(name==2 || name==13|| name==3 )
- Skinmap[z][x].TextureOrder=2;
- if(name==1 || name==14|| name==9 )
- Skinmap[z][x].TextureOrder=3;
- }
- }
- //////////////read lodmap.lod
- fp=fopen("Terrains/lodmap.lod","rb");
- if(!fp)return false;
- for( z=255;z>-1;z--)
- for(int x=0;x<256;x++)
- {
- fread(&LODmap[z][x],sizeof(unsigned char),1,fp);
- }
- ///////////////////////////////////////////////
- cFrustumCull.InitFrustumCull(40,60);
- ///////////////////////////////////////////////
- ///////////////Calculate light normal and lighting color
- CMath math;
- NORMAL na1,na2,na;
- NORMAL nb1,nb2,nb;
- NORMAL normal;
- float xz;
- float xrot,yrot;
- for( z=0;z<256;z++)
- for(int x=0;x<256;x++)
- {
- int addz=z+1; if(addz==256)addz=0;
- int subz=z-1; if(subz==-1)subz=255;
- int addx=x+1; if(addx==256)addx=0;
- int subx=x-1; if(subx==-1)subx=255;
- na1=NORMAL(0, float(m_cHmap.m_pTmap[(addz)*256+x] -m_cHmap.m_pTmap[z*256+x] ),6);
- na2=NORMAL(6,float(m_cHmap.m_pTmap[z*256+addx] -m_cHmap.m_pTmap[z*256+x] ),0 );
-
- nb1=NORMAL(0, float(m_cHmap.m_pTmap[(subz)*256+x] -m_cHmap.m_pTmap[z*256+x] ),-6);
- nb2=NORMAL(-6,float(m_cHmap.m_pTmap[z*256+subx] -m_cHmap.m_pTmap[z*256+x] ),0 );
- na=math.GetTwoNormalProduct(na1,na2);
- nb=math.GetTwoNormalProduct(nb1,nb2);
- //////////////////////////////////
- normal.nx=na.nx+nb.nx;
- normal.ny=na.ny+nb.ny;
- normal.nz=na.nz+nb.nz;
- normal=math.Normalization(normal);
- ///////////////////Init Lighting normal////////
- if(normal.ny>1)normal.ny=1;
- if(normal.ny<-1)normal.ny=-1;
- xrot=asinf(normal.ny)*57.29578f;
- xz=(float)sqrt(normal.nx*normal.nx+normal.nz*normal.nz);
- yrot=acosf(-normal.nz/xz)*57.29578f;
- if(normal.nx>0)yrot=360-yrot;
- NormalIndex[z*256+x]=int(xrot/10) * 36+ int(yrot/10);
- if(NormalIndex[z*256+x]>359)NormalIndex[z*256+x]=359;
- ///////////////////Init Lighting Color////////
- /*
- float Aglcos=math.GetTwoVectorAngleCosine(NORMAL(-1.0f,0.5f,1.0f),normal);
- if(Aglcos>0 && Aglcos<=1)ColorIndex[z*256+x]=int(Aglcos*255);
- else ColorIndex[z*256+x]=0;*/
- }
- ////////// Init Lighting color
-
- //////////////////end
- return true;
- }
- void CTerrain::FillMovemap()
- {
- offsetx=int(m_cHmap.m_pViewPos->xpos*0.025f);
- if(offsetx<0)offsetx-=1;
- biasX=m_cHmap.m_pViewPos->xpos*0.025f-offsetx;
- offsetz=int(m_cHmap.m_pViewPos->zpos*0.025f);
- if(offsetz<0)offsetz-=1;
- biasZ=m_cHmap.m_pViewPos->zpos*0.025f-offsetz;
- int startz=((cFrustumCull.m_MinZ+offsetz)*4)%256;
- if(startz<0)startz=256+startz;
- int startx=((cFrustumCull.m_MinX+offsetx)*4)%256;
- if(startx<0)startx=256+startx;
- int zpos=startz;
- for(int z=cFrustumCull.m_MinZ;z<cFrustumCull.m_MaxZ;z++)
- {
- int xpos=startx;
- for(int x=cFrustumCull.m_MinX;x<cFrustumCull.m_MaxX;x++)
- {
- m_cHmap.m_pMovemap[(128+z)*256+128+x].xpos=xpos;
- m_cHmap.m_pMovemap[(128+z)*256+128+x].zpos=zpos;
- xpos+=4;
- if(xpos>252)xpos=0;
- }
- zpos+=4;
- if(zpos>252)zpos=0;
- }
- offsetx=offsetx*40;
- offsetz=offsetz*40;
- }
- void CTerrain::UpdateTerrainmap()
- {
- cFrustumCull.UpdateFrustumCull(*m_cHmap.m_pViewRotY);
- numTriangles=0;
- FillMovemap();
- UpdateLODmap();
- ///// Update boundary
- m_cHmap.m_rect.minx=cFrustumCull.m_MinX+128;
- m_cHmap.m_rect.maxx=cFrustumCull.m_MaxX+128;
- m_cHmap.m_rect.minz=cFrustumCull.m_MinZ+128;
- m_cHmap.m_rect.maxz=cFrustumCull.m_MaxZ+128;
- }
- ////////////////////////////////////////////////////////
- void CTerrain::UpdateLODmap()
- {
- int leftX,leftZ;
- int rightX, rightZ;
- int foucsX, foucsZ;
- int step=1;
- /////////////////////////////////////////////////
- ////////////////////////Left
-
- if(cFrustumCull.m_LeftArray[127]==0) //X
- {
- leftX=cFrustumCull.m_LeftArray[125];
- foucsX=cFrustumCull.m_LeftArray[126];
- leftZ=cFrustumCull.m_LeftArray[0];
- foucsZ=cFrustumCull.m_LeftArray[cFrustumCull.m_LeftArray[124]-1];
- int num=cFrustumCull.m_LeftArray[124];
- if(leftX<foucsX)
- for(int i=0;i<num;i+=step)
- ProcessLine(leftX+i,cFrustumCull.m_LeftArray[i]);
- else
- for(int i=0;i<num;i+=step)
- ProcessLine(leftX-i,cFrustumCull.m_LeftArray[i]);
- }else //Z
- {
- leftX=cFrustumCull.m_LeftArray[0];
- foucsX=cFrustumCull.m_LeftArray[cFrustumCull.m_LeftArray[124]-1];
- leftZ=cFrustumCull.m_LeftArray[125];
- foucsZ=cFrustumCull.m_LeftArray[126];
- int num=cFrustumCull.m_LeftArray[124];
- if(leftZ<foucsZ)
- for(int i=0;i<num;i+=step)
- ProcessLine(cFrustumCull.m_LeftArray[i],leftZ+i);
- else
- for(int i=0;i<num;i+=step)
- ProcessLine(cFrustumCull.m_LeftArray[i],leftZ-i);
- }
- ////////////////////////////////////////////////
- ///////////////////////right
- if(cFrustumCull.m_RightArray[127]==0) //X
- {
- foucsX=cFrustumCull.m_RightArray[125];
- rightX=cFrustumCull.m_RightArray[126];
- foucsZ=cFrustumCull.m_RightArray[0];
- rightZ=cFrustumCull.m_RightArray[cFrustumCull.m_RightArray[124]-1];
- int num=cFrustumCull.m_RightArray[124];
- if(foucsX<rightX)
- for(int i=0;i<num;i+=step)
- ProcessLine(foucsX+i,cFrustumCull.m_RightArray[i]);
- else
- for(int i=0;i<num;i+=step)
- ProcessLine(foucsX-i,cFrustumCull.m_RightArray[i]);
- }else //Z
- {
- foucsX=cFrustumCull.m_RightArray[0];
- rightX=cFrustumCull.m_RightArray[cFrustumCull.m_RightArray[124]-1];
- foucsZ=cFrustumCull.m_RightArray[125];
- rightZ=cFrustumCull.m_RightArray[126];
- int num=cFrustumCull.m_RightArray[124];
- if(foucsZ<rightZ)
- for(int i=0;i<num;i+=step)
- ProcessLine(cFrustumCull.m_RightArray[i],foucsZ+i);
- else
- for(int i=0;i<num;i+=step)
- ProcessLine(cFrustumCull.m_RightArray[i],foucsZ-i);
- }
- /////////////////////////////////////////
- /*
- radius=4;
- maxx=radius;
- minx=-radius;
- maxz=radius;
- minz=-radius;
-
- if(cFrustumCull.m_MaxX<maxx)maxx=cFrustumCull.m_MaxX;
- if(cFrustumCull.m_MinX>minx)minx=cFrustumCull.m_MinX;
- if(cFrustumCull.m_MaxZ<maxz)maxz=cFrustumCull.m_MaxZ;
- if(cFrustumCull.m_MinZ>minz)minz=cFrustumCull.m_MinZ;
- */
- for(int z=127;z<130;z++)
- for(int x=127;x<130;x++)
- DrawMap[z][x]=1;
- /////////////////////
- /*
- /////////////////
- glBegin(GL_LINE_STRIP);
- glVertex3f(pViewerPos->xpos,100,pViewerPos->zpos);
- glVertex3f(leftX*20,100,leftZ*20);
- glVertex3f(foucsX*20,100,foucsZ*20);
- glVertex3f(rightX*20,100,rightZ*20);
- glVertex3f(pViewerPos->xpos,100,pViewerPos->zpos);
- glEnd();
- */
- }
- void CTerrain::ProcessLine(int ox,int oz)//处理(X,Y,Z)到视点连线之间的点
- {
- float x=float(128+ox);
- float z=float(128+oz);
- float viewx=128;
- float viewz=128;
- float viewy=m_cHmap.m_pViewPos->ypos+10;
- float dx=viewx - x; //视点与(x,y,z)在x轴之差
- float dz=viewz - z; //视点与(x,y,z)在z轴之差
- int signx,signz;
- if(dx<0)
- {dx=-dx; signx=-1;}
- else
- signx=1;
- if(dz<0)
- {dz=-dz; signz=-1;}
- else
- signz=1;
- // From viewer to (x,y,z) position
- if(dz>dx)
- {
- float bias,deltaX,curX;
- if(signz==1)
- {
- bias=(dx+biasX*signx)*dz*10/((dz+biasZ)*10)-dx;
- /* viewy=m_cHmap.GetHeight(m_cHmap.m_pViewPos->xpos-(biasX-bias)*40,
- m_cHmap.m_pViewPos->zpos-(biasZ)*40); */
- }
- else
- {
- bias=(dx+biasX*signx)*(dz-1)*10/((dz-biasZ)*10)-dx;
- dz--;
- viewz++;
- /* viewy=m_cHmap.GetHeight(m_cHmap.m_pViewPos->xpos-(biasX-bias)*40,
- m_cHmap.m_pViewPos->zpos+(1-biasZ)*40); */
- }
- deltaX=signx*(dx+bias)/dz;
- curX=viewx+bias*signx;
- int intx;
- float slope=-1000;
- float curVH=0;
- float max,min;
- for(int i=1;i<dz;i++)
- {
- curX-=deltaX;
- intx=int(curX);
- float h1=m_cHmap.m_pTmap[GetPos(intx,int(viewz-signz*i))];
- float h2=m_cHmap.m_pTmap[GetPos(intx+1,int(viewz-signz*i))];
- if(h2>h1){max=h2;min=h1;}
- else {max=h1;min=h2;}
-
- float newSlope=float(max-viewy)/(i);
-
- if(newSlope>slope) //visible
- {
- slope=float(min-viewy)/(i);//newSlope*1.01f;
- DrawMap[int(viewz-signz*i)][intx]=1;
- DrawMap[int(viewz-signz*i)][intx+1]=1;
- }
- }
- }
- else /////////////// dx>dz
- {
- float bias,deltaZ,curZ;
- if(signx==1)
- bias=(dz+biasZ*signz)*dx*10/((dx+biasX)*10)-dz;
- else
- {
- bias=(dz+biasZ*signz)*(dx-1)*10/((dx-biasX)*10)-dz;
- dx--;
- viewx++;
- }
- deltaZ=signz*(dz+bias)/dx;
- curZ=viewz+bias*signz;
- int intz;
- float slope=-1000;
- for(int i=1;i<dx;i++)
- {
- curZ-=deltaZ;
- intz=int(curZ);
- float h1=m_cHmap.m_pTmap[GetPos(int(viewx-signx*i),intz)];
- float h2=m_cHmap.m_pTmap[GetPos(int(viewx-signx*i),intz+1)];
- float max,min;
- if(h2>h1){max=h2;min=h1;}
- else {max=h1;min=h2;}
- float newSlope=float(max-viewy)/i;
- if(newSlope>slope) //visible
- {
- slope=float(min-viewy)/i;
- DrawMap[intz][int(viewx-signx*i)]=1;
- DrawMap[(intz+1)][int(viewx-signx*i)]=1;
- }
- }
- }
- }
- void CTerrain::RestoreDrawMap()
- {
- for(int z=cFrustumCull.m_MinZ;z<cFrustumCull.m_MaxZ;z++)
- for(int x=cFrustumCull.m_MinX;x<cFrustumCull.m_MaxX;x++)
- DrawMap[128+z][128+x]=0;
- for( z=minz;z<maxz;z++)
- for(int x=minx;x<maxx;x++)
- DrawMap[128+z][128+x]=0;
- }
- void CTerrain::RendTerrain()
- {
- glEnable(GL_DEPTH_TEST);
- for(int x=m_cHmap.m_rect.minx;x<m_cHmap.m_rect.maxx; x++)
- {
- for(int z= m_cHmap.m_rect.minz;z<m_cHmap.m_rect.maxz; z++)
- RenderTerrainTile( x, z);
- }
- }
- void CTerrain::RenderTerrainTile(int x,int z)
- {
- int level=LODmap[z][x];
- if(level==0)return;
- /*
- if(level==7)
- {
- DrawLevel_7(x-128,z-128);
- return;
- }*/
- if(DrawMap[z][x]>0 )
- {
- if(level==7 )
- DrawLevel_7(x-128,z-128);
- else if(level==6 )
- DrawLevel_6(x-128,z-128);
- else if(level==5 )
- DrawLevel_5(x-128,z-128);
- else if(level==4)
- DrawLevel_4(x-128,z-128);
- else if(level==3)
- DrawLevel_3(x-128,z-128);
- else if(level==2)
- DrawLevel_2(x-128,z-128);
- else if(level==1)
- DrawLevel_1(x-128,z-128);
- }
- else
- {
- int step=1;
- if(LODmap[z][x]>5)step=2;
- if(DrawMap[z][x+step]>0)
- LevelChoose(level,x,z);
- else if(DrawMap[z+step][x]>0)
- LevelChoose(level,x,z);
- else if(DrawMap[z-step][x]>0)
- LevelChoose(level,x,z);
- else if(DrawMap[z][x-step]>0)
- LevelChoose(level,x,z);
- }
- }
- void CTerrain::LevelChoose(int level,int x,int z)
- {
- if(level==7 )
- DrawLevel_7(x-128,z-128);
- else if(level==6 )
- DrawLevel_6(x-128,z-128);
- else if(level==5 )
- DrawLevel_5(x-128,z-128);
- else if(level==4)
- DrawLevel_4(x-128,z-128);
- else if(level==3)
- DrawLevel_3(x-128,z-128);
- else if(level==2)
- DrawLevel_2(x-128,z-128);
- else if(level==1)
- DrawLevel_1(x-128,z-128);
- }
- void CTerrain::DrawLevel_1(int x,int z)
- {
- int rx=x*4;
- int rz=z*4;
- int base0=GetPos(x+128,z+128);
- // int base1=GetPos(x+128-1,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
- int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
- int base3=GetPos(x+128+1,z+128+1);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
- int base4=GetPos(x+128+1,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
- int base5=GetPos(x+128,z-1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
- float ax,az,bx,bz,cx,cz,dx,dz,ex,ez,fx,fz,gx,gz,hx,hz;
- ////////////////////////////
- glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
- glEnable(GL_TEXTURE_2D);
- ////////////Get Texture Order////////////////
- switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
- {
- case 0:
- ax=0; az=0; bx=1;bz=0; cx=1;cz=1; dx=0; dz=1; break;
- case 1:
- ax=1; az=0; bx=1;bz=1; cx=0;cz=1; dx=0; dz=0; break;
- case 2:
- ax=1; az=1; bx=0;bz=1; cx=0;cz=0; dx=1; dz=0; break;
- case 3:
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- default :
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- }
- ex=(ax+bx)*0.5f; ez=(az+bz)*0.5f;
- fx=(bx+cx)*0.5f; fz=(bz+cz)*0.5f;
- gx=(cx+dx)*0.5f; gz=(cz+dz)*0.5f;
- hx=(dx+ax)*0.5f; hz=(dz+az)*0.5f;
- ///////////////////////////////////
- //////////////////Left_up
- ///////////////////////////////////
- glBegin(GL_TRIANGLE_FAN);
- //6
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+1]]);
- glTexCoord2f((dx+0.5f)*0.5f,(dz+0.5f)*0.5f);
- glVertex3f(float((rx+1)*10)+offsetx, float(m_cHmap.m_pTmap[base0+256+1] ), float((rz+1)*10+offsetz));
- //0
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
- //5
- if(LODmap[128+z][128+x-1]==1)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256]]);
- glTexCoord2f((dx+hx)*0.5f,(dz+hz)*0.5f);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0+256] ), float(rz+1)*10+offsetz);
- }
- //10
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
- glTexCoord2f(hx,hz);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+offsetz);
- //11
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+1]]);
- glTexCoord2f((hx+0.5f)*0.5f,(hz+0.5f)*0.5f);
- glVertex3f(float((rx+1)*10)+offsetx, float(m_cHmap.m_pTmap[base0+512+1] ), float(rz+2)*10+offsetz);
- //12
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
- //7
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+2]]);
- glTexCoord2f((gx+0.5f)*0.5f,(gz+0.5f)*0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base0+256+2] ), float(rz+1)*10+offsetz);
- //2
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
- glTexCoord2f(gx,gz);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
- //1
- if(LODmap[128+z-1][128+x]==1)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+1]]);
- glTexCoord2f((gx+dx)*0.5f,(gz+dz)*0.5f);
- glVertex3f(float((rx+1)*10)+offsetx, float(m_cHmap.m_pTmap[base0+1] ), float(rz)*10+offsetz);
- }
- //0
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
- glEnd();
- ///////////////////////////////////
- //////////////////Left_down
- ///////////////////////////////////
- glBegin(GL_TRIANGLE_FAN);
- //16
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+1]]);
- glTexCoord2f((ax+0.5f)*0.5f,(az+0.5f)*0.5f);
- glVertex3f(float((rx+1)*10)+offsetx, float(m_cHmap.m_pTmap[base0+768+1] ), float((rz+3)*10+offsetz));
- //10
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
- glTexCoord2f(hx,hz);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+offsetz);
- //15
- if(LODmap[128+z][128+x-1]==1)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768]]);
- glTexCoord2f((ax+hx)*0.5f,(az+hz)*0.5f);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0+768] ), float(rz+3)*10+offsetz);
- }
- //20
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
- glTexCoord2f(ax,az);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+offsetz);
- //21
- if(LODmap[128+z+1][128+x]==1)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+1]]);
- glTexCoord2f((ax+ex)*0.5f,(az+ez)*0.5f);
- glVertex3f(float((rx+1)*10)+offsetx, float(m_cHmap.m_pTmap[base2+1] ), float(rz+4)*10+offsetz);
- }
- //22
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
- glTexCoord2f(ex,ez);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
- //17
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+2]]);
- glTexCoord2f((ex+0.5f)*0.5f,(ez+0.5f)*0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base0+768+2] ), float(rz+3)*10+offsetz);
-
- //12
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
- //11
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+1]]);
- glTexCoord2f((hx+0.5f)*0.5f,(hz+0.5f)*0.5f);
- glVertex3f(float((rx+1)*10)+offsetx, float(m_cHmap.m_pTmap[base0+512+1] ), float(rz+2)*10+offsetz);
- //10
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
- glTexCoord2f(hx,hz);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+offsetz);
- glEnd();
- ///////////////////////////////////
- //////////////////right_up
- ///////////////////////////////////
- glBegin(GL_TRIANGLE_FAN);
- //8
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+3]]);
- glTexCoord2f((cx+0.5f)*0.5f,(cz+0.5f)*0.5f);
- glVertex3f(float((rx+3)*10)+offsetx, float(m_cHmap.m_pTmap[base0+256+3] ), float((rz+1)*10+offsetz));
- //2
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
- glTexCoord2f(gx,gz);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
- //7
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+2]]);
- glTexCoord2f((gx+0.5f)*0.5f,(gz+0.5f)*0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base0+256+2] ), float(rz+1)*10+offsetz);
-
- //12
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
- //13
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+3]]);
- glTexCoord2f((fx+0.5f)*0.5f,(fz+0.5f)*0.5f);
- glVertex3f(float((rx+3)*10)+offsetx, float(m_cHmap.m_pTmap[base0+512+3] ), float(rz+2)*10+offsetz);
- //14
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
- glTexCoord2f(fx,fz);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
- //9
- if(LODmap[128+z][128+x+1]==1)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+256]]);
- glTexCoord2f((fx+cx)*0.5f,(fz+cz)*0.5f);
- glVertex3f(float(rx+4)*10+offsetx, float(m_cHmap.m_pTmap[base4+256]), float(rz+1)*10+offsetz);
- }
- //4
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
- glTexCoord2f(cx,cz);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
- //3
- if(LODmap[128+z-1][128+x]==1)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+3]]);
- glTexCoord2f((gx+cx)*0.5f,(gz+cz)*0.5f);
- glVertex3f(float((rx+3)*10)+offsetx, float(m_cHmap.m_pTmap[base0+3] ), float(rz)*10+offsetz);
- }
- //2
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
- glTexCoord2f(gx,gz);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
- glEnd();
- ///////////////////////////////////
- //////////////////right_down
- ///////////////////////////////////
- glBegin(GL_TRIANGLE_FAN);
- //18
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+3]]);
- glTexCoord2f((bx+0.5f)*0.5f,(bz+0.5f)*0.5f);
- glVertex3f(float((rx+3)*10)+offsetx, float(m_cHmap.m_pTmap[base0+768+3] ), float((rz+3)*10+offsetz));
- //12
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
- //17
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+2]]);
- glTexCoord2f((ex+0.5f)*0.5f,(ez+0.5f)*0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base0+768+2] ), float(rz+3)*10+offsetz);
-
- //22
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
- glTexCoord2f(ex,ez);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
- //23
- if(LODmap[128+z+1][128+x]==1)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+3]]);
- glTexCoord2f((ex+bx)*0.5f,(ez+bz)*0.5f);
- glVertex3f(float(rx+3)*10+offsetx, float(m_cHmap.m_pTmap[base2+3]), float(rz+4)*10+offsetz);
- }
- //24
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
- glTexCoord2f(bx,bz);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+offsetz);
-
- //19
- if(LODmap[128+z][128+x+1]==1)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+768]]);
- glTexCoord2f((bx+fx)*0.5f,(bz+fz)*0.5f);
- glVertex3f(float(rx+4)*10+offsetx, float(m_cHmap.m_pTmap[base4+768]), float(rz+3)*10+offsetz);
- }
- //14
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
- glTexCoord2f(fx,fz);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
-
- //13
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+3]]);
- glTexCoord2f((fx+0.5f)*0.5f,(fz+0.5f)*0.5f);
- glVertex3f(float((rx+3)*10)+offsetx, float(m_cHmap.m_pTmap[base0+512+3] ), float(rz+2)*10+offsetz);
- //12
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
- glEnd();
- numTriangles+=32;
- }
- void CTerrain::DrawLevel_2(int x,int z)
- {
- int rx=x*4;
- int rz=z*4;
- int base0=GetPos(x+128,z+128);
- // int base1=GetPos(x+128-1,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
- int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
- int base3=GetPos(x+128+1,z+128+1);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
- int base4=GetPos(x+128+1,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
- int base5=GetPos(x+128,z-1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
- float ax,az,bx,bz,cx,cz,dx,dz,ex,ez,fx,fz,gx,gz,hx,hz;
- ////////////////////////////
- glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
- glEnable(GL_TEXTURE_2D);
- ////////////Get Texture Order////////////////
- switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
- {
- case 0:
- ax=0; az=0; bx=1;bz=0; cx=1;cz=1; dx=0; dz=1; break;
- case 1:
- ax=1; az=0; bx=1;bz=1; cx=0;cz=1; dx=0; dz=0; break;
- case 2:
- ax=1; az=1; bx=0;bz=1; cx=0;cz=0; dx=1; dz=0; break;
- case 3:
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- default :
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- }
- ex=(ax+bx)*0.5f; ez=(az+bz)*0.5f;
- fx=(bx+cx)*0.5f; fz=(bz+cz)*0.5f;
- gx=(cx+dx)*0.5f; gz=(cz+dz)*0.5f;
- hx=(dx+ax)*0.5f; hz=(dz+az)*0.5f;
- ///////////////////////////////////
- //////////////////Left_up
- ///////////////////////////////////
- glBegin(GL_TRIANGLE_FAN);
- //6
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+1]]);
- glTexCoord2f((dx+0.5f)*0.5f,(dz+0.5f)*0.5f);
- glVertex3f(float((rx+1)*10)+offsetx, float(m_cHmap.m_pTmap[base0+256+1] ), float((rz+1)*10+offsetz));
- //0
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
- //10
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
- glTexCoord2f(hx,hz);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+offsetz);
- //12
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
- //2
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
- glTexCoord2f(gx,gz);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
- //0
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
- glEnd();
- ///////////////////////////////////
- //////////////////Left_down
- ///////////////////////////////////
- glBegin(GL_TRIANGLE_FAN);
- //16
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+1]]);
- glTexCoord2f((ax+0.5f)*0.5f,(az+0.5f)*0.5f);
- glVertex3f(float((rx+1)*10)+offsetx, float(m_cHmap.m_pTmap[base0+768+1] ), float((rz+3)*10+offsetz));
- //10
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
- glTexCoord2f(hx,hz);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+offsetz);
- //20
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
- glTexCoord2f(ax,az);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+offsetz);
- //21
- //22
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
- glTexCoord2f(ex,ez);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
-
- //12
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
- //10
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
- glTexCoord2f(hx,hz);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base0+512]), float(rz+2)*10+offsetz);
- glEnd();
- ///////////////////////////////////
- //////////////////right_up
- ///////////////////////////////////
- glBegin(GL_TRIANGLE_FAN);
- //8
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+256+3]]);
- glTexCoord2f((cx+0.5f)*0.5f,(cz+0.5f)*0.5f);
- glVertex3f(float((rx+3)*10)+offsetx, float(m_cHmap.m_pTmap[base0+256+3] ), float((rz+1)*10+offsetz));
- //2
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
- glTexCoord2f(gx,gz);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
-
- //12
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
- //14
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
- glTexCoord2f(fx,fz);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
- //4
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
- glTexCoord2f(cx,cz);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
- //2
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
- glTexCoord2f(gx,gz);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
- glEnd();
- ///////////////////////////////////
- //////////////////right_down
- ///////////////////////////////////
- glBegin(GL_TRIANGLE_FAN);
- //18
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+768+3]]);
- glTexCoord2f((bx+0.5f)*0.5f,(bz+0.5f)*0.5f);
- glVertex3f(float((rx+3)*10)+offsetx, float(m_cHmap.m_pTmap[base0+768+3] ), float((rz+3)*10+offsetz));
- //12
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
- //22
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
- glTexCoord2f(ex,ez);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
- //24
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
- glTexCoord2f(bx,bz);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+offsetz);
- //14
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
- glTexCoord2f(fx,fz);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
- //12
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float(rx+2)*10+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float(rz+2)*10+offsetz);
- glEnd();
- numTriangles+=16;
- }
- void CTerrain::DrawLevel_3(int x,int z)
- {
- int rx=x*4;
- int rz=z*4;
- int base0=GetPos(x+128,z+128);
- // int base1=GetPos(x-1+128,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
- int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
- int base3=GetPos(x+1+128,z+1+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
- int base4=GetPos(x+1+128,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
- int base5=GetPos(x+128,z-1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
- float ax,az,bx,bz,cx,cz,dx,dz;
- ////////////////////////////
- glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
- glEnable(GL_TEXTURE_2D);
- ////////////Get Texture Order////////////////
- switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
- {
- case 0:
- ax=0; az=0; bx=1;bz=0; cx=1;cz=1; dx=0; dz=1; break;
- case 1:
- ax=1; az=0; bx=1;bz=1; cx=0;cz=1; dx=0; dz=0; break;
- case 2:
- ax=1; az=1; bx=0;bz=1; cx=0;cz=0; dx=1; dz=0; break;
- case 3:
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- default :
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- }
- glBegin(GL_TRIANGLE_FAN);
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float((rz+2)*10+offsetz));
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base0+256]]);
- glTexCoord2f((ax+dx)*0.5f,(az+dz)*0.5f);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0+512] ), float(rz+2)*10+offsetz);
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
- glTexCoord2f(ax,az);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
- glTexCoord2f((ax+bx)*0.5f,(az+bz)*0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
- glTexCoord2f(bx,bz);
- glVertex3f(float(rx+4)*10+offsetx, float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4+256]]);
- glTexCoord2f((cx+bx)*0.5f,(cz+bz)*0.5f);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
- glTexCoord2f(cx,cz);
- glVertex3f(float(rx+4)*10+offsetx, float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
- glTexCoord2f((cx+dx)*0.5f,(cz+dz)*0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
- glEnd();
- /////////////////////////blend
- /*
- glBindTexture(GL_TEXTURE_2D, Detail[0]);
- glEnable(GL_TEXTURE_2D);
- // glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_COLOR);
- glBlendFunc(GL_DST_COLOR,GL_SRC_COLOR);
- glEnable(GL_BLEND);
- glBegin(GL_TRIANGLE_FAN);
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float((rz+2)*10+offsetz));
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base0+256]]);
- glTexCoord2f((ax+dx)*0.5f,(az+dz)*0.5f);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0+512] ), float(rz+2)*10+offsetz);
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
- glTexCoord2f(ax,az);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
- glTexCoord2f((ax+bx)*0.5f,(az+bz)*0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
- glTexCoord2f(bx,bz);
- glVertex3f(float(rx+4)*10+offsetx, float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4+256]]);
- glTexCoord2f((cx+bx)*0.5f,(cz+bz)*0.5f);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
- glTexCoord2f(cx,cz);
- glVertex3f(float(rx+4)*10+offsetx, float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
- glTexCoord2f((cx+dx)*0.5f,(cz+dz)*0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
- glEnd();
- */
- glDisable(GL_BLEND);
- numTriangles+=8;
- }
- void CTerrain::DrawLevel_4(int x,int z)
- {
- int rx=x*4;
- int rz=z*4;
- int base0=GetPos(x+128,z+128);
- // int base1=GetPos(x-1+128,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
- int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
- int base3=GetPos(x+1+128,z+1+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
- int base4=GetPos(x+1+128,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
- // int base5=GetPos(x+128,z-1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
- float ax,az,bx,bz,cx,cz,dx,dz;
- ////////////////////////////
- glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
- glEnable(GL_TEXTURE_2D);
- ////////////Get Texture Order////////////////
- switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
- {
- case 0:
- ax=0; az=0; bx=1;bz=0; cx=1;cz=1; dx=0; dz=1; break;
- case 1:
- ax=1; az=0; bx=1;bz=1; cx=0;cz=1; dx=0; dz=0; break;
- case 2:
- ax=1; az=1; bx=0;bz=1; cx=0;cz=0; dx=1; dz=0; break;
- case 3:
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- default :
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- }
- glBegin(GL_TRIANGLE_FAN);
- //12
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512+2]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base0+512+2] ), float((rz+2)*10+offsetz));
- //0
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
- //10
- if(LODmap[128+z][128+x-1]<4)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+512]]);
- glTexCoord2f((ax+dx)*0.5f,(az+dz)*0.5f);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0+512] ), float(rz+2)*10+offsetz);
- }
- //20
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
- glTexCoord2f(ax,az);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+offsetz);
- //22
- if(LODmap[128+z+1][128+x]<4)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2+2]]);
- glTexCoord2f((ax+bx)*0.5f,(az+bz)*0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base2+2] ), float(rz+4)*10+offsetz);
- }
- //24
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
- glTexCoord2f(bx,bz);
- glVertex3f(float(rx+4)*10+offsetx, float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+offsetz);
- //14
- if(LODmap[128+z][128+x+1]<4)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4+512]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4+256]]);
- glTexCoord2f((cx+bx)*0.5f,(cz+bz)*0.5f);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base4+512] ), float(rz+2)*10+offsetz);
- }
- //4
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
- glTexCoord2f(cx,cz);
- glVertex3f(float(rx+4)*10+offsetx, float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
- //2
- if(LODmap[128+z-1][128+x]<4)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0+2]]);
- glTexCoord2f((cx+dx)*0.5f,(cz+dz)*0.5f);
- glVertex3f(float((rx+2)*10)+offsetx, float(m_cHmap.m_pTmap[base0+2] ), float(rz)*10+offsetz);
- }
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
- glEnd();
- numTriangles+=4;
- }
- void CTerrain::DrawLevel_5(int x,int z)
- {
- int rx=x*4;
- int rz=z*4;
- int base0=GetPos(x+128,z+128);
- // int base1=GetPos(x-1+128,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
- int base2=GetPos(x+128,z+1+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
- int base3=GetPos(x+1+128,z+1+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
- int base4=GetPos(x+1+128,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
- float ax,az,bx,bz,cx,cz,dx,dz;
- ////////////////////////////
- glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
- glEnable(GL_TEXTURE_2D);
- ////////////Get Texture Order////////////////
- switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
- {
- case 0:
- ax=0; az=0; bx=1;bz=0; cx=1;cz=1; dx=0; dz=1; break;
- case 1:
- ax=1; az=0; bx=1;bz=1; cx=0;cz=1; dx=0; dz=0; break;
- case 2:
- ax=1; az=1; bx=0;bz=1; cx=0;cz=0; dx=1; dz=0; break;
- case 3:
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- default :
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- }
- glBegin(GL_TRIANGLE_FAN);
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base2]]);
- glTexCoord2f(ax,az);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base2]), float(rz+4)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base3]]);
- glTexCoord2f(bx,bz);
- glVertex3f(float(rx+4)*10+offsetx, float(m_cHmap.m_pTmap[base3] ), float(rz+4)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4]]);
- glTexCoord2f(cx,cz);
- glVertex3f(float(rx+4)*10+offsetx, float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
- glEnd();
- numTriangles+=2;
- }
- void CTerrain::DrawLevel_6(int x,int z)
- {
- int rx=x*4;
- int rz=z*4;
- int base0=GetPos(x+128,z+128);
- int base1=GetPos(x+128,z+2+128);
- int base2=GetPos(x+2+128,z+2+128);
- int base3=GetPos(x+2+128,z+128);
- int base4=GetPos(x+1+128,z+1+128);
- int base5=GetPos(x+128,z+1+128);
- int base6=GetPos(x+1+128,z+2+128);
- int base7=GetPos(x+2+128,z+1+128);
- int base8=GetPos(x+1+128,z+128);
- float ax,az,bx,bz,cx,cz,dx,dz;
- ////////////////////////////
- glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
- glEnable(GL_TEXTURE_2D);
- ////////////Get Texture Order////////////////
- switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
- {
- case 0:
- ax=0; az=0; bx=1;bz=0; cx=1;cz=1; dx=0; dz=1; break;
- case 1:
- ax=1; az=0; bx=1;bz=1; cx=0;cz=1; dx=0; dz=0; break;
- case 2:
- ax=1; az=1; bx=0;bz=1; cx=0;cz=0; dx=1; dz=0; break;
- case 3:
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- default :
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- }
- glBegin(GL_TRIANGLE_FAN);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
- glTexCoord2f(0.5f,0.5f);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base4] ), float((rz+4)*10+offsetz));
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
-
- if(LODmap[128+z][128+x-2]!=7)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base5]]);
- glTexCoord2f((ax+dx)*0.5f,(az+dz)*0.5f);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base5] ), float(rz+4)*10+offsetz);
- }
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base1]]);
- glTexCoord2f(ax,az);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base1]), float(rz+8)*10+offsetz);
- if(LODmap[128+z+2][128+x]!=7)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base6]]);
- glTexCoord2f((ax+bx)*0.5f,(az+bz)*0.5f);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base6] ), float(rz+8)*10+offsetz);
- }
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
- glTexCoord2f(bx,bz);
- glVertex3f(float(rx+8)*10+offsetx, float(m_cHmap.m_pTmap[base2] ), float(rz+8)*10+offsetz);
-
- if(LODmap[128+z][128+x+2]!=7)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base7]]);
- glTexCoord2f((cx+bx)*0.5f,(cz+bz)*0.5f);
- glVertex3f(float((rx+8)*10)+offsetx, float(m_cHmap.m_pTmap[base7] ), float(rz+4)*10+offsetz);
- }
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
- glTexCoord2f(cx,cz);
- glVertex3f(float(rx+8)*10+offsetx, float(m_cHmap.m_pTmap[base3] ), float(rz)*10+offsetz);
- //2
- if(LODmap[128+z-2][128+x]!=7)
- {
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base8]]);
- glTexCoord2f((cx+dx)*0.5f,(cz+dz)*0.5f);
- glVertex3f(float((rx+4)*10)+offsetx, float(m_cHmap.m_pTmap[base8] ), float(rz)*10+offsetz);
- }
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
- glEnd();
- numTriangles+=4;
- }
- void CTerrain::DrawLevel_7(int x,int z)
- {
- int rx=x*4;
- int rz=z*4;
- int base0=GetPos(x+128,z+128);
- // int base1=GetPos(x-1+128,z+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x-1];
- int base2=GetPos(x+128,z+2+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x];
- int base3=GetPos(x+2+128,z+2+128);//m_cHmap.m_pMovemap[(128+z)*256+128+x+1];
- int base4=GetPos(x+2+128,z+128);//m_cHmap.m_pMovemap[(128+z+1)*256+128+x+1];
- float ax,az,bx,bz,cx,cz,dx,dz;
- ////////////////////////////
- glBindTexture(GL_TEXTURE_2D, Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureIndex);
- glEnable(GL_TEXTURE_2D);
- ////////////Get Texture Order////////////////
- switch(Skinmap[GetZpos(x,z)/4][GetXpos(x,z)/4].TextureOrder)
- {
- case 0:
- ax=0; az=0; bx=1;bz=0; cx=1;cz=1; dx=0; dz=1; break;
- case 1:
- ax=1; az=0; bx=1;bz=1; cx=0;cz=1; dx=0; dz=0; break;
- case 2:
- ax=1; az=1; bx=0;bz=1; cx=0;cz=0; dx=1; dz=0; break;
- case 3:
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- default :
- ax=0; az=1; bx=0;bz=0; cx=1;cz=0; dx=1; dz=1; break;
- }
- glBegin(GL_TRIANGLE_FAN);
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base0]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base0]]);
- glTexCoord2f(dx,dz);
- glVertex3f(float(rx*10)+offsetx, float(m_cHmap.m_pTmap[base0] ), float(rz)*10+offsetz);
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base2]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base2]]);
- glTexCoord2f(ax,az);
- glVertex3f(float(rx)*10+offsetx, float(m_cHmap.m_pTmap[base2]), float(rz+8)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base3]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base3]]);
- glTexCoord2f(bx,bz);
- glVertex3f(float(rx+8)*10+offsetx, float(m_cHmap.m_pTmap[base3] ), float(rz+8)*10+offsetz);
-
- glNormal3fv(cNormal.m_3dENormal[NormalIndex[base4]]);
- //glColor3fv(cNormal.m_3dEColor[ColorIndex[base4]]);
- glTexCoord2f(cx,cz);
- glVertex3f(float(rx+8)*10+offsetx, float(m_cHmap.m_pTmap[base4] ), float(rz)*10+offsetz);
- glEnd();
- numTriangles+=2;
- }
- int CTerrain::GetPos(int x,int z)
- {
- return m_cHmap.m_pMovemap[(z)*256+x].zpos*256+m_cHmap.m_pMovemap[(z)*256+x].xpos;
- }
- int CTerrain::GetXpos(int x,int z)
- {
- return m_cHmap.m_pMovemap[(128+z)*256+128+x].xpos;
- }
- int CTerrain::GetZpos(int x,int z)
- {
- return m_cHmap.m_pMovemap[(128+z)*256+128+x].zpos;
- }
- CTerrain::~CTerrain()
- {
- for(int i=0;i<4;i++)
- glDeleteTextures(1,&Blend[i]);
- for(i=0;i<5;i++)
- {
- glDeleteTextures(1,&BaseA[i]);
- glDeleteTextures(1,&BaseB[i]);
- }
- }
- int CTerrain::GetNumTriangles()
- {
- return numTriangles;
- }