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

游戏引擎

开发平台:

Visual C++

  1. // Plant.cpp: implementation of the CPlant class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Texture.h"
  6. #include "Plant.h"
  7. #include "math.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CPlant::CPlant()
  12. {
  13. m_szTree=0.2f;
  14.     m_height=m_szTree*60;
  15. m_szBush=10;
  16. m_szTreeB=10;
  17. m_szGrass=6;
  18. m_szVine=30;
  19. m_szStone=5;
  20. }
  21. CPlant::~CPlant()
  22. {
  23. /* for(int i=0;i<4;i++)
  24. {
  25. glDeleteTextures(1,&Trees[i]);
  26. }
  27. */
  28. }
  29. bool CPlant::LoadPlantPicture()
  30. {
  31. /*
  32.  CTexture cTex;
  33.  //////////////read blend skin texture
  34.  int i=0;
  35.  char filename[64];
  36.  char Alphaname[64];
  37.  for(i=0;i<2;i++)
  38.  {
  39.  wsprintf(filename,"Plants/treeBody%d.bmp",i+1);
  40.  if(!cTex.MakeTextureBind(filename,&texTreeBody[i]))
  41.  {
  42.      MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
  43.      return false;
  44.  }  
  45.  }
  46.  for(i=0;i<1;i++)
  47.  {
  48.  wsprintf(filename,"Plants/stone.bmp");
  49.  if(!cTex.MakeTextureBind(filename,&texStone[i]))
  50.  {
  51.      MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
  52.      return false;
  53.  }  
  54.  }
  55.  for(i=0;i<4;i++)
  56.  {
  57.  wsprintf(filename,"Plants/grass%d.bmp",i+1);
  58.  wsprintf(Alphaname,"Plants/grassAlpha%d.bmp",i+1);
  59.  if(!cTex.MakeAlphaTextureBind(filename,Alphaname,&texGrass[i]))
  60.  {
  61.      MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
  62.      return false;
  63.  }  
  64.  }
  65.  for(i=0;i<4;i++)
  66.  {
  67.  wsprintf(filename,"Plants/bush%d.bmp",i+1);
  68.  wsprintf(Alphaname,"Plants/bushAlpha%d.bmp",i+1);
  69.  if(!cTex.MakeAlphaTextureBind(filename,Alphaname,&texBush[i]))
  70.  {
  71.      MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
  72.      return false;
  73.  }  
  74.  }
  75.  for(i=0;i<5;i++)
  76.  {
  77.  wsprintf(filename,"Plants/branch%d.bmp",i+1);
  78.  wsprintf(Alphaname,"Plants/branchAlpha%d.bmp",i+1);
  79.  if(!cTex.MakeAlphaTextureBind(filename,Alphaname,&texBranch[i]))
  80.  {
  81.      MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
  82.      return false;
  83.  }  
  84.  }
  85.  for(i=0;i<2;i++)
  86.  {
  87.  wsprintf(filename,"Plants/vine%d.bmp",i+1);
  88.  wsprintf(Alphaname,"Plants/vineAlpha%d.bmp",i+1);
  89.  if(!cTex.MakeAlphaTextureBind(filename,Alphaname,&texVine[i]))
  90.  {
  91.      MessageBox(NULL,"Read Skin error","ERROR",MB_OK|MB_ICONSTOP);
  92.      return false;
  93.  }  
  94.  }*/
  95.      return true;
  96. }
  97. bool CPlant::InitPlant()
  98. {
  99.     if(!LoadPlantPicture())return false;
  100.     return true;
  101. }
  102. void CPlant::DrawTree()
  103. {
  104.     ///////////////////////////////////
  105. //////////Draw Tree Body
  106.     glDisable(GL_ALPHA_TEST);
  107. glDisable(GL_BLEND);
  108.   glBindTexture(GL_TEXTURE_2D, texTreeBody[1]);
  109. glEnable(GL_TEXTURE_2D);
  110. glBegin(GL_QUAD_STRIP);
  111.     for(float i=0;i<8;i++)
  112. {
  113.         glTexCoord2i(int(i+1)%2,0);    
  114. glVertex3f(-m_szTree*sinf(i*45*0.0174533f),0,-m_szTree*cosf(i*45*0.0174533f));
  115.         glTexCoord2i(int(i+1)%2,50);    
  116. glVertex3f(-m_szTree*sinf(i*45*0.0174533f)*0.1f,m_height,-m_szTree*cosf(i*45*0.0174533f)*0.1f);
  117.   }
  118.     glTexCoord2f(1,0);    
  119.     glVertex3f(0,0,-m_szTree);
  120.     glTexCoord2f(1,50);    
  121. glVertex3f(0,m_height,-m_szTree*0.1f);
  122.     glEnd();
  123.     glEnable(GL_ALPHA_TEST);
  124.     glEnable(GL_BLEND);
  125.     //////////////////////////////////////////
  126. ///////////////// Draw Branch ////////////
  127.   glBindTexture(GL_TEXTURE_2D, texBranch[1]);
  128. glEnable(GL_TEXTURE_2D);
  129. glBegin(GL_QUADS);
  130. for( i=0;i<8;i++)
  131. {
  132.     glTexCoord2f(0,0);
  133.     glVertex3f(-m_szTree*20*sinf(i*45*0.0174533f),m_height*0.4f,-m_szTree*20*cosf(i*45*0.0174533f));
  134.     glTexCoord2f(1,0);
  135.     glVertex3f(0,m_height*0.4f,0);
  136.     glTexCoord2f(1,1);
  137.     glVertex3f(0,m_height*0.65f,0);
  138.     glTexCoord2f(0,1);
  139.     glVertex3f(-m_szTree*20*sinf(i*45*0.0174533f),m_height*0.65f,-m_szTree*20*cosf(i*45*0.0174533f));
  140. }
  141. glEnd();
  142.   glBindTexture(GL_TEXTURE_2D, texBranch[3]);
  143. glEnable(GL_TEXTURE_2D);
  144. glBegin(GL_QUADS);
  145. for( i=0.2f;i<6.2f;i++)
  146. {
  147.     glTexCoord2f(0,0);
  148.     glVertex3f(-m_szTree*15*sinf(i*60*0.0174533f),m_height*0.6f,-m_szTree*15*cosf(i*60*0.0174533f));
  149.     glTexCoord2f(1,0);
  150.     glVertex3f(0,m_height*0.6f,0);
  151.     glTexCoord2f(1,1);
  152.     glVertex3f(0,m_height*0.8f,0);
  153.     glTexCoord2f(0,1);
  154.     glVertex3f(-m_szTree*15*sinf(i*60*0.0174533f),m_height*0.8f,-m_szTree*15*cosf(i*60*0.0174533f));
  155. }
  156. glEnd();
  157.   glBindTexture(GL_TEXTURE_2D, texBranch[4]);
  158. glEnable(GL_TEXTURE_2D);
  159. glBegin(GL_QUADS);
  160. for( i=0.2f;i<4.2f;i++)
  161. {
  162.     glTexCoord2f(0,0);
  163.     glVertex3f(-m_szTree*10*sinf(i*90*0.0174533f),m_height*0.75f,-m_szTree*10*cosf(i*90*0.0174533f));
  164.     glTexCoord2f(1,0);
  165.     glVertex3f(0,m_height*0.75f,0);
  166.     glTexCoord2f(1,1);
  167.     glVertex3f(0,m_height*0.95f,0);
  168.     glTexCoord2f(0,1);
  169.     glVertex3f(-m_szTree*10*sinf(i*90*0.0174533f),m_height*0.95f,-m_szTree*10*cosf(i*90*0.0174533f));
  170. }
  171. glEnd();
  172.   
  173. }
  174. void CPlant::DrawTreeB()
  175. {
  176.     //////////////////////////////////////////
  177. ///////////////// Draw Branch ////////////
  178.   glBindTexture(GL_TEXTURE_2D, texBranch[2]);
  179. glEnable(GL_TEXTURE_2D);
  180. glBegin(GL_QUADS);
  181. for(float i=0;i<3;i++)
  182. {
  183.     glTexCoord2f(0,0);
  184.     glVertex3f(-m_szTreeB*sinf(i*60*0.0174533f ),0,-m_szTreeB*cosf(i*60*0.0174533f ));
  185.     glTexCoord2f(1,0);
  186.     glVertex3f(m_szTreeB*sinf(i*60*0.0174533f ),0,m_szTreeB*cosf(i*60*0.0174533f ));
  187.     glTexCoord2f(1,1);
  188.     glVertex3f(m_szTreeB*sinf(i*60*0.0174533f ),m_szTreeB*(2+float(i)/6),m_szTreeB*cosf(i*60*0.0174533f ));
  189.     glTexCoord2f(0,1);
  190.     glVertex3f(-m_szTree*sinf(i*60*0.0174533f ),m_szTreeB*(2+float(i)/6),-m_szTree*cosf(i*60*0.0174533f ));
  191. }
  192. for( i=0.5f;i<3.5f;i++)
  193. {
  194.     glTexCoord2f(1,0);
  195.     glVertex3f(-m_szTreeB*sinf(i*60*0.0174533f ),0,-m_szTreeB*cosf(i*60*0.0174533f ));
  196.     glTexCoord2f(0,0);
  197.     glVertex3f(m_szTreeB*sinf(i*60*0.0174533f ),0,m_szTreeB*cosf(i*60*0.0174533f ));
  198.     glTexCoord2f(0,1);
  199.     glVertex3f(m_szTreeB*sinf(i*60*0.0174533f ),m_szTreeB*(2+float(i)/6),m_szTreeB*cosf(i*60*0.0174533f ));
  200.     glTexCoord2f(1,1);
  201.     glVertex3f(-m_szTree*sinf(i*60*0.0174533f ),m_szTreeB*(2+float(i)/6),-m_szTree*cosf(i*60*0.0174533f ));
  202. }
  203. glEnd();
  204. }
  205. void CPlant::DrawGrass()
  206. {
  207. /////////////Round type
  208.    glBindTexture(GL_TEXTURE_2D, texGrass[2]);
  209. glEnable(GL_TEXTURE_2D);
  210. glBegin(GL_QUAD_STRIP);
  211.     for(float i=0;i<6;i++)
  212. {
  213.         glTexCoord2i(int(i+1)%2,0);    
  214. glVertex3f(-m_szGrass*sinf(i*60*0.0174533f )*0.8f,0,-m_szGrass*cosf(i*60*0.0174533f )*0.8f);
  215.         glTexCoord2i(int(i+1)%2,1);    
  216. glVertex3f(-m_szGrass*sinf(i*60*0.0174533f ),m_szGrass,-m_szGrass*cosf(i*60*0.0174533f ));
  217.   }
  218.     glTexCoord2f(1,0);    
  219.     glVertex3f(0,0,-m_szGrass*0.8f);
  220.     glTexCoord2f(1,1);    
  221. glVertex3f(0,m_szGrass,-m_szGrass);
  222.     glTexCoord2f(0,0);    
  223.     glVertex3f(0,0,m_szGrass*0.8f);
  224.     glTexCoord2f(0,1);    
  225. glVertex3f(0,m_szGrass,m_szGrass);
  226.     glEnd();
  227. }
  228. void CPlant::DrawVine()
  229. {
  230. /////////////vine type
  231.     glEnable(GL_ALPHA_TEST);
  232.   glBindTexture(GL_TEXTURE_2D, texVine[0]);
  233. glEnable(GL_TEXTURE_2D);
  234. glBegin(GL_QUADS);
  235. for(float i=0;i<8;i++)
  236. {
  237.     glTexCoord2f(0,0);
  238.     glVertex3f(-m_szTree*10*sinf(i*45*0.0174533f ),0,-m_szTree*10*cosf(i*45*0.0174533f ));
  239.     glTexCoord2f(1,0);
  240.     glVertex3f(0,0,0);
  241.     glTexCoord2f(1,1);
  242.     glVertex3f(0,m_szTree*10,0);
  243.     glTexCoord2f(0,1);
  244.     glVertex3f(-m_szTree*10*sinf(i*45*0.0174533f ),m_szTree*10,-m_szTree*10*cosf(i*45*0.0174533f ));
  245. }
  246. glEnd();
  247.   glBindTexture(GL_TEXTURE_2D, texVine[1]);
  248. glEnable(GL_TEXTURE_2D);
  249. glBegin(GL_QUADS);
  250. for( i=0.5f;i<6.25f;i++)
  251. {
  252.     glTexCoord2f(0,0);
  253.     glVertex3f(-m_szTree*6*sinf(i*60*0.0174533f ),0,-m_szTree*6*cosf(i*60*0.0174533f ));
  254.     glTexCoord2f(1,0);
  255.     glVertex3f(0,0,0);
  256.     glTexCoord2f(1,1);
  257.     glVertex3f(0,m_szTree*6,0);
  258.     glTexCoord2f(0,1);
  259.     glVertex3f(-m_szTree*6*sinf(i*60*0.0174533f ),m_szTree*6,-m_szTree*6*cosf(i*60*0.0174533f ));
  260. }
  261. glEnd();
  262. }
  263. void CPlant::DrawBushA()
  264. {
  265. /////////////bush type
  266.   glBindTexture(GL_TEXTURE_2D, texBush[0]);
  267. glEnable(GL_TEXTURE_2D);
  268. glBegin(GL_QUADS);
  269. for(float i=0;i<6;i++)
  270. {
  271.     glTexCoord2f(0.02f,0.336f);
  272.     glVertex3f(0,0,0);    
  273. glTexCoord2f(1,0.336f);
  274.     glVertex3f(-m_szBush*sinf(i*60*0.0174533f ),0,-m_szBush*cosf(i*60*0.0174533f ));
  275.        glTexCoord2f(1,1);
  276.     glVertex3f(-m_szBush*sinf(i*60*0.0174533f ),m_szBush*0.6f,-m_szBush*cosf(i*60*0.0174533f ));    
  277. glTexCoord2f(0.02f,1);
  278.     glVertex3f(0,m_szBush*0.6f,0);
  279. }
  280. /////1
  281.     glTexCoord2f(0,0);
  282.     glVertex3f(-m_szBush*0.4f,0,-m_szBush*0.3f);
  283.     glTexCoord2f(0.664f,0);
  284.     glVertex3f(m_szBush*0.4f,0,-m_szBush*0.7f);
  285.     glTexCoord2f(0.664f,0.336f);
  286.     glVertex3f(m_szBush*0.4f,m_szBush*0.4f,-m_szBush*0.7f);
  287.     glTexCoord2f(0,0.336f);
  288.     glVertex3f(-m_szBush*0.4f,m_szBush*0.4f,-m_szBush*0.3f);
  289.     ////////2
  290.     glTexCoord2f(0,0);
  291.     glVertex3f(-m_szBush*0.3f,0,m_szBush*0.1f);
  292.     glTexCoord2f(0.664f,0);
  293.     glVertex3f(-m_szBush*0.7f,0,-m_szBush*0.8f);
  294.     glTexCoord2f(0.664f,0.336f);
  295.     glVertex3f(-m_szBush*0.7f,m_szBush*0.4f,-m_szBush*0.8f);
  296.     glTexCoord2f(0,0.336f);
  297.     glVertex3f(-m_szBush*0.3f,m_szBush*0.4f,m_szBush*0.1f);
  298.     /////////3
  299.     glTexCoord2f(0,0);
  300.     glVertex3f(-m_szBush*0.3f,0,m_szBush*0.8f);
  301.     glTexCoord2f(0.664f,0);
  302.     glVertex3f(-m_szBush*0.7f,0,-m_szBush*0.1f);
  303.     glTexCoord2f(0.664f,0.336f);
  304.     glVertex3f(-m_szBush*0.7f,m_szBush*0.4f,-m_szBush*0.1f);
  305.     glTexCoord2f(0,0.336f);
  306.     glVertex3f(-m_szBush*0.3f,m_szBush*0.4f,m_szBush*0.8f);
  307.     ////////4
  308.     glTexCoord2f(0,0);
  309.     glVertex3f(m_szBush*0.3f,0,m_szBush*0.4f);
  310.     glTexCoord2f(0.664f,0);
  311.     glVertex3f(-m_szBush*0.5f,0,m_szBush*0.9f);
  312.     glTexCoord2f(0.664f,0.336f);
  313.     glVertex3f(-m_szBush*0.5f,m_szBush*0.4f,m_szBush*0.9f);
  314.     glTexCoord2f(0,0.336f);
  315.     glVertex3f(m_szBush*0.3f,m_szBush*0.4f,m_szBush*0.4f);
  316.     ///////5
  317.      glTexCoord2f(0,0);
  318.     glVertex3f(m_szBush*0.3f,0,m_szBush*0.8f);
  319.     glTexCoord2f(0.664f,0);
  320.     glVertex3f(m_szBush*0.7f,0,m_szBush*0.1f);
  321.     glTexCoord2f(0.664f,0.336f);
  322.     glVertex3f(m_szBush*0.7f,m_szBush*0.4f,m_szBush*0.1f);
  323.     glTexCoord2f(0,0.336f);
  324.     glVertex3f(m_szBush*0.3f,m_szBush*0.4f,m_szBush*0.8f);
  325.     ///////6
  326.     glTexCoord2f(0,0);
  327.     glVertex3f(m_szBush*0.2f,0,-m_szBush*0.6f);
  328.     glTexCoord2f(0.664f,0);
  329.     glVertex3f(m_szBush*0.8f,0,-m_szBush*0.1f);
  330.     glTexCoord2f(0.664f,0.336f);
  331.     glVertex3f(m_szBush*0.8f,m_szBush*0.4f,-m_szBush*0.1f);
  332.     glTexCoord2f(0,0.336f);
  333.     glVertex3f(m_szBush*0.2f,m_szBush*0.4f,-m_szBush*0.6f);
  334. glEnd();
  335.   glBindTexture(GL_TEXTURE_2D, texGrass[3]);
  336. glEnable(GL_TEXTURE_2D);
  337. glBegin(GL_QUADS);
  338. for( i=0.5;i<6.5;i++)
  339. {
  340.     glTexCoord2f(0.02f,0.336f);
  341.     glVertex3f(0,m_szBush*0.3f,0);    
  342. glTexCoord2f(1,0.336f);
  343.     glVertex3f(-m_szBush*0.9f*sinf(i*60*0.0174533f ),m_szBush*0.3f,-m_szBush*0.9f*cosf(i*60*0.0174533f ));
  344.        glTexCoord2f(1,1);
  345.     glVertex3f(-m_szBush*0.9f*sinf(i*60*0.0174533f ),m_szBush*0.8f,-m_szBush*0.9f*cosf(i*60*0.0174533f ));    
  346. glTexCoord2f(0.02f,1);
  347.     glVertex3f(0,m_szBush*0.8f,0);
  348. }
  349. ///////1
  350.     glTexCoord2f(0,0);
  351.     glVertex3f(m_szBush*0.4f,-0,-m_szBush*0.4f);
  352.     glTexCoord2f(1,0);
  353.     glVertex3f(-m_szBush*0.4f,0,-m_szBush*0.6f);
  354.     glTexCoord2f(1,1);
  355.     glVertex3f(-m_szBush*0.4f,m_szBush*0.4f,-m_szBush*0.6f);
  356.     glTexCoord2f(0,1);
  357.     glVertex3f(m_szBush*0.4f,m_szBush*0.4f,-m_szBush*0.4f);
  358.     ////////2
  359.     glTexCoord2f(0,0);
  360.     glVertex3f(-m_szBush*0.3f,0,-m_szBush*0.5f);
  361.     glTexCoord2f(1,0);
  362.     glVertex3f(-m_szBush*0.7f,0,m_szBush*0.1f);
  363.     glTexCoord2f(1,1);
  364.     glVertex3f(-m_szBush*0.7f,m_szBush*0.4f,m_szBush*0.1f);
  365.     glTexCoord2f(0,1);
  366.     glVertex3f(-m_szBush*0.3f,m_szBush*0.4f,-m_szBush*0.5f);
  367.     /////////3
  368.     glTexCoord2f(0,0);
  369.     glVertex3f(-m_szBush*0.6f,0,m_szBush*0.1f);
  370.     glTexCoord2f(1,0);
  371.     glVertex3f(m_szBush*0.1f,0,m_szBush*0.8f);
  372.     glTexCoord2f(1,1);
  373.     glVertex3f(m_szBush*0.1f,m_szBush*0.4f,m_szBush*0.8f);
  374.     glTexCoord2f(0,1);
  375.     glVertex3f(-m_szBush*0.6f,m_szBush*0.4f,m_szBush*0.1f);
  376.     ////////4
  377.     glTexCoord2f(0,0);
  378.     glVertex3f(-m_szBush*0.3f,0,m_szBush*0.5f);
  379.     glTexCoord2f(1,0);
  380.     glVertex3f(m_szBush*0.4f,0,m_szBush*0.8f);
  381.     glTexCoord2f(1,1);
  382.     glVertex3f(m_szBush*0.4f,m_szBush*0.4f,m_szBush*0.8f);
  383.     glTexCoord2f(0,1);
  384.     glVertex3f(-m_szBush*0.3f,m_szBush*0.4f,m_szBush*0.5f);
  385.     ///////5
  386.      glTexCoord2f(0,0);
  387.     glVertex3f(m_szBush*0.4f,0,m_szBush*0.7f);
  388.     glTexCoord2f(1,0);
  389.     glVertex3f(m_szBush*0.6f,0,-m_szBush*0.3f);
  390.     glTexCoord2f(1,1);
  391.     glVertex3f(m_szBush*0.6f,m_szBush*0.5f,-m_szBush*0.3f);
  392.     glTexCoord2f(0,1);
  393.     glVertex3f(m_szBush*0.4f,m_szBush*0.5f,m_szBush*0.7f);
  394.     ///////6
  395.     glTexCoord2f(0,0);
  396.     glVertex3f(m_szBush*0.6f,0,m_szBush*0.1f);
  397.     glTexCoord2f(1,0);
  398.     glVertex3f(m_szBush*0.4f,0,-m_szBush*0.75f);
  399.     glTexCoord2f(1,1);
  400.     glVertex3f(m_szBush*0.4f,m_szBush*0.4f,-m_szBush*0.75f);
  401.     glTexCoord2f(0,1);
  402.     glVertex3f(m_szBush*0.6f,m_szBush*0.4f,m_szBush*0.1f);
  403.     glEnd();
  404. }
  405. void CPlant::DrawBushB()
  406. {
  407. /////////////bush type
  408.   glBindTexture(GL_TEXTURE_2D, texBush[2]);
  409. glEnable(GL_TEXTURE_2D);
  410. glBegin(GL_QUADS);
  411. for(float i=0;i<6;i++)
  412. {
  413.     glTexCoord2f(0.02f,0.336f);
  414.     glVertex3f(0,0,0);    
  415. glTexCoord2f(1,0.336f);
  416.     glVertex3f(-m_szBush*0.9f*sinf(i*60*0.0174533f ),0,-m_szBush*0.9f*cosf(i*60*0.0174533f ));
  417.        glTexCoord2f(1,1);
  418.     glVertex3f(-m_szBush*0.9f*sinf(i*60*0.0174533f ),m_szBush*0.5f,-m_szBush*0.9f*cosf(i*60*0.0174533f ));    
  419. glTexCoord2f(0.02f,1);
  420.     glVertex3f(0,m_szBush*0.5f,0);
  421. }
  422. /////1
  423.     glTexCoord2f(0,0);
  424.     glVertex3f(-m_szBush*0.1f,0,0);
  425.     glTexCoord2f(0.664f,0);
  426.     glVertex3f(m_szBush*0.2f,0,-m_szBush*0.6f);
  427.     glTexCoord2f(0.664f,0.336f);
  428.     glVertex3f(m_szBush*0.2f,m_szBush*0.4f,-m_szBush*0.6f);
  429.     glTexCoord2f(0,0.336f);
  430.     glVertex3f(-m_szBush*0.1f,m_szBush*0.4f,0);
  431.     ////////2
  432.     glTexCoord2f(0,0);
  433.     glVertex3f(-m_szBush*0.3f,0,0);
  434.     glTexCoord2f(0.664f,0);
  435.     glVertex3f(-m_szBush*0.8f,0,-m_szBush*0.4f);
  436.     glTexCoord2f(0.664f,0.336f);
  437.     glVertex3f(-m_szBush*0.8f,m_szBush*0.2f,-m_szBush*0.4f);
  438.     glTexCoord2f(0,0.336f);
  439.     glVertex3f(-m_szBush*0.3f,m_szBush*0.2f,0);
  440.     /////////3
  441.     glTexCoord2f(0,0);
  442.     glVertex3f(0,0,m_szBush*0.3f);
  443.     glTexCoord2f(0.664f,0);
  444.     glVertex3f(-m_szBush*0.8f,0,m_szBush*0.1f);
  445.     glTexCoord2f(0.664f,0.336f);
  446.     glVertex3f(-m_szBush*0.8f,m_szBush*0.6f,m_szBush*0.1f);
  447.     glTexCoord2f(0,0.336f);
  448.     glVertex3f(0,m_szBush*0.4f,m_szBush*0.6f);
  449.     ////////4
  450.     glTexCoord2f(0,0);
  451.     glVertex3f(m_szBush*0.4f,0,m_szBush*0.1f);
  452.     glTexCoord2f(0.664f,0);
  453.     glVertex3f(-m_szBush*0.5f,0,m_szBush*0.6f);
  454.     glTexCoord2f(0.664f,0.336f);
  455.     glVertex3f(-m_szBush*0.5f,m_szBush*0.3f,m_szBush*0.6f);
  456.     glTexCoord2f(0,0.336f);
  457.     glVertex3f(m_szBush*0.4f,m_szBush*0.3f,m_szBush*0.1f);
  458.     ///////5
  459.      glTexCoord2f(0,0);
  460.     glVertex3f(m_szBush*0.1f,0,-m_szBush*0.1f);
  461.     glTexCoord2f(0.664f,0);
  462.     glVertex3f(m_szBush*0.5f,0,m_szBush*0.6f);
  463.     glTexCoord2f(0.664f,0.336f);
  464.     glVertex3f(m_szBush*0.5f,m_szBush*0.45f,m_szBush*0.6f);
  465.     glTexCoord2f(0,0.336f);
  466.     glVertex3f(m_szBush*0.1f,m_szBush*0.45f,-m_szBush*0.1f);
  467.     ///////6
  468.     glTexCoord2f(0,0);
  469.     glVertex3f(m_szBush*0.3f,0,m_szBush*0.1f);
  470.     glTexCoord2f(0.664f,0);
  471.     glVertex3f(m_szBush*0.6f,0,-m_szBush*0.7f);
  472.     glTexCoord2f(0.664f,0.336f);
  473.     glVertex3f(m_szBush*0.6f,m_szBush*0.2f,-m_szBush*0.7f);
  474.     glTexCoord2f(0,0.336f);
  475.     glVertex3f(m_szBush*0.3f,m_szBush*0.2f,m_szBush*0.1f);
  476. glEnd();
  477. }
  478. void CPlant::DrawStone()
  479. {
  480.     glDisable(GL_ALPHA_TEST);
  481.     glDisable(GL_BLEND);
  482.   glBindTexture(GL_TEXTURE_2D, texStone[0]);
  483. glEnable(GL_TEXTURE_2D);
  484. glBegin(GL_TRIANGLE_FAN);
  485.         glTexCoord2f(0,0);
  486.         glVertex3f(0,m_szStone,0);
  487.         glTexCoord2f(1,0);
  488.         glVertex3f(0,0,-m_szStone);
  489.         glTexCoord2f(1,1);
  490.         glVertex3f(-m_szStone*1.2f,0,-m_szStone*0.5f);
  491.         glTexCoord2f(0,1);
  492.         glVertex3f(0,0,m_szStone);
  493.         glTexCoord2f(1,0);
  494.         glVertex3f(m_szStone*0.4f,0,-m_szStone*0.2f);
  495.         glTexCoord2f(1,1);
  496.         glVertex3f(0,0,-m_szStone);
  497. glEnd();
  498. glEnable(GL_BLEND);
  499.     glEnable(GL_ALPHA_TEST);
  500. glTranslatef(m_szStone*0.4f,0,0);
  501.   glBindTexture(GL_TEXTURE_2D, texGrass[1]);
  502. glEnable(GL_TEXTURE_2D);
  503. glBegin(GL_TRIANGLE_STRIP);
  504.         glTexCoord2f(0,0);
  505.         glVertex3f(0,0,0);
  506.         glTexCoord2f(0,1);
  507.         glVertex3f(0,m_szStone*2,0);
  508.         glTexCoord2f(0.594f,0);
  509.         glVertex3f(m_szStone*0.4f,0,0);
  510.         glTexCoord2f(0.594f,1);
  511.         glVertex3f(m_szStone*0.4f,m_szStone*2,0);
  512.         glTexCoord2f(0.762f,0);
  513.         glVertex3f(m_szStone*0.25f,0,m_szStone*0.25f);
  514.         glTexCoord2f(0.762f,1);
  515.         glVertex3f(m_szStone*0.25f,m_szStone*2,m_szStone*0.25f);
  516.         glTexCoord2f(1,0);
  517.         glVertex3f(0,0,0);
  518.         glTexCoord2f(1,1);
  519.         glVertex3f(0,m_szStone*2,0);
  520. glEnd();
  521. }
  522. void CPlant::DrawPlant(int PlantID,float XPosition,
  523.    float YPosition,float ZPosition,int distance)
  524. {
  525. m_xpos=XPosition;
  526. m_ypos=YPosition;
  527. m_zpos=ZPosition;
  528. glAlphaFunc(GL_GREATER,0.15f);
  529. glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  530. // if(distance>10) glDisable(GL_BLEND);
  531. // else  
  532. glEnable(GL_BLEND);
  533.     glEnable(GL_ALPHA_TEST);
  534.     glDisable(GL_CULL_FACE);
  535.     glDisable(GL_LIGHTING);
  536.     glDisable(GL_LIGHT0);
  537.     glPushMatrix();
  538. glTranslatef(m_xpos,m_ypos,m_zpos);
  539.     if(PlantID==1)DrawStone();
  540.     if(PlantID==2)DrawGrass();
  541. if(PlantID==3)DrawTreeB();//DrawBushA();
  542. if(PlantID==4)DrawTreeB();//DrawBushB();
  543. if(PlantID==5)DrawVine();
  544. if(PlantID==6)DrawTreeB();
  545. glPopMatrix();
  546.     glDisable(GL_ALPHA_TEST);
  547. glDisable(GL_BLEND);
  548.     glEnable(GL_CULL_FACE);
  549. glEnable(GL_LIGHTING);
  550. glEnable(GL_LIGHT0);
  551. }