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. }
  14. CHouse::~CHouse()
  15. {
  16. }
  17. bool CHouse::InitHouse(VERTEX position)
  18. {
  19. m_position=position;
  20.     CTexture cTexture;
  21.     if(!cTexture.MakeTextureBind("texture/rock0.bmp",         &m_texParticles[0]))return false;
  22.     if(!cTexture.MakeTextureBind("texture/rock1.bmp",         &m_texParticles[1]))return false;
  23.     if(!cTexture.MakeAlphaTextureBind("texture/smoke.bmp",    &m_texParticles[2]))return false;
  24.     if(!cTexture.MakeAlphaTextureBind("texture/smoke02.bmp",    &m_texParticles[3]))return false;
  25. if(!m_ms3dHouse.Load("model/ms3d/house.ms3d"))
  26. {
  27. MessageBox(0, "Init ms3d failed", "Error", MB_OK | MB_ICONERROR);
  28. return FALSE;
  29. }
  30. if(!m_smoke.InitParticle(SMOKE_P,VERTEX(0,0,0),m_texParticles))
  31. {
  32. MessageBox(0, "Init smoke failed", "Error", MB_OK | MB_ICONERROR);
  33. return FALSE;
  34. }
  35.     m_chimneyPos.xpos=m_ms3dHouse.m_boundary.minx*0.5f;
  36.     m_chimneyPos.ypos=m_ms3dHouse.m_boundary.maxy*0.95f;
  37.     m_chimneyPos.zpos=m_ms3dHouse.m_boundary.minz*0.55f;
  38. m_ms3dHouse.m_boundary.minx += m_position.xpos;
  39. m_ms3dHouse.m_boundary.maxx += m_position.xpos;
  40. m_ms3dHouse.m_boundary.miny += m_position.ypos;
  41. m_ms3dHouse.m_boundary.maxy += m_position.ypos;
  42. m_ms3dHouse.m_boundary.minz += m_position.zpos;
  43. m_ms3dHouse.m_boundary.maxz += m_position.zpos;
  44. return true;
  45. }
  46. void CHouse::DrawHouse()
  47. {
  48.     if(!m_cHmap.IsInFrustum(m_position))return;
  49.     NORMAL direction;
  50.     direction.nx=-cosf((*m_cHmap.m_pViewRotX)*0.0174533f)*sinf((*m_cHmap.m_pViewRotY)*0.0174533f);
  51.     direction.ny=-sinf((*m_cHmap.m_pViewRotX)*0.0174533f);
  52.     direction.nz=-cosf((*m_cHmap.m_pViewRotX)*0.0174533f)*cosf((*m_cHmap.m_pViewRotY)*0.0174533f);
  53.     glPushMatrix();
  54. glTranslatef(m_position.xpos,m_position.ypos,m_position.zpos);
  55.         m_ms3dHouse.Render(direction);
  56.     glDisable(GL_LIGHTING);
  57.     glDisable(GL_LIGHT0);
  58.      glTranslatef(m_chimneyPos.xpos,
  59.          m_chimneyPos.ypos,
  60.  m_chimneyPos.zpos);
  61.       glRotatef(*m_cHmap.m_pViewRotY,  0.0f,1.0f,0.0f);
  62.      glRotatef(-*m_cHmap.m_pViewRotX,  1.0f,0.0f,0.0f);
  63. m_smoke.DrawParticles();
  64.     glPopMatrix();
  65. // m_ms3dHouse.DrawBoundary();
  66. CheckSunVisible();
  67. }
  68. void CHouse::CheckSunVisible()
  69. {
  70. if(!m_cHmap.m_bSunVisible)return;
  71.     if(m_cMath.IsLineSegmentCutBy3DBoundary(*m_cHmap.m_pViewPos ,
  72.                                      *m_cHmap.m_pSunPos,
  73.     m_ms3dHouse.m_boundary))
  74.         m_cHmap.m_bSunVisible=false;
  75. }