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=30.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. ///////////////////////////////////////
  34. return true;
  35. }
  36. void CRocket::UpdateRocket()
  37. {
  38. if(m_bHit)return;
  39. m_oldPos=m_CurPos;
  40. m_CurPos.xpos+=m_direction.nx*m_Speed;
  41. m_CurPos.ypos+=m_direction.ny*m_Speed;
  42. m_CurPos.zpos+=m_direction.nz*m_Speed;
  43.     if(m_cHmap.CollideCheck(m_oldPos,m_CurPos,0,1))
  44. {
  45. m_life=150;
  46. m_bHit=true;
  47.     m_ptcExplosion.InitParticle(EXPLOSION_P,m_oldPos);
  48. }
  49.     else 
  50. {
  51. m_life--;
  52.         Flamethrow();
  53. }
  54. }
  55. void  CRocket::DrawRocket()
  56. {
  57. if(m_bHit)
  58. {
  59. DrawExplosion();
  60. m_life--;
  61. }
  62. else DrawSmokeTail();
  63. }
  64. void  CRocket::DrawExplosion()
  65. {
  66.     glPushMatrix();
  67. glTranslatef(m_CurPos.xpos,m_CurPos.ypos,m_CurPos.zpos);
  68. glRotatef(*m_cHmap.m_pViewRotY,  0.0f,1.0f,0.0f);
  69. glRotatef(-*m_cHmap.m_pViewRotX,  1.0f,0.0f,0.0f);
  70.         m_ptcExplosion.DrawParticles(m_CurPos);
  71.     glPopMatrix();
  72. }
  73. void  CRocket::DrawSmokeTail()
  74. {
  75.     ////////here draw rocket
  76. glDisable(GL_CULL_FACE);
  77. glEnable(GL_TEXTURE_2D);
  78.   glBindTexture(GL_TEXTURE_2D,m_texid);
  79. glBlendFunc(GL_SRC_ALPHA,GL_ONE);
  80. // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  81. glEnable(GL_BLEND);
  82. // glEnable(GL_ALPHA_TEST);
  83. ////////draw smoke
  84.     for(int i=listPos;i>-1;i--)
  85. {
  86. if(m_particle[i].life>0)
  87. {
  88. glPushMatrix();
  89. glTranslatef(m_particle[i].pos.xpos, m_particle[i].pos.ypos, m_particle[i].pos.zpos);
  90.             glRotated( m_rotY,0,1,0);
  91.             glRotated(-m_rotX,1,0,0);
  92. //         glRotatef(*m_cHmap.m_pViewRotY,  0.0f,1.0f,0.0f);
  93. //         glRotatef(-*m_cHmap.m_pViewRotX,  1.0f,0.0f,0.0f);
  94. glColor4d(0.5f,0.5f,0.5f,m_particle[i].life);
  95. glBegin(GL_QUADS);
  96.         glTexCoord2d(0,0);       
  97.     glVertex3f(-m_particle[i].size,-m_particle[i].size,0);
  98.         glTexCoord2d(1,0); 
  99. glVertex3f( m_particle[i].size,-m_particle[i].size,0);
  100.         glTexCoord2d(1,1);      
  101. glVertex3f( m_particle[i].size, m_particle[i].size,0);
  102.         glTexCoord2d(0,1);      
  103. glVertex3f(-m_particle[i].size, m_particle[i].size,0);
  104.             glEnd();
  105. glPopMatrix();
  106. }
  107. }
  108.     for( i=P_MAXNUM;i>listPos;i--)
  109. {
  110. if(m_particle[i].life>0)
  111. {
  112. glPushMatrix();
  113. glTranslatef(m_particle[i].pos.xpos, m_particle[i].pos.ypos, m_particle[i].pos.zpos);
  114.             glRotated( m_rotY,0,1,0);
  115.             glRotated(-m_rotX,1,0,0);
  116. glColor4d(0.5f,0.5f,0.5f,m_particle[i].life);
  117. glBegin(GL_QUADS);
  118.         glTexCoord2d(0,0);       
  119.     glVertex3f(-m_particle[i].size,-m_particle[i].size,0);
  120.         glTexCoord2d(1,0); 
  121. glVertex3f( m_particle[i].size,-m_particle[i].size,0);
  122.         glTexCoord2d(1,1);      
  123. glVertex3f( m_particle[i].size, m_particle[i].size,0);
  124.         glTexCoord2d(0,1);      
  125. glVertex3f(-m_particle[i].size, m_particle[i].size,0);
  126.             glEnd();
  127. glPopMatrix();
  128. }
  129. }
  130. glDisable(GL_BLEND);
  131. glDisable(GL_ALPHA_TEST);
  132. glEnable(GL_CULL_FACE);
  133. glColor3f(1,1,1);
  134. listPos++;
  135. if(listPos>(P_MAXNUM-1))listPos=0;
  136. }
  137. void CRocket::Flamethrow()
  138. {
  139.     for(int i=0;i<P_MAXNUM;i++)
  140. {
  141. if(m_particle[i].life>0)
  142. {
  143. m_particle[i].life-=0.1f;
  144. m_particle[i].size+=0.5f;
  145. //m_particle[i].pos.ypos+=(1-m_particle[i].life)*1.0f;
  146. }
  147. }
  148. m_particle[listPos].life = 1;
  149. m_particle[listPos].size = 1.5f;
  150. m_particle[listPos].pos  = m_CurPos; 
  151. }