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

游戏引擎

开发平台:

Visual C++

  1. // InfoPanel1.cpp: implementation of the CInfoPanel class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "InfoPanel.h"
  6. #include "texManager.h"
  7. #include "imgtext.h"
  8. #include "stdio.h"
  9. #include "input.h"
  10. #include "gamesetting.h"
  11. //////////////////////////////////////////////////////////////////////
  12. // Construction/Destruction
  13. //////////////////////////////////////////////////////////////////////
  14. CInfoPanel::CInfoPanel()
  15. {
  16. m_gunBiasY=0;
  17. m_gunBiasAngleY=0;
  18. m_gunBiasZ=0;
  19. m_gunBiasX=0;
  20. m_gunBiasAngleX=0;
  21. m_bHelpOpen=false;
  22. m_bFire=false;
  23. }
  24. CInfoPanel::~CInfoPanel()
  25. {
  26. }
  27. bool CInfoPanel::InitInfoPanel()
  28. {
  29. CTexManager cTex;
  30. if(!m_myWeapon.InitSMFLoader("model/soldier/mygun.smf",cTex.GetTextureID(TEX_MY_GUN),1))
  31.      return FALSE;
  32. m_texMetal=cTex.GetTextureID(TEX_METAL);
  33. m_texNavigator=cTex.GetTextureID(TEX_NAVIGATOR);
  34. m_texHelp=cTex.GetTextureID(TEX_HELP);
  35. m_cGunFire.InitGunFire(0.8f,1.2f);
  36. m_gunMouth=m_myWeapon.GetPos(SMF_GUN_MOUTH);
  37. return true;
  38. }
  39. void CInfoPanel::DrawInfoPanel()
  40. {
  41. glColor3f(0,1,0);
  42. CHeightmap cHmap;
  43. double dist=sqrt(cHmap.m_distFromFocus);
  44. glEnable(GL_CULL_FACE);
  45.     glEnable(GL_LIGHTING);
  46. // DrawMyWeapon();
  47.     glDisable(GL_LIGHTING);
  48. glDisable(GL_CULL_FACE);
  49. glColor3f(0,1,0);
  50. CImgText::PrintValue(600,10,cHmap.m_ViewPos.xpos);
  51. CImgText::PrintValue(600,30,cHmap.m_ViewPos.ypos);
  52. CImgText::PrintValue(600,50,cHmap.m_ViewPos.zpos);
  53. CImgText::PrintValue(600,70,cHmap.m_ViewRotY);
  54. CImgText::PrintValue(500,10,cHmap.m_numTriangles);
  55.     if(dist<3000)
  56. {
  57. char str[16];
  58. sprintf(str,"%.1fm",dist/4);
  59. CImgText::PrintString(400,300,str);
  60. }
  61. else 
  62. CImgText::PrintString(400,300,"3Km+");
  63. /////////////////////draw cursor
  64. glBegin(GL_LINES);
  65.     glVertex3f(0,      12,CImgText::GetTextDist());
  66.         glVertex3f(0,      4,CImgText::GetTextDist());
  67.         glVertex3f(0,      -4,CImgText::GetTextDist());
  68.         glVertex3f(0,      -12,CImgText::GetTextDist());
  69.     glVertex3f(12,      0,CImgText::GetTextDist());
  70.         glVertex3f(4,      0,CImgText::GetTextDist());
  71.         glVertex3f(-4,     0,CImgText::GetTextDist());
  72.         glVertex3f(-12,      0,CImgText::GetTextDist());
  73.     glEnd();
  74. //////////////////Draw navigator
  75. if(CInput::m_keys[CGameSetting::m_iKeyHelp])
  76. {
  77. CInput::m_keys[CGameSetting::m_iKeyHelp]=false;
  78. m_bHelpOpen=!m_bHelpOpen;
  79. }
  80. if(m_bHelpOpen)
  81. {
  82.     if(CInput::m_keys[VK_ESCAPE])
  83. {
  84.     CInput::m_keys[VK_ESCAPE]=false;
  85.     m_bHelpOpen=false;
  86. }
  87. }
  88. glColor3f(1,1,1);
  89. glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_COLOR);
  90.     glEnable(GL_BLEND);
  91.     glBindTexture(GL_TEXTURE_2D,m_texNavigator);
  92. glEnable(GL_TEXTURE_2D);
  93. glBegin(GL_QUADS);
  94. glTexCoord2f(0,0);
  95.     glVertex3f(-384, -156 ,CImgText::GetTextDist());
  96. glTexCoord2f(1,0);
  97.     glVertex3f(-256, -156 ,CImgText::GetTextDist());
  98. glTexCoord2f(1,1);
  99.     glVertex3f(-256, -284 ,CImgText::GetTextDist());
  100. glTexCoord2f(0,1);
  101.     glVertex3f(-384, -284 ,CImgText::GetTextDist());
  102. glEnd();
  103.     //////////////////////
  104.     glDisable(GL_BLEND);
  105. if(m_bHelpOpen)
  106. {
  107.     glBindTexture(GL_TEXTURE_2D,m_texHelp);
  108.         glBegin(GL_QUADS);
  109. glTexCoord2f(0,0);
  110.     glVertex3f(-380, 20 ,CImgText::GetTextDist());
  111. glTexCoord2f(1,0);
  112.     glVertex3f(-124, 20 ,CImgText::GetTextDist());
  113. glTexCoord2f(1,1);
  114.     glVertex3f(-124, 276 ,CImgText::GetTextDist());
  115. glTexCoord2f(0,1);
  116.     glVertex3f(-380, 276 ,CImgText::GetTextDist());
  117.      glEnd();
  118. }
  119.     glDisable(GL_TEXTURE_2D);
  120. glPointSize(2);
  121. float x,y;
  122. glBegin(GL_POINTS);
  123. for(int i=0;i<m_cHmap.m_numSoldier;i++)
  124. {
  125. GetNavigatorPos(&m_cHmap.m_soldierPos[i],&x,&y);
  126. if(x !=0)
  127. {
  128. if(m_cHmap.m_soldierHealth[i]>0)
  129.         glColor3f(1,0,0);
  130. else
  131. glColor3f(1,1,0);
  132. glVertex3f(x,y,CImgText::GetTextDist());
  133. }
  134. }
  135. glEnd();
  136.     /////////////////
  137. glColor3f(1,1,1);
  138. }
  139. void CInfoPanel::DrawMyWeapon()
  140. {
  141. if(m_cHmap.m_bAttack)
  142. {
  143. m_bFire=!m_bFire;
  144.     m_gunBiasAngleX += 50;
  145.     if(m_gunBiasAngleX>360)m_gunBiasAngleX-=360;
  146. }
  147. else
  148. {
  149. m_bFire=false;
  150.     m_gunBiasAngleY+= 4;
  151.     if(m_gunBiasAngleY>360)m_gunBiasAngleY-=360;
  152. }
  153. m_gunBiasX=sinf(m_gunBiasAngleX*0.0174533f)*0.02f;
  154. m_gunBiasY=sinf(m_gunBiasAngleY*0.0174533f)*0.03f;
  155. if(!m_bFire)m_gunBiasZ=0;
  156. else m_gunBiasZ=0.02f;
  157. ////////////////////////draw gun
  158. /* glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
  159. glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
  160.     glBindTexture(GL_TEXTURE_2D,m_texMetal);
  161. glEnable(GL_TEXTURE_GEN_S);
  162. glEnable(GL_TEXTURE_GEN_T);
  163.     glBlendFunc(GL_SRC_ALPHA,GL_ONE);
  164.     glEnable(GL_BLEND);*/
  165.     glPushMatrix();   
  166. glTranslatef(m_gunBiasX,m_gunBiasY,m_gunBiasZ);
  167. m_myWeapon.RenderOneFrame(0);
  168.     glPopMatrix();
  169.  
  170. /*
  171. glDisable(GL_TEXTURE_GEN_S);
  172. glDisable(GL_TEXTURE_GEN_T);
  173.     glDisable(GL_BLEND);*/
  174. /////////////////////////draw gun fire
  175. CHeightmap::m_numTriangles += 698 ;
  176. if(!m_bFire)return;
  177.     glPushMatrix();  
  178. glTranslatef(m_gunMouth.xpos,m_gunMouth.ypos+m_gunBiasY,m_gunMouth.zpos);
  179.     m_cGunFire.DrawGunFire();
  180. //////////////end draw
  181.     glPopMatrix();
  182. /////////////// Gun mouth
  183. CHeightmap::m_numTriangles += 2 ;
  184. }
  185. void  CInfoPanel::GetNavigatorPos(VERTEX *Pos,float *x,float *y)
  186. {
  187.     //////// translation
  188.     VERTEX v0=VERTEX(Pos->xpos - m_cHmap.m_ViewPos.xpos,
  189.                  Pos->ypos - m_cHmap.m_ViewPos.ypos,
  190.                  Pos->zpos - m_cHmap.m_ViewPos.zpos);
  191.     //////// y rotate
  192.     VERTEX v1=VERTEX(v0.xpos*cosf(m_cHmap.m_ViewRotY*0.0174533f)-
  193.                      v0.zpos*sinf(m_cHmap.m_ViewRotY*0.0174533f),
  194.                  v0.ypos,
  195.                      v0.xpos*sinf(m_cHmap.m_ViewRotY*0.0174533f)+
  196.                      v0.zpos*cosf(m_cHmap.m_ViewRotY*0.0174533f));
  197.     if(v1.xpos>1280 || v1.xpos<-1280 || v1.zpos>1280 || v1.zpos<-1280)
  198. {
  199. *x=0;
  200. return ;
  201. }
  202. *x=v1.xpos*0.05f-320;
  203. *y=-220-v1.zpos*0.05f;
  204. }