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