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

游戏引擎

开发平台:

Visual C++

  1. // Bush.cpp: implementation of the CBush class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Bush.h"
  6. #include "texmanager.h"
  7. #include "math.h"
  8. #include "heightmap.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CBush::CBush()
  13. {
  14. m_size=10.0f;
  15.     m_height=m_size*0.5f;
  16. }
  17. CBush::~CBush()
  18. {
  19. }
  20. bool CBush::InitBush(int type)
  21. {
  22.  m_type=type;
  23.  CTexManager cTexManager;
  24.  //////////////read blend skin texture
  25. //  if(type==1)
  26.  texBush=cTexManager.GetTextureID(TEX_BUSH_0);
  27. //     else
  28. //  texBush=cTexManager.GetTextureID(TEX_BUSH_0);
  29.      return true;
  30. }
  31. void CBush::RenderBush(VERTEX pos)
  32. {
  33.     glPushMatrix();
  34. glTranslatef(pos.xpos,pos.ypos,pos.zpos);
  35.     glAlphaFunc(GL_GREATER,0.10f);
  36. glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  37. glEnable(GL_BLEND);
  38.     glEnable(GL_ALPHA_TEST);
  39. glBindTexture(GL_TEXTURE_2D, texBush);
  40. glEnable(GL_TEXTURE_2D);
  41. ////////////////////////////////////
  42. if(m_type==1)
  43.         DrawBush();
  44. else
  45. DrawLichen();
  46.    ///////////////////////////////////////////
  47.     glDisable(GL_ALPHA_TEST);
  48. glDisable(GL_BLEND); 
  49.     glPopMatrix();
  50. }
  51. void CBush::DrawBush()
  52. {
  53. DrawCross(m_size,0,80,0,1,0.336f,1);
  54. DrawCross(m_size*0.4f,m_size*0.2f,60,1,0.65f,0,0.336f);
  55.     glPushMatrix();
  56.     //////////////////////////////////
  57. glTranslatef(m_size*0.4f,0,m_size*0.25f);
  58. DrawCross(m_size*0.4f,0,70,1,0.65f,0,0.336f);
  59. ////////////////////////////
  60. glPopMatrix();
  61. }
  62. void CBush::DrawLichen()
  63. {
  64. DrawCross(m_size,0,45,0,1,0.336f,1);
  65. DrawCross(m_size*0.7f,m_size*0.2f,30,1,0.65f,0,0.336f);
  66. /*
  67.     glPushMatrix();
  68.     //////////////////////////////////
  69. glTranslatef(m_size*0.4f,0,m_size*0.25f);
  70. DrawCross(m_size*0.4f,0,70,1,0.65f,0,0.336f);
  71. ////////////////////////////
  72. glPopMatrix();
  73. */
  74. }
  75. void CBush::DrawCross(float size,float bias,int angle,float x1,float x2,float y1,float y2)
  76. {
  77. int num=360/angle;
  78. glBegin(GL_QUADS);
  79. int curAngle=0;
  80. for(int i=0;i<num;i++)
  81. {
  82. curAngle=angle*i;
  83.     glTexCoord2f(x1,y1);
  84.     glVertex3f(bias*cosf(0.0174533f*curAngle),0,bias*sinf(0.0174533f*curAngle));    
  85. glTexCoord2f(x2,y1);
  86.     glVertex3f((bias+size)*cosf(0.0174533f*curAngle),0,(bias+size)*sinf(0.0174533f*curAngle));    
  87.        glTexCoord2f(x2,y2);
  88.     glVertex3f((bias+size)*cosf(0.0174533f*curAngle),size*0.5f,(bias+size)*sinf(0.0174533f*curAngle));    
  89. glTexCoord2f(x1,y2);
  90.     glVertex3f(bias*cosf(0.0174533f*curAngle),size*0.5f,bias*sinf(0.0174533f*curAngle));    
  91.  
  92.      CHeightmap::m_numTriangles += 2 ;
  93. }
  94.     glEnd();
  95. }