House.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:3k
- // House.cpp: implementation of the CHouse class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "House.h"
- #include "math.h"
- #include "texture.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CHouse::CHouse()
- {
- }
- CHouse::~CHouse()
- {
- }
- bool CHouse::InitHouse(VERTEX position)
- {
- m_position=position;
- CTexture cTexture;
- if(!cTexture.MakeTextureBind("texture/rock0.bmp", &m_texParticles[0]))return false;
- if(!cTexture.MakeTextureBind("texture/rock1.bmp", &m_texParticles[1]))return false;
- if(!cTexture.MakeAlphaTextureBind("texture/smoke.bmp", &m_texParticles[2]))return false;
- if(!cTexture.MakeAlphaTextureBind("texture/smoke02.bmp", &m_texParticles[3]))return false;
- if(!m_ms3dHouse.Load("model/ms3d/house.ms3d"))
- {
- MessageBox(0, "Init ms3d failed", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- if(!m_smoke.InitParticle(SMOKE_P,VERTEX(0,0,0),m_texParticles))
- {
- MessageBox(0, "Init smoke failed", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- m_chimneyPos.xpos=m_ms3dHouse.m_boundary.minx*0.5f;
- m_chimneyPos.ypos=m_ms3dHouse.m_boundary.maxy*0.95f;
- m_chimneyPos.zpos=m_ms3dHouse.m_boundary.minz*0.55f;
- m_ms3dHouse.m_boundary.minx += m_position.xpos;
- m_ms3dHouse.m_boundary.maxx += m_position.xpos;
- m_ms3dHouse.m_boundary.miny += m_position.ypos;
- m_ms3dHouse.m_boundary.maxy += m_position.ypos;
- m_ms3dHouse.m_boundary.minz += m_position.zpos;
- m_ms3dHouse.m_boundary.maxz += m_position.zpos;
- return true;
- }
- void CHouse::DrawHouse()
- {
- if(!m_cHmap.IsInFrustum(m_position))return;
- NORMAL direction;
- direction.nx=-cosf((*m_cHmap.m_pViewRotX)*0.0174533f)*sinf((*m_cHmap.m_pViewRotY)*0.0174533f);
- direction.ny=-sinf((*m_cHmap.m_pViewRotX)*0.0174533f);
- direction.nz=-cosf((*m_cHmap.m_pViewRotX)*0.0174533f)*cosf((*m_cHmap.m_pViewRotY)*0.0174533f);
- glPushMatrix();
- glTranslatef(m_position.xpos,m_position.ypos,m_position.zpos);
- m_ms3dHouse.Render(direction);
-
- glDisable(GL_LIGHTING);
- glDisable(GL_LIGHT0);
- glTranslatef(m_chimneyPos.xpos,
- m_chimneyPos.ypos,
- m_chimneyPos.zpos);
- glRotatef(*m_cHmap.m_pViewRotY, 0.0f,1.0f,0.0f);
- glRotatef(-*m_cHmap.m_pViewRotX, 1.0f,0.0f,0.0f);
- m_smoke.DrawParticles();
- glPopMatrix();
-
- // m_ms3dHouse.DrawBoundary();
- CheckSunVisible();
- }
- void CHouse::CheckSunVisible()
- {
- if(!m_cHmap.m_bSunVisible)return;
- if(m_cMath.IsLineSegmentCutBy3DBoundary(*m_cHmap.m_pViewPos ,
- *m_cHmap.m_pSunPos,
- m_ms3dHouse.m_boundary))
- m_cHmap.m_bSunVisible=false;
- }