SpritManager.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:3k
- // SpriteManager.cpp: implementation of the CSpriteManager class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "SpriteManager.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CSpriteManager::CSpriteManager()
- {
- }
- CSpriteManager::~CSpriteManager()
- {
- }
- bool CSpriteManager::InitSpriteManager()
- {
- if(!m_cMD2.InitMd2Loader("model/major.md2","model/major.bmp",0.2f))
- {
- MessageBox(0, "read heightmap failed", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- if(!m_cWeapon.InitMd2Loader("model/majorweapon.md2","model/majorweapon.bmp",0.2f))
- {
- MessageBox(0, "read heightmap failed", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- float height=m_cMD2.m_boundary.maxy-m_cMD2.m_boundary.miny;
- for(int i=0;i<NUM_MAJOR;i++)
- if(!m_cMajor[i].InitSprite(16,VERTEX(806,m_cHmap.GetHeight(806,1300+i*i*10)+height*0.5f,1300+i*i*10),
- -90,m_cMD2.numFrames,height,m_cMD2.m_boundary,true))
- {
- MessageBox(0, "read heightmap failed", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- //////////////////////////////////////////////////////////////
- if(!m_cMD2Dragon.InitMd2Loader("model/sodf.md2","model/sodf.BMP",0.2f))
- {
- MessageBox(0, "read heightmap failed", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- height=m_cMD2Dragon.m_boundary.maxy-m_cMD2.m_boundary.miny;
- for( i=0;i<NUM_DRAGON;i++)
- if(!m_cDragon[i].InitSprite(16,VERTEX(850,m_cHmap.GetHeight(850,1320+i*10)+height*0.5f,1320+i*10),
- -90,m_cMD2.numFrames,height,m_cMD2Dragon.m_boundary,true))
- {
- MessageBox(0, "read heightmap failed", "Error", MB_OK | MB_ICONERROR);
- return FALSE;
- }
- return true;
- }
- void CSpriteManager::UpdateSpriteManager()
- {
- for(int i=0;i<NUM_MAJOR;i++)
- {
- m_cMajor[i].UpdateSprite();
- if(m_cHmap.IsInFrustum(m_cMajor[i].m_Camera.m_CamPos))
- {
- glPushMatrix();
- glTranslatef(m_cMajor[i].m_Camera.m_CamPos.xpos,
- m_cMajor[i].m_Camera.m_CamPos.ypos,
- m_cMajor[i].m_Camera.m_CamPos.zpos);
- glRotatef(m_cMajor[i].m_Camera.m_CamRotY-90, 0.0f,1.0f,0.0f);
- /*
- m_cMajor[i].m_Health-=0.02f;
- if(m_cMajor[i].m_Health<0)m_cMajor[i].m_Health=1.5;
- glColor3f(m_cMajor[i].m_Health,m_cMajor[i].m_Health,m_cMajor[i].m_Health);
- glBlendFunc(GL_SRC_COLOR,GL_ONE);
- if(m_cMajor[i].m_Health<1)glEnable(GL_BLEND);*/
- m_cMD2.Animate (m_cMajor[i].m_startFrame,m_cMajor[i].m_endFrame,m_cMajor[i].m_percent);
- m_cWeapon.Animate(m_cMajor[i].m_startFrame,m_cMajor[i].m_endFrame,m_cMajor[i].m_percent);
- // glDisable(GL_BLEND);
- // glColor3f(1,1,1);
- glPopMatrix();
- }
- }
- /////////////////////////////////
- for( i=0;i<NUM_DRAGON;i++)
- {
- m_cDragon[i].UpdateSprite();
- if(m_cHmap.IsInFrustum(m_cDragon[i].m_Camera.m_CamPos))
- {
- glPushMatrix();
- glTranslatef(m_cDragon[i].m_Camera.m_CamPos.xpos,
- m_cDragon[i].m_Camera.m_CamPos.ypos,
- m_cDragon[i].m_Camera.m_CamPos.zpos);
- glRotatef(m_cDragon[i].m_Camera.m_CamRotY-90, 0.0f,1.0f,0.0f);
-
- m_cMD2Dragon.Animate(m_cDragon[i].m_startFrame,m_cDragon[i].m_endFrame,m_cDragon[i].m_percent);
-
- glPopMatrix();
- }
- }
- }