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

游戏引擎

开发平台:

Visual C++

  1. // House.cpp: implementation of the CHouse class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "House.h"
  6. #include "math.h"
  7. #include "texture.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CHouse::CHouse()
  12. {
  13.     m_pModel=NULL;
  14. m_pSmoke=NULL;
  15. m_bSomking=true;
  16. }
  17. CHouse::~CHouse()
  18. {
  19. }
  20. bool CHouse::InitHouse(CMs3dLoader *pModel,CSmokeParticle *pSmoke,
  21.    VERTEX position,float roty,unsigned int texid,bool bSmoking)
  22. {
  23.     m_pModel=pModel;
  24. if(m_pModel==NULL)return false;
  25. m_pSmoke=pSmoke;
  26. if(m_pSmoke==NULL)return false;
  27. m_position.xpos=position.xpos;
  28. m_position.zpos=position.zpos;
  29. m_position.ypos=m_cHmap.GetHeight(m_position.xpos,m_position.zpos);
  30. m_roty=roty;
  31.     m_texID=texid;
  32.     VERTEX v1=pModel->GetVertex(72);
  33.     VERTEX v2=pModel->GetVertex(76);
  34.  
  35.     m_somkePos.xpos=m_position.xpos+(v1.xpos+v2.xpos)/2;
  36.     m_somkePos.ypos=m_position.ypos+(v1.ypos+v2.ypos)/2;
  37.     m_somkePos.zpos=m_position.zpos+(v1.zpos+v2.zpos)/2;
  38. m_bigBoundary.minx = m_pModel->m_boundary.minx + m_position.xpos;
  39. m_bigBoundary.maxx = m_pModel->m_boundary.maxx + m_position.xpos;
  40. m_bigBoundary.miny = m_pModel->m_boundary.miny + m_position.ypos;
  41. m_bigBoundary.maxy = m_pModel->m_boundary.maxy + m_position.ypos;
  42. m_bigBoundary.minz = m_pModel->m_boundary.minz + m_position.zpos;
  43. m_bigBoundary.maxz = m_pModel->m_boundary.maxz + m_position.zpos;
  44. VERTEX v3=pModel->GetVertex(51);
  45. VERTEX v4=pModel->GetVertex(69);
  46.   m_smallBoundary.maxx=v4.xpos + m_position.xpos;
  47. m_smallBoundary.minx=v3.xpos + m_position.xpos;
  48. m_smallBoundary.maxy=v4.ypos + m_position.ypos;
  49. m_smallBoundary.miny=v3.ypos + m_position.ypos;
  50. m_smallBoundary.maxz=v4.zpos + m_position.zpos;
  51. m_smallBoundary.minz=v3.zpos + m_position.zpos;
  52. m_bSomking=bSmoking;
  53. return true;
  54. }
  55. void CHouse::DrawHouse()
  56. {
  57.     if(!m_cHmap.IsInFrustum(&m_bigBoundary))return;
  58.     glPushMatrix();
  59. glTranslatef(m_position.xpos,m_position.ypos,m_position.zpos);
  60.     glRotatef(m_roty,  0.0f,1.0f,0.0f); 
  61.   glBindTexture(GL_TEXTURE_2D,m_texID);
  62. glEnable(GL_TEXTURE_2D);
  63. m_pModel->Render();
  64.     glPopMatrix();
  65. CHeightmap::m_numTriangles += 181 ;
  66. }
  67. void CHouse::DrawSmoke()
  68. {
  69. if(!m_bSomking)return ;
  70.     if(!m_cHmap.IsInFrustum(&m_bigBoundary))return;
  71.     glPushMatrix();
  72.     glTranslatef(m_somkePos.xpos,m_somkePos.ypos,m_somkePos.zpos);
  73.     glRotatef(m_cHmap.m_ViewRotY,  0.0f,1.0f,0.0f);
  74.     glRotatef(-m_cHmap.m_ViewRotX,  1.0f,0.0f,0.0f);
  75. m_pSmoke->DrawParticle();
  76.     glPopMatrix();
  77. CHeightmap::m_numTriangles += 100 ;
  78. }
  79. void CHouse::SetSmoking(bool bSomking)
  80. {
  81.     m_bSomking=bSomking;
  82. }