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

游戏引擎

开发平台:

Visual C++

  1. // Rocket.cpp: implementation of the CRocket class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Rocket.h"
  6. #include "math.h"
  7. //////////////////////////////////////////////////////////////////////
  8. // Construction/Destruction
  9. //////////////////////////////////////////////////////////////////////
  10. CRocket::CRocket()
  11. {
  12.     m_life=0;
  13. m_Speed=10.0f;
  14. listPos=0;
  15. m_bHit=false;
  16. }
  17. CRocket::~CRocket()
  18. {
  19. }
  20. bool CRocket::InitRocket(VERTEX  startPos,float rotx,float roty,NORMAL direction,unsigned int texid )
  21. {
  22. m_texid=texid;
  23.     m_CurPos=startPos;
  24. m_oldPos=startPos;
  25. m_rotX=rotx;
  26. m_rotY=roty;
  27. m_rotZ=0;
  28.     m_direction = direction;
  29. m_life=400;
  30.     m_bHit=false;
  31. for(int i=0;i<P_MAXNUM;i++)
  32. m_particle[i].life=0;
  33. return true;
  34. }
  35. void CRocket::UpdateRocket()
  36. {
  37. if(m_bHit)return;
  38. m_oldPos=m_CurPos;
  39. m_CurPos.xpos+=m_direction.nx*m_Speed;
  40. m_CurPos.ypos+=m_direction.ny*m_Speed;
  41. m_CurPos.zpos+=m_direction.nz*m_Speed;
  42.     if(m_cHmap.CollideCheck(m_oldPos,m_CurPos,1))
  43. {
  44. m_life=150;
  45. m_bHit=true;
  46.     m_ptcExplosion.InitParticle(EXPLOSION_P,m_CurPos);
  47. }
  48.     else 
  49. {
  50. m_life--;
  51.         Flamethrow();
  52. }
  53. }
  54. void  CRocket::DrawRocket()
  55. {
  56. if(m_bHit)
  57. {
  58. DrawExplosion();
  59. m_life--;
  60. }
  61. else DrawSmokeTail();
  62. }
  63. void  CRocket::DrawExplosion()
  64. {
  65.     glPushMatrix();
  66. glTranslatef(m_CurPos.xpos,m_CurPos.ypos,m_CurPos.zpos);
  67. glRotatef(*m_cHmap.m_pViewRotY,  0.0f,1.0f,0.0f);
  68. glRotatef(-*m_cHmap.m_pViewRotX,  1.0f,0.0f,0.0f);
  69.         m_ptcExplosion.DrawParticles(m_CurPos);
  70.     glPopMatrix();
  71. }
  72. void  CRocket::DrawSmokeTail()
  73. {
  74.     ////////here draw rocket
  75. glDisable(GL_CULL_FACE);
  76. glEnable(GL_TEXTURE_2D);
  77.   glBindTexture(GL_TEXTURE_2D,m_texid);
  78. glBlendFunc(GL_SRC_ALPHA,GL_ONE);
  79. // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  80. glEnable(GL_BLEND);
  81. // glEnable(GL_ALPHA_TEST);
  82. ////////draw smoke
  83.     for(int i=listPos;i>-1;i--)
  84. {
  85. if(m_particle[i].life>0)
  86. {
  87. glPushMatrix();
  88. glTranslatef(m_particle[i].pos.xpos, m_particle[i].pos.ypos, m_particle[i].pos.zpos);
  89.             glRotated( m_rotY,0,1,0);
  90.             glRotated(-m_rotX,1,0,0);
  91. //         glRotatef(*m_cHmap.m_pViewRotY,  0.0f,1.0f,0.0f);
  92. //         glRotatef(-*m_cHmap.m_pViewRotX,  1.0f,0.0f,0.0f);
  93. glColor4d(0.5f,0.5f,0.5f,m_particle[i].life);
  94. glBegin(GL_QUADS);
  95.         glTexCoord2d(0,0);       
  96.     glVertex3f(-m_particle[i].size,-m_particle[i].size,0);
  97.         glTexCoord2d(1,0); 
  98. glVertex3f( m_particle[i].size,-m_particle[i].size,0);
  99.         glTexCoord2d(1,1);      
  100. glVertex3f( m_particle[i].size, m_particle[i].size,0);
  101.         glTexCoord2d(0,1);      
  102. glVertex3f(-m_particle[i].size, m_particle[i].size,0);
  103.             glEnd();
  104. glPopMatrix();
  105. }
  106. }
  107.     for( i=P_MAXNUM;i>listPos;i--)
  108. {
  109. if(m_particle[i].life>0)
  110. {
  111. glPushMatrix();
  112. glTranslatef(m_particle[i].pos.xpos, m_particle[i].pos.ypos, m_particle[i].pos.zpos);
  113.             glRotated( m_rotY,0,1,0);
  114.             glRotated(-m_rotX,1,0,0);
  115. glColor4d(0.5f,0.5f,0.5f,m_particle[i].life);
  116. glBegin(GL_QUADS);
  117.         glTexCoord2d(0,0);       
  118.     glVertex3f(-m_particle[i].size,-m_particle[i].size,0);
  119.         glTexCoord2d(1,0); 
  120. glVertex3f( m_particle[i].size,-m_particle[i].size,0);
  121.         glTexCoord2d(1,1);      
  122. glVertex3f( m_particle[i].size, m_particle[i].size,0);
  123.         glTexCoord2d(0,1);      
  124. glVertex3f(-m_particle[i].size, m_particle[i].size,0);
  125.             glEnd();
  126. glPopMatrix();
  127. }
  128. }
  129. glDisable(GL_BLEND);
  130. glDisable(GL_ALPHA_TEST);
  131. glEnable(GL_CULL_FACE);
  132. glColor3f(1,1,1);
  133. listPos++;
  134. if(listPos>(P_MAXNUM-1))listPos=0;
  135. }
  136. void CRocket::Flamethrow()
  137. {
  138.     for(int i=0;i<P_MAXNUM;i++)
  139. {
  140. if(m_particle[i].life>0)
  141. {
  142. m_particle[i].life-=0.1f;
  143. m_particle[i].size+=0.5f;
  144. // m_particle[i].pos.ypos+=(1-m_particle[i].life)*1.0f;
  145. }
  146. }
  147. m_particle[listPos].life = 1;
  148. m_particle[listPos].size = 1.5f;
  149. m_particle[listPos].pos  = m_CurPos; 
  150. }