Plant.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:18k
- // Plant.cpp: implementation of the CPlant class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Texture.h"
- #include "Plant.h"
- #include "math.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CPlant::CPlant()
- {
- m_szTree=0.2f;
- m_height=m_szTree*60;
- m_szBush=10;
- m_szTreeB=10;
- m_szGrass=6;
- m_szVine=30;
- m_szStone=5;
- }
- CPlant::~CPlant()
- {
- /* for(int i=0;i<4;i++)
- {
- glDeleteTextures(1,&Trees[i]);
- }
- */
- }
- bool CPlant::LoadPlantPicture()
- {
- /*
- CTexture cTex;
- //////////////read blend skin texture
- int i=0;
- char filename[64];
- char Alphaname[64];
- for(i=0;i<2;i++)
- {
- wsprintf(filename,"Plants/treeBody%d.bmp",i+1);
- if(!cTex.MakeTextureBind(filename,&texTreeBody[i]))
- {
- MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
- return false;
- }
- }
- for(i=0;i<1;i++)
- {
- wsprintf(filename,"Plants/stone.bmp");
- if(!cTex.MakeTextureBind(filename,&texStone[i]))
- {
- MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
- return false;
- }
- }
- for(i=0;i<4;i++)
- {
- wsprintf(filename,"Plants/grass%d.bmp",i+1);
- wsprintf(Alphaname,"Plants/grassAlpha%d.bmp",i+1);
- if(!cTex.MakeAlphaTextureBind(filename,Alphaname,&texGrass[i]))
- {
- MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
- return false;
- }
- }
- for(i=0;i<4;i++)
- {
- wsprintf(filename,"Plants/bush%d.bmp",i+1);
- wsprintf(Alphaname,"Plants/bushAlpha%d.bmp",i+1);
- if(!cTex.MakeAlphaTextureBind(filename,Alphaname,&texBush[i]))
- {
- MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
- return false;
- }
- }
- for(i=0;i<5;i++)
- {
- wsprintf(filename,"Plants/branch%d.bmp",i+1);
- wsprintf(Alphaname,"Plants/branchAlpha%d.bmp",i+1);
- if(!cTex.MakeAlphaTextureBind(filename,Alphaname,&texBranch[i]))
- {
- MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
- return false;
- }
- }
- for(i=0;i<2;i++)
- {
- wsprintf(filename,"Plants/vine%d.bmp",i+1);
- wsprintf(Alphaname,"Plants/vineAlpha%d.bmp",i+1);
- if(!cTex.MakeAlphaTextureBind(filename,Alphaname,&texVine[i]))
- {
- MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
- return false;
- }
- }*/
- return true;
- }
- bool CPlant::InitPlant()
- {
- if(!LoadPlantPicture())return false;
- return true;
- }
- void CPlant::DrawTree()
- {
-
- ///////////////////////////////////
- //////////Draw Tree Body
- glDisable(GL_ALPHA_TEST);
- glDisable(GL_BLEND);
- glBindTexture(GL_TEXTURE_2D, texTreeBody[1]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUAD_STRIP);
- for(float i=0;i<8;i++)
- {
- glTexCoord2i(int(i+1)%2,0);
- glVertex3f(-m_szTree*sinf(i*45*0.0174533f),0,-m_szTree*cosf(i*45*0.0174533f));
- glTexCoord2i(int(i+1)%2,50);
- glVertex3f(-m_szTree*sinf(i*45*0.0174533f)*0.1f,m_height,-m_szTree*cosf(i*45*0.0174533f)*0.1f);
- }
- glTexCoord2f(1,0);
- glVertex3f(0,0,-m_szTree);
- glTexCoord2f(1,50);
- glVertex3f(0,m_height,-m_szTree*0.1f);
- glEnd();
- glEnable(GL_ALPHA_TEST);
- glEnable(GL_BLEND);
- //////////////////////////////////////////
- ///////////////// Draw Branch ////////////
- glBindTexture(GL_TEXTURE_2D, texBranch[1]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
- for( i=0;i<8;i++)
- {
- glTexCoord2f(0,0);
- glVertex3f(-m_szTree*20*sinf(i*45*0.0174533f),m_height*0.4f,-m_szTree*20*cosf(i*45*0.0174533f));
- glTexCoord2f(1,0);
- glVertex3f(0,m_height*0.4f,0);
- glTexCoord2f(1,1);
- glVertex3f(0,m_height*0.65f,0);
- glTexCoord2f(0,1);
- glVertex3f(-m_szTree*20*sinf(i*45*0.0174533f),m_height*0.65f,-m_szTree*20*cosf(i*45*0.0174533f));
- }
- glEnd();
- glBindTexture(GL_TEXTURE_2D, texBranch[3]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
- for( i=0.2f;i<6.2f;i++)
- {
- glTexCoord2f(0,0);
- glVertex3f(-m_szTree*15*sinf(i*60*0.0174533f),m_height*0.6f,-m_szTree*15*cosf(i*60*0.0174533f));
- glTexCoord2f(1,0);
- glVertex3f(0,m_height*0.6f,0);
- glTexCoord2f(1,1);
- glVertex3f(0,m_height*0.8f,0);
- glTexCoord2f(0,1);
- glVertex3f(-m_szTree*15*sinf(i*60*0.0174533f),m_height*0.8f,-m_szTree*15*cosf(i*60*0.0174533f));
- }
- glEnd();
- glBindTexture(GL_TEXTURE_2D, texBranch[4]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
- for( i=0.2f;i<4.2f;i++)
- {
- glTexCoord2f(0,0);
- glVertex3f(-m_szTree*10*sinf(i*90*0.0174533f),m_height*0.75f,-m_szTree*10*cosf(i*90*0.0174533f));
- glTexCoord2f(1,0);
- glVertex3f(0,m_height*0.75f,0);
- glTexCoord2f(1,1);
- glVertex3f(0,m_height*0.95f,0);
- glTexCoord2f(0,1);
- glVertex3f(-m_szTree*10*sinf(i*90*0.0174533f),m_height*0.95f,-m_szTree*10*cosf(i*90*0.0174533f));
- }
- glEnd();
-
- }
- void CPlant::DrawTreeB()
- {
-
- //////////////////////////////////////////
- ///////////////// Draw Branch ////////////
- glBindTexture(GL_TEXTURE_2D, texBranch[2]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
- for(float i=0;i<3;i++)
- {
- glTexCoord2f(0,0);
- glVertex3f(-m_szTreeB*sinf(i*60*0.0174533f ),0,-m_szTreeB*cosf(i*60*0.0174533f ));
- glTexCoord2f(1,0);
- glVertex3f(m_szTreeB*sinf(i*60*0.0174533f ),0,m_szTreeB*cosf(i*60*0.0174533f ));
- glTexCoord2f(1,1);
- glVertex3f(m_szTreeB*sinf(i*60*0.0174533f ),m_szTreeB*(2+float(i)/6),m_szTreeB*cosf(i*60*0.0174533f ));
- glTexCoord2f(0,1);
- glVertex3f(-m_szTree*sinf(i*60*0.0174533f ),m_szTreeB*(2+float(i)/6),-m_szTree*cosf(i*60*0.0174533f ));
- }
- for( i=0.5f;i<3.5f;i++)
- {
- glTexCoord2f(1,0);
- glVertex3f(-m_szTreeB*sinf(i*60*0.0174533f ),0,-m_szTreeB*cosf(i*60*0.0174533f ));
- glTexCoord2f(0,0);
- glVertex3f(m_szTreeB*sinf(i*60*0.0174533f ),0,m_szTreeB*cosf(i*60*0.0174533f ));
- glTexCoord2f(0,1);
- glVertex3f(m_szTreeB*sinf(i*60*0.0174533f ),m_szTreeB*(2+float(i)/6),m_szTreeB*cosf(i*60*0.0174533f ));
- glTexCoord2f(1,1);
- glVertex3f(-m_szTree*sinf(i*60*0.0174533f ),m_szTreeB*(2+float(i)/6),-m_szTree*cosf(i*60*0.0174533f ));
- }
- glEnd();
- }
- void CPlant::DrawGrass()
- {
- /////////////Round type
- glBindTexture(GL_TEXTURE_2D, texGrass[2]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUAD_STRIP);
- for(float i=0;i<6;i++)
- {
- glTexCoord2i(int(i+1)%2,0);
- glVertex3f(-m_szGrass*sinf(i*60*0.0174533f )*0.8f,0,-m_szGrass*cosf(i*60*0.0174533f )*0.8f);
- glTexCoord2i(int(i+1)%2,1);
- glVertex3f(-m_szGrass*sinf(i*60*0.0174533f ),m_szGrass,-m_szGrass*cosf(i*60*0.0174533f ));
- }
- glTexCoord2f(1,0);
- glVertex3f(0,0,-m_szGrass*0.8f);
- glTexCoord2f(1,1);
- glVertex3f(0,m_szGrass,-m_szGrass);
- glTexCoord2f(0,0);
- glVertex3f(0,0,m_szGrass*0.8f);
- glTexCoord2f(0,1);
- glVertex3f(0,m_szGrass,m_szGrass);
- glEnd();
- }
- void CPlant::DrawVine()
- {
- /////////////vine type
- glEnable(GL_ALPHA_TEST);
- glBindTexture(GL_TEXTURE_2D, texVine[0]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
- for(float i=0;i<8;i++)
- {
- glTexCoord2f(0,0);
- glVertex3f(-m_szTree*10*sinf(i*45*0.0174533f ),0,-m_szTree*10*cosf(i*45*0.0174533f ));
- glTexCoord2f(1,0);
- glVertex3f(0,0,0);
- glTexCoord2f(1,1);
- glVertex3f(0,m_szTree*10,0);
- glTexCoord2f(0,1);
- glVertex3f(-m_szTree*10*sinf(i*45*0.0174533f ),m_szTree*10,-m_szTree*10*cosf(i*45*0.0174533f ));
- }
- glEnd();
- glBindTexture(GL_TEXTURE_2D, texVine[1]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
- for( i=0.5f;i<6.25f;i++)
- {
- glTexCoord2f(0,0);
- glVertex3f(-m_szTree*6*sinf(i*60*0.0174533f ),0,-m_szTree*6*cosf(i*60*0.0174533f ));
- glTexCoord2f(1,0);
- glVertex3f(0,0,0);
- glTexCoord2f(1,1);
- glVertex3f(0,m_szTree*6,0);
- glTexCoord2f(0,1);
- glVertex3f(-m_szTree*6*sinf(i*60*0.0174533f ),m_szTree*6,-m_szTree*6*cosf(i*60*0.0174533f ));
- }
- glEnd();
- }
- void CPlant::DrawBushA()
- {
- /////////////bush type
- glBindTexture(GL_TEXTURE_2D, texBush[0]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
-
- for(float i=0;i<6;i++)
- {
- glTexCoord2f(0.02f,0.336f);
- glVertex3f(0,0,0);
-
- glTexCoord2f(1,0.336f);
- glVertex3f(-m_szBush*sinf(i*60*0.0174533f ),0,-m_szBush*cosf(i*60*0.0174533f ));
- glTexCoord2f(1,1);
- glVertex3f(-m_szBush*sinf(i*60*0.0174533f ),m_szBush*0.6f,-m_szBush*cosf(i*60*0.0174533f ));
-
- glTexCoord2f(0.02f,1);
- glVertex3f(0,m_szBush*0.6f,0);
- }
- /////1
-
- glTexCoord2f(0,0);
- glVertex3f(-m_szBush*0.4f,0,-m_szBush*0.3f);
- glTexCoord2f(0.664f,0);
- glVertex3f(m_szBush*0.4f,0,-m_szBush*0.7f);
- glTexCoord2f(0.664f,0.336f);
- glVertex3f(m_szBush*0.4f,m_szBush*0.4f,-m_szBush*0.7f);
- glTexCoord2f(0,0.336f);
- glVertex3f(-m_szBush*0.4f,m_szBush*0.4f,-m_szBush*0.3f);
- ////////2
-
- glTexCoord2f(0,0);
- glVertex3f(-m_szBush*0.3f,0,m_szBush*0.1f);
- glTexCoord2f(0.664f,0);
- glVertex3f(-m_szBush*0.7f,0,-m_szBush*0.8f);
- glTexCoord2f(0.664f,0.336f);
- glVertex3f(-m_szBush*0.7f,m_szBush*0.4f,-m_szBush*0.8f);
- glTexCoord2f(0,0.336f);
- glVertex3f(-m_szBush*0.3f,m_szBush*0.4f,m_szBush*0.1f);
- /////////3
- glTexCoord2f(0,0);
- glVertex3f(-m_szBush*0.3f,0,m_szBush*0.8f);
- glTexCoord2f(0.664f,0);
- glVertex3f(-m_szBush*0.7f,0,-m_szBush*0.1f);
- glTexCoord2f(0.664f,0.336f);
- glVertex3f(-m_szBush*0.7f,m_szBush*0.4f,-m_szBush*0.1f);
- glTexCoord2f(0,0.336f);
- glVertex3f(-m_szBush*0.3f,m_szBush*0.4f,m_szBush*0.8f);
- ////////4
-
- glTexCoord2f(0,0);
- glVertex3f(m_szBush*0.3f,0,m_szBush*0.4f);
- glTexCoord2f(0.664f,0);
- glVertex3f(-m_szBush*0.5f,0,m_szBush*0.9f);
- glTexCoord2f(0.664f,0.336f);
- glVertex3f(-m_szBush*0.5f,m_szBush*0.4f,m_szBush*0.9f);
- glTexCoord2f(0,0.336f);
- glVertex3f(m_szBush*0.3f,m_szBush*0.4f,m_szBush*0.4f);
- ///////5
- glTexCoord2f(0,0);
- glVertex3f(m_szBush*0.3f,0,m_szBush*0.8f);
- glTexCoord2f(0.664f,0);
- glVertex3f(m_szBush*0.7f,0,m_szBush*0.1f);
- glTexCoord2f(0.664f,0.336f);
- glVertex3f(m_szBush*0.7f,m_szBush*0.4f,m_szBush*0.1f);
- glTexCoord2f(0,0.336f);
- glVertex3f(m_szBush*0.3f,m_szBush*0.4f,m_szBush*0.8f);
- ///////6
- glTexCoord2f(0,0);
- glVertex3f(m_szBush*0.2f,0,-m_szBush*0.6f);
- glTexCoord2f(0.664f,0);
- glVertex3f(m_szBush*0.8f,0,-m_szBush*0.1f);
- glTexCoord2f(0.664f,0.336f);
- glVertex3f(m_szBush*0.8f,m_szBush*0.4f,-m_szBush*0.1f);
- glTexCoord2f(0,0.336f);
- glVertex3f(m_szBush*0.2f,m_szBush*0.4f,-m_szBush*0.6f);
-
- glEnd();
- glBindTexture(GL_TEXTURE_2D, texGrass[3]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
-
- for( i=0.5;i<6.5;i++)
- {
- glTexCoord2f(0.02f,0.336f);
- glVertex3f(0,m_szBush*0.3f,0);
-
- glTexCoord2f(1,0.336f);
- glVertex3f(-m_szBush*0.9f*sinf(i*60*0.0174533f ),m_szBush*0.3f,-m_szBush*0.9f*cosf(i*60*0.0174533f ));
- glTexCoord2f(1,1);
- glVertex3f(-m_szBush*0.9f*sinf(i*60*0.0174533f ),m_szBush*0.8f,-m_szBush*0.9f*cosf(i*60*0.0174533f ));
-
- glTexCoord2f(0.02f,1);
- glVertex3f(0,m_szBush*0.8f,0);
- }
- ///////1
- glTexCoord2f(0,0);
- glVertex3f(m_szBush*0.4f,-0,-m_szBush*0.4f);
- glTexCoord2f(1,0);
- glVertex3f(-m_szBush*0.4f,0,-m_szBush*0.6f);
- glTexCoord2f(1,1);
- glVertex3f(-m_szBush*0.4f,m_szBush*0.4f,-m_szBush*0.6f);
- glTexCoord2f(0,1);
- glVertex3f(m_szBush*0.4f,m_szBush*0.4f,-m_szBush*0.4f);
- ////////2
-
- glTexCoord2f(0,0);
- glVertex3f(-m_szBush*0.3f,0,-m_szBush*0.5f);
- glTexCoord2f(1,0);
- glVertex3f(-m_szBush*0.7f,0,m_szBush*0.1f);
- glTexCoord2f(1,1);
- glVertex3f(-m_szBush*0.7f,m_szBush*0.4f,m_szBush*0.1f);
- glTexCoord2f(0,1);
- glVertex3f(-m_szBush*0.3f,m_szBush*0.4f,-m_szBush*0.5f);
-
- /////////3
- glTexCoord2f(0,0);
- glVertex3f(-m_szBush*0.6f,0,m_szBush*0.1f);
- glTexCoord2f(1,0);
- glVertex3f(m_szBush*0.1f,0,m_szBush*0.8f);
- glTexCoord2f(1,1);
- glVertex3f(m_szBush*0.1f,m_szBush*0.4f,m_szBush*0.8f);
- glTexCoord2f(0,1);
- glVertex3f(-m_szBush*0.6f,m_szBush*0.4f,m_szBush*0.1f);
- ////////4
- glTexCoord2f(0,0);
- glVertex3f(-m_szBush*0.3f,0,m_szBush*0.5f);
- glTexCoord2f(1,0);
- glVertex3f(m_szBush*0.4f,0,m_szBush*0.8f);
- glTexCoord2f(1,1);
- glVertex3f(m_szBush*0.4f,m_szBush*0.4f,m_szBush*0.8f);
- glTexCoord2f(0,1);
- glVertex3f(-m_szBush*0.3f,m_szBush*0.4f,m_szBush*0.5f);
- ///////5
- glTexCoord2f(0,0);
- glVertex3f(m_szBush*0.4f,0,m_szBush*0.7f);
- glTexCoord2f(1,0);
- glVertex3f(m_szBush*0.6f,0,-m_szBush*0.3f);
- glTexCoord2f(1,1);
- glVertex3f(m_szBush*0.6f,m_szBush*0.5f,-m_szBush*0.3f);
- glTexCoord2f(0,1);
- glVertex3f(m_szBush*0.4f,m_szBush*0.5f,m_szBush*0.7f);
- ///////6
- glTexCoord2f(0,0);
- glVertex3f(m_szBush*0.6f,0,m_szBush*0.1f);
- glTexCoord2f(1,0);
- glVertex3f(m_szBush*0.4f,0,-m_szBush*0.75f);
- glTexCoord2f(1,1);
- glVertex3f(m_szBush*0.4f,m_szBush*0.4f,-m_szBush*0.75f);
- glTexCoord2f(0,1);
- glVertex3f(m_szBush*0.6f,m_szBush*0.4f,m_szBush*0.1f);
- glEnd();
- }
- void CPlant::DrawBushB()
- {
- /////////////bush type
- glBindTexture(GL_TEXTURE_2D, texBush[2]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
-
- for(float i=0;i<6;i++)
- {
- glTexCoord2f(0.02f,0.336f);
- glVertex3f(0,0,0);
-
- glTexCoord2f(1,0.336f);
- glVertex3f(-m_szBush*0.9f*sinf(i*60*0.0174533f ),0,-m_szBush*0.9f*cosf(i*60*0.0174533f ));
- glTexCoord2f(1,1);
- glVertex3f(-m_szBush*0.9f*sinf(i*60*0.0174533f ),m_szBush*0.5f,-m_szBush*0.9f*cosf(i*60*0.0174533f ));
-
- glTexCoord2f(0.02f,1);
- glVertex3f(0,m_szBush*0.5f,0);
- }
- /////1
-
- glTexCoord2f(0,0);
- glVertex3f(-m_szBush*0.1f,0,0);
- glTexCoord2f(0.664f,0);
- glVertex3f(m_szBush*0.2f,0,-m_szBush*0.6f);
- glTexCoord2f(0.664f,0.336f);
- glVertex3f(m_szBush*0.2f,m_szBush*0.4f,-m_szBush*0.6f);
- glTexCoord2f(0,0.336f);
- glVertex3f(-m_szBush*0.1f,m_szBush*0.4f,0);
- ////////2
-
- glTexCoord2f(0,0);
- glVertex3f(-m_szBush*0.3f,0,0);
- glTexCoord2f(0.664f,0);
- glVertex3f(-m_szBush*0.8f,0,-m_szBush*0.4f);
- glTexCoord2f(0.664f,0.336f);
- glVertex3f(-m_szBush*0.8f,m_szBush*0.2f,-m_szBush*0.4f);
- glTexCoord2f(0,0.336f);
- glVertex3f(-m_szBush*0.3f,m_szBush*0.2f,0);
- /////////3
- glTexCoord2f(0,0);
- glVertex3f(0,0,m_szBush*0.3f);
- glTexCoord2f(0.664f,0);
- glVertex3f(-m_szBush*0.8f,0,m_szBush*0.1f);
- glTexCoord2f(0.664f,0.336f);
- glVertex3f(-m_szBush*0.8f,m_szBush*0.6f,m_szBush*0.1f);
- glTexCoord2f(0,0.336f);
- glVertex3f(0,m_szBush*0.4f,m_szBush*0.6f);
- ////////4
- glTexCoord2f(0,0);
- glVertex3f(m_szBush*0.4f,0,m_szBush*0.1f);
- glTexCoord2f(0.664f,0);
- glVertex3f(-m_szBush*0.5f,0,m_szBush*0.6f);
- glTexCoord2f(0.664f,0.336f);
- glVertex3f(-m_szBush*0.5f,m_szBush*0.3f,m_szBush*0.6f);
- glTexCoord2f(0,0.336f);
- glVertex3f(m_szBush*0.4f,m_szBush*0.3f,m_szBush*0.1f);
- ///////5
- glTexCoord2f(0,0);
- glVertex3f(m_szBush*0.1f,0,-m_szBush*0.1f);
- glTexCoord2f(0.664f,0);
- glVertex3f(m_szBush*0.5f,0,m_szBush*0.6f);
- glTexCoord2f(0.664f,0.336f);
- glVertex3f(m_szBush*0.5f,m_szBush*0.45f,m_szBush*0.6f);
- glTexCoord2f(0,0.336f);
- glVertex3f(m_szBush*0.1f,m_szBush*0.45f,-m_szBush*0.1f);
- ///////6
- glTexCoord2f(0,0);
- glVertex3f(m_szBush*0.3f,0,m_szBush*0.1f);
- glTexCoord2f(0.664f,0);
- glVertex3f(m_szBush*0.6f,0,-m_szBush*0.7f);
- glTexCoord2f(0.664f,0.336f);
- glVertex3f(m_szBush*0.6f,m_szBush*0.2f,-m_szBush*0.7f);
- glTexCoord2f(0,0.336f);
- glVertex3f(m_szBush*0.3f,m_szBush*0.2f,m_szBush*0.1f);
-
- glEnd();
- }
- void CPlant::DrawStone()
- {
- glDisable(GL_ALPHA_TEST);
- glDisable(GL_BLEND);
- glBindTexture(GL_TEXTURE_2D, texStone[0]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_TRIANGLE_FAN);
- glTexCoord2f(0,0);
- glVertex3f(0,m_szStone,0);
- glTexCoord2f(1,0);
- glVertex3f(0,0,-m_szStone);
- glTexCoord2f(1,1);
- glVertex3f(-m_szStone*1.2f,0,-m_szStone*0.5f);
- glTexCoord2f(0,1);
- glVertex3f(0,0,m_szStone);
- glTexCoord2f(1,0);
- glVertex3f(m_szStone*0.4f,0,-m_szStone*0.2f);
- glTexCoord2f(1,1);
- glVertex3f(0,0,-m_szStone);
- glEnd();
- glEnable(GL_BLEND);
- glEnable(GL_ALPHA_TEST);
- glTranslatef(m_szStone*0.4f,0,0);
- glBindTexture(GL_TEXTURE_2D, texGrass[1]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_TRIANGLE_STRIP);
- glTexCoord2f(0,0);
- glVertex3f(0,0,0);
- glTexCoord2f(0,1);
- glVertex3f(0,m_szStone*2,0);
- glTexCoord2f(0.594f,0);
- glVertex3f(m_szStone*0.4f,0,0);
- glTexCoord2f(0.594f,1);
- glVertex3f(m_szStone*0.4f,m_szStone*2,0);
- glTexCoord2f(0.762f,0);
- glVertex3f(m_szStone*0.25f,0,m_szStone*0.25f);
- glTexCoord2f(0.762f,1);
- glVertex3f(m_szStone*0.25f,m_szStone*2,m_szStone*0.25f);
- glTexCoord2f(1,0);
- glVertex3f(0,0,0);
- glTexCoord2f(1,1);
- glVertex3f(0,m_szStone*2,0);
- glEnd();
- }
- void CPlant::DrawPlant(int PlantID,float XPosition,
- float YPosition,float ZPosition,int distance)
- {
- m_xpos=XPosition;
- m_ypos=YPosition;
- m_zpos=ZPosition;
- glAlphaFunc(GL_GREATER,0.15f);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- // if(distance>10) glDisable(GL_BLEND);
- // else
- glEnable(GL_BLEND);
- glEnable(GL_ALPHA_TEST);
- glDisable(GL_CULL_FACE);
- glDisable(GL_LIGHTING);
- glDisable(GL_LIGHT0);
- glPushMatrix();
- glTranslatef(m_xpos,m_ypos,m_zpos);
- if(PlantID==1)DrawStone();
- if(PlantID==2)DrawGrass();
- if(PlantID==3)DrawTreeB();//DrawBushA();
- if(PlantID==4)DrawTreeB();//DrawBushB();
- if(PlantID==5)DrawVine();
- if(PlantID==6)DrawTreeB();
- glPopMatrix();
- glDisable(GL_ALPHA_TEST);
- glDisable(GL_BLEND);
- glEnable(GL_CULL_FACE);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- }