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

游戏引擎

开发平台:

Visual C++

  1. // SkyBox.cpp: implementation of the CSkyBox class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "texmanager.h"
  6. #include "SkyBox.h"
  7. //////////////////////////////////////////////////////////////////////
  8. // Construction/Destruction
  9. //////////////////////////////////////////////////////////////////////
  10. CSkyBox::CSkyBox()
  11. {
  12. }
  13. CSkyBox::~CSkyBox()
  14. {
  15. }
  16. bool CSkyBox::InitSkyBox(int XLenght, int YLenght,int ZLenght,
  17.  int CenterX,int CenterY,int CenterZ)
  18. {
  19. m_XLength=XLenght;
  20. m_YLength=YLenght;
  21. m_ZLength=ZLenght;
  22. m_CenterX=CenterX;
  23. m_CenterY=CenterY;
  24. m_CenterZ=CenterZ;
  25. CTexManager cTexManager;
  26. texSky[0]=cTexManager.GetTextureID(TEX_SKY_0);
  27. texSky[1]=cTexManager.GetTextureID(TEX_SKY_1);
  28. texSky[2]=cTexManager.GetTextureID(TEX_SKY_2);
  29. texSky[3]=cTexManager.GetTextureID(TEX_SKY_3);
  30. texSky[4]=cTexManager.GetTextureID(TEX_SKY_4);
  31. return true;
  32. }
  33. void CSkyBox::DrawSkyBox()
  34. {
  35. int lx,ly,lz,cx,cy,cz;
  36. lx=m_XLength;
  37. ly=m_YLength;
  38. lz=m_ZLength;
  39. cx=m_CenterX;
  40. cy=m_CenterY;
  41. cz=m_CenterZ;
  42. float btmy=0.0f;//This variable indicate how much texture should be cut from 0 to btmy
  43. //  glDisable(GL_FOG); 
  44. ////////front
  45.   glBindTexture(GL_TEXTURE_2D, texSky[0]);
  46.     glEnable(GL_TEXTURE_2D); 
  47.    glBegin(GL_QUADS);
  48.             glTexCoord2f(0,btmy);
  49.     glVertex3i(-lx+cx, cy,   -lz+cz);
  50.              glTexCoord2f(1,btmy);
  51.     glVertex3i(lx+cx, cy,   -lz+cz);
  52.             glTexCoord2f(1,1);
  53.     glVertex3i(lx+cx, ly+cy,   -lz+cz);
  54.             glTexCoord2f(0,1);
  55.     glVertex3i(-lx+cx, ly+cy,    -lz+cz);
  56.             glEnd();
  57. glDisable(GL_TEXTURE_2D); 
  58. ///     ////////////////sky1
  59. /////////////////right
  60. glBindTexture(GL_TEXTURE_2D, texSky[1]);
  61.     glEnable(GL_TEXTURE_2D); 
  62.   
  63. glBegin(GL_QUADS);
  64.             glTexCoord2f(0,btmy);
  65.     glVertex3i(lx+cx, cy,    -lz+cz);
  66.              glTexCoord2f(1,btmy);
  67.     glVertex3i(lx+cx, cy,    lz+cz);
  68.             glTexCoord2f(1,1);
  69.     glVertex3i(lx+cx, ly+cy,    lz+cz);
  70.             glTexCoord2f(0,1);
  71.     glVertex3i(lx+cx, ly+cy,    -lz+cz);
  72.             glEnd();
  73. glDisable(GL_TEXTURE_2D); 
  74. ///     ////////////////sky2
  75. //////////////back
  76. glBindTexture(GL_TEXTURE_2D, texSky[2]);
  77.     glEnable(GL_TEXTURE_2D); 
  78.  
  79. glBegin(GL_QUADS);
  80.             glTexCoord2f(0,btmy);
  81.     glVertex3i(lx+cx, cy,    lz+cz);
  82.              glTexCoord2f(1,btmy);
  83.     glVertex3i(-lx+cx, cy,    lz+cz);
  84.             glTexCoord2f(1,1);
  85.     glVertex3i(-lx+cx, ly+cy,    lz+cz);
  86.             glTexCoord2f(0,1);
  87.     glVertex3i(lx+cx, ly+cy,    lz+cz);
  88.             glEnd();
  89. glDisable(GL_TEXTURE_2D); 
  90. ///     ////////////////sky3
  91. ////////////////left
  92. glBindTexture(GL_TEXTURE_2D, texSky[3]);
  93.     glEnable(GL_TEXTURE_2D); 
  94.        glBegin(GL_QUADS);
  95.             glTexCoord2f(0,btmy);
  96.     glVertex3i(-lx+cx, cy,    lz+cz);
  97.              glTexCoord2f(1,btmy);
  98.     glVertex3i(-lx+cx, cy,    -lz+cz);
  99.             glTexCoord2f(1,1);
  100.     glVertex3i(-lx+cx, ly+cy,    -lz+cz);
  101.             glTexCoord2f(0,1);
  102.     glVertex3i(-lx+cx, ly+cy,    lz+cz);
  103.             glEnd();
  104. glDisable(GL_TEXTURE_2D); 
  105. ///     ////////////////sky4
  106. /////////////up
  107. glBindTexture(GL_TEXTURE_2D, texSky[4]);
  108.     glEnable(GL_TEXTURE_2D); 
  109. glBegin(GL_QUADS);
  110.             glTexCoord2f(0,0);
  111.     glVertex3i(-lx+cx, ly+cy,    -lz+cz);
  112.              glTexCoord2f(1,0);
  113.     glVertex3i(lx+cx,ly+cy,    -lz+cz);
  114.             glTexCoord2f(1,1);
  115.     glVertex3i(lx+cx, ly+cy,    lz+cz);
  116.             glTexCoord2f(0,1);
  117.     glVertex3i(-lx+cx, ly+cy,    lz+cz);
  118.             glEnd();
  119. glDisable(GL_TEXTURE_2D);
  120.   //glEnable(GL_FOG); 
  121. }