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

游戏引擎

开发平台:

Visual C++

  1. // SpriteManager.cpp: implementation of the CSpriteManager class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "SpriteManager.h"
  6. //////////////////////////////////////////////////////////////////////
  7. // Construction/Destruction
  8. //////////////////////////////////////////////////////////////////////
  9. CSpriteManager::CSpriteManager()
  10. {
  11. }
  12. CSpriteManager::~CSpriteManager()
  13. {
  14. }
  15. bool CSpriteManager::InitSpriteManager()
  16. {
  17. if(!m_cMD2.InitMd2Loader("model/major.md2","model/major.bmp",0.2f))
  18. {
  19. MessageBox(0, "read heightmap failed", "Error", MB_OK | MB_ICONERROR);
  20. return FALSE;
  21. }
  22. if(!m_cWeapon.InitMd2Loader("model/majorweapon.md2","model/majorweapon.bmp",0.2f))
  23. {
  24. MessageBox(0, "read heightmap failed", "Error", MB_OK | MB_ICONERROR);
  25. return FALSE;
  26. }
  27. float height=m_cMD2.m_boundary.maxy-m_cMD2.m_boundary.miny;
  28. for(int i=0;i<NUM_MAJOR;i++)
  29.     if(!m_cMajor[i].InitSprite(16,VERTEX(806,m_cHmap.GetHeight(806,1300+i*i*10)+height*0.5f,1300+i*i*10),
  30.                       -90,m_cMD2.numFrames,height,m_cMD2.m_boundary,true))
  31. {
  32.     MessageBox(0, "read heightmap failed", "Error", MB_OK | MB_ICONERROR);
  33.     return FALSE;
  34. }
  35. //////////////////////////////////////////////////////////////
  36. if(!m_cMD2Dragon.InitMd2Loader("model/sodf.md2","model/sodf.BMP",0.2f))
  37. {
  38. MessageBox(0, "read heightmap failed", "Error", MB_OK | MB_ICONERROR);
  39. return FALSE;
  40. }
  41. height=m_cMD2Dragon.m_boundary.maxy-m_cMD2.m_boundary.miny;
  42. for( i=0;i<NUM_DRAGON;i++)
  43.     if(!m_cDragon[i].InitSprite(16,VERTEX(850,m_cHmap.GetHeight(850,1320+i*10)+height*0.5f,1320+i*10),
  44.                       -90,m_cMD2.numFrames,height,m_cMD2Dragon.m_boundary,true))
  45. {
  46.     MessageBox(0, "read heightmap failed", "Error", MB_OK | MB_ICONERROR);
  47.     return FALSE;
  48. }
  49. return true;
  50. }
  51. void CSpriteManager::UpdateSpriteManager()
  52. {
  53. for(int i=0;i<NUM_MAJOR;i++)
  54. {
  55.         m_cMajor[i].UpdateSprite();
  56.         if(m_cHmap.IsInFrustum(m_cMajor[i].m_Camera.m_CamPos))
  57. {
  58.             glPushMatrix();
  59.         glTranslatef(m_cMajor[i].m_Camera.m_CamPos.xpos,
  60.          m_cMajor[i].m_Camera.m_CamPos.ypos,
  61.  m_cMajor[i].m_Camera.m_CamPos.zpos);
  62.         glRotatef(m_cMajor[i].m_Camera.m_CamRotY-90,  0.0f,1.0f,0.0f);
  63.  /*
  64.         m_cMajor[i].m_Health-=0.02f;
  65.         if(m_cMajor[i].m_Health<0)m_cMajor[i].m_Health=1.5;
  66.         glColor3f(m_cMajor[i].m_Health,m_cMajor[i].m_Health,m_cMajor[i].m_Health);
  67.         glBlendFunc(GL_SRC_COLOR,GL_ONE);
  68.             if(m_cMajor[i].m_Health<1)glEnable(GL_BLEND);*/
  69.             m_cMD2.Animate   (m_cMajor[i].m_startFrame,m_cMajor[i].m_endFrame,m_cMajor[i].m_percent);
  70.             m_cWeapon.Animate(m_cMajor[i].m_startFrame,m_cMajor[i].m_endFrame,m_cMajor[i].m_percent);
  71. //          glDisable(GL_BLEND);
  72. //         glColor3f(1,1,1);
  73.             glPopMatrix();
  74. }
  75.     }
  76.     /////////////////////////////////
  77. for( i=0;i<NUM_DRAGON;i++)
  78. {
  79.         m_cDragon[i].UpdateSprite();
  80.         if(m_cHmap.IsInFrustum(m_cDragon[i].m_Camera.m_CamPos))
  81. {
  82.             glPushMatrix();
  83.         glTranslatef(m_cDragon[i].m_Camera.m_CamPos.xpos,
  84.          m_cDragon[i].m_Camera.m_CamPos.ypos,
  85.  m_cDragon[i].m_Camera.m_CamPos.zpos);
  86.         glRotatef(m_cDragon[i].m_Camera.m_CamRotY-90,  0.0f,1.0f,0.0f);
  87.  
  88.             m_cMD2Dragon.Animate(m_cDragon[i].m_startFrame,m_cDragon[i].m_endFrame,m_cDragon[i].m_percent);
  89.  
  90.             glPopMatrix();
  91. }
  92.     }
  93. }