Particle.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:24k
- // Particle.cpp: implementation of the CParticle class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Particle.h"
- #include "Texture.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- unsigned int *CParticle::m_pTexResource=NULL;
- CParticle::CParticle()
- {
- particle=NULL;
- maxnum=100;
- Type=-1;
- }
- bool CParticle::InitParticle(int type,VERTEX startPos,unsigned int *texResource)
- {
- if(m_pTexResource==NULL)m_pTexResource=texResource;
- if(Type<0)Type=type;
- switch(Type)
- {
- case RIFLE_P:
- maxnum=40;
- break;
- case EXPLOSION_P:
- maxnum=100;
- break;
- case ROCKET_P:
- maxnum=50;
- break;
- case SMOKE_P:
- maxnum=60;
- break;
- }
- if(particle==NULL)
- {
- particle=new PARTICLE[maxnum];
- }
- switch(Type)
- {
- case RIFLE_P:
- InitShotParticle();
- break;
- case EXPLOSION_P:
- InitExpParticle();
- break;
- case ROCKET_P:
- InitBulletParticle( startPos);
- break;
- case SMOKE_P:
- InitSmokeParticle( );
- break;
- }
- return true;
- }
- void CParticle::DrawParticles(VERTEX startPos)
- {
- switch(Type)
- {
- case RIFLE_P:
- DrawShotParticles();
- break;
- case EXPLOSION_P:
- DrawExpParticles( );
- break;
- case ROCKET_P:
- DrawBulletParticles( startPos);
- break;
- case SMOKE_P:
- DrawSmokeParticles();
- break;
- }
- }
- bool CParticle::InitShotParticle()
- {
- smokenum=30;
- for(int i=0 ;i<maxnum;i++)
- {
- particle[i].size =float(rand()%50)*0.001f+0.02f;
- particle[i].pos.xpos = float((rand()%40)*0.1f-2)*particle[i].size;// /75.f;
- particle[i].pos.ypos = float((rand()%40)*0.1f-2)*particle[i].size;
- particle[i].pos.zpos = float((rand()%40)*0.1f-2)*particle[i].size;
- particle[i].rotate = float(rand()%100-50);
- if(i<smokenum)
- {
- particle[i].normal.nx = float((rand()%50)-25)*0.001f;
- particle[i].normal.ny = float((rand()%50)-0 )*0.005f+0.3f;
- particle[i].normal.nz = float((rand()%50)-25)*0.001f;
- particle[i].size =float((rand()%20)*0.01f+0.3f);
- }
- else
- {
- particle[i].normal.nx = float((rand()%50)-25)*0.02f;
- particle[i].normal.ny = float((rand()%50)-0 )*0.01f;
- particle[i].normal.nz = float((rand()%50)-25)*0.02f;
- }
- particle[i].life = 1;
- particle[i].fade =float(rand()%100)/50000 + 0.01f;
- }
- glReadPixels(402,302,5,5,GL_RGB,GL_FLOAT,srccolor);
- srccolor[26][0]=0;
- srccolor[26][1]=0;
- srccolor[26][2]=0;
- for( i=0;i<25;i++)
- {
- srccolor[26][0]+=srccolor[i][0];
- srccolor[26][1]+=srccolor[i][1];
- srccolor[26][2]+=srccolor[i][2];
- }
- srccolor[26][0]=srccolor[26][0]*0.03f;
- srccolor[26][1]=srccolor[26][1]*0.03f;
- srccolor[26][2]=srccolor[26][2]*0.03f;
- return true;
- }
- void CParticle::DrawShotParticles()
- {
- glDisable(GL_CULL_FACE);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- glDisable(GL_TEXTURE_2D);
-
- for(int i=smokenum;i<maxnum;i++)
- {
- if (particle[i].life > 0 && particle[i].pos.ypos>0)
- {
- particle[i].pos.xpos += particle[i].normal.nx;
- particle[i].pos.ypos += particle[i].normal.ny;
- particle[i].pos.zpos += particle[i].normal.nz;
- particle[i].normal.ny -= 0.02f; // cheap simulated gravity
- particle[i].normal.nx *= 0.9f;
- particle[i].normal.ny *= 0.99f;
- particle[i].normal.nz *= 0.9f;
- particle[i].life -= particle[i].fade;
-
- // if(particle[i].rotate>0)
- particle[i].rotate +=4.0f;
- // else
- // particle[i].rotate -=4.0f;
-
- /* glPushMatrix();
-
- glTranslatef(particle[i].pos.xpos, particle[i].pos.ypos, particle[i].pos.zpos);
- glRotated(particle[i].rotate,1,1,1);
- glTranslatef(-particle[i].pos.xpos, -particle[i].pos.ypos, -particle[i].pos.zpos);
- */
- // glColor4d(srccolor[26][0],srccolor[26][1],srccolor[26][2],particle[i].life);
- glColor4f(0,0,0,particle[i].life);
- glBegin(GL_QUADS);
- glTexCoord2d(1,1);
- glVertex3d( particle[i].pos.xpos+particle[i].size,particle[i].pos.ypos+ particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(1,0);
- glVertex3d( particle[i].pos.xpos+particle[i].size,particle[i].pos.ypos-particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(0,0);
- glVertex3d(particle[i].pos.xpos-particle[i].size,particle[i].pos.ypos-particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(0,1);
- glVertex3d(particle[i].pos.xpos-particle[i].size,particle[i].pos.ypos+ particle[i].size,particle[i].pos.zpos);
- glEnd();
- // glPopMatrix();
- }
- }
- //////////////draw smoke
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,m_pTexResource[2] );
- glDisable(GL_DEPTH_TEST);
- // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- // glBlendFunc(GL_SRC_ALPHA,GL_ONE);
- for( i=0;i<smokenum;i++)
- {
- if(i>(smokenum-10))glBlendFunc(GL_SRC_ALPHA,GL_ONE);
- else glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- if (particle[i].life > 0 && particle[i].pos.ypos>0)
- {
- particle[i].pos.xpos += particle[i].normal.nx;
- particle[i].pos.ypos += particle[i].normal.ny;
- particle[i].pos.zpos += particle[i].normal.nz;
- particle[i].normal.ny -= 0.005f; // cheap simulated gravity
- particle[i].normal.nx *= 0.9f;
- particle[i].normal.ny *= 0.9f;
- particle[i].normal.nz *= 0.9f;
- particle[i].life -= particle[i].fade;
-
- glColor4d(0.2f,0.13f,0.0f,particle[i].life);
- // glColor4d(0.95f,0.75f,0.25f,particle[i].life);
- // glColor4d(srccolor[26][0],srccolor[26][1],srccolor[26][2],particle[i].life);
- glBegin(GL_QUADS);
- glTexCoord2d(1,1);
- glVertex3d( particle[i].pos.xpos+particle[i].size,particle[i].pos.ypos+ particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(1,0);
- glVertex3d( particle[i].pos.xpos+particle[i].size,particle[i].pos.ypos-particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(0,0);
- glVertex3d(particle[i].pos.xpos-particle[i].size,particle[i].pos.ypos-particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(0,1);
- glVertex3d(particle[i].pos.xpos-particle[i].size,particle[i].pos.ypos+ particle[i].size,particle[i].pos.zpos);
- glEnd();
- }
- }
- glDisable(GL_ALPHA_TEST);
- glColor4d(1,1,1,1);
- glEnable(GL_DEPTH_TEST);
- glDisable(GL_BLEND);
- }
- bool CParticle::InitExpParticle()
- {
- smokenum=30;
- rocknum=70;
- for(int i=0 ;i<maxnum;i++)
- {
- particle[i].size =float(rand()%50)*0.001f+0.05f;
-
- particle[i].pos.xpos = float((rand()%4)-2)*particle[i].size;// /75.f;
- particle[i].pos.ypos = float((rand()%4)-2)*particle[i].size;
- particle[i].pos.zpos = float(i-maxnum/2)*0.1f;
- particle[i].rotate = float(i);
- if(i<smokenum)
- {
- particle[i].normal.nx = float((rand()%50)-25)*0.015f;
- if(i>20)
- {
- particle[i].normal.nx = float((rand()%50)-25)*0.002f;
- particle[i].normal.ny = float((rand()%50)-0)*0.04f+0.1f;
- particle[i].fade =float(rand()%100)*0.00001f + 0.01f;
- }
- else
- {
- particle[i].normal.nx = float((rand()%50)-25)*0.01f;
- particle[i].normal.ny = float((rand()%50)-0)*0.08f;
- particle[i].fade =float(rand()%100)*0.00001f + 0.001f;
- }
- particle[i].normal.nz = 0;//float((rand()%50)-25)*0.006f;
- particle[i].size =float((rand()%40)*0.1f+12);
- }
- else if(i<rocknum)
- {
- particle[i].normal.nx = float((rand()%50)-25)*0.04f;
- particle[i].normal.ny = float((rand()%35)-0)*0.12f;
- particle[i].normal.nz = float((rand()%50)-25)*0.04f;
- particle[i].fade =float(rand()%100)*0.00005f + 0.0001f;
- particle[i].size =float(rand()%50)*0.001f+0.1f;
- }
- else
- {
- particle[i].normal.nx = float((rand()%50)-25)*0.07f;
- particle[i].normal.ny = float((rand()%35)-0)*0.8f;
- particle[i].normal.nz = float((rand()%50)-25)*0.07f;
- particle[i].fade =float(rand()%100)*0.00005f + 0.0001f;
- }
- particle[i].life = 1;
- }
- /*
- glReadPixels(402,302,5,5,GL_RGB,GL_FLOAT,srccolor);
- srccolor[26][0]=0;
- srccolor[26][1]=0;
- srccolor[26][2]=0;
- for( i=0;i<25;i++)
- {
- srccolor[26][0]+=srccolor[i][0];
- srccolor[26][1]+=srccolor[i][1];
- srccolor[26][2]+=srccolor[i][2];
- }
- srccolor[26][0]=srccolor[26][0]*0.04f;
- srccolor[26][1]=srccolor[26][1]*0.04f;
- srccolor[26][2]=srccolor[26][2]*0.04f; */
- return true;
- }
- void CParticle::DrawExpParticles()
- {
- glDisable(GL_CULL_FACE);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,m_pTexResource[1] );
- for(int i=smokenum;i<maxnum;i++)
- {
- if (particle[i].life > 0)
- {
- if(particle[i].life > 0.4)
- glDisable(GL_BLEND);
- else glEnable(GL_BLEND);
- particle[i].pos.xpos += particle[i].normal.nx;
- particle[i].pos.ypos += particle[i].normal.ny;
- particle[i].pos.zpos += particle[i].normal.nz;
- particle[i].normal.ny -= 0.08f; // cheap simulated gravity
- particle[i].normal.nx *= 0.99f;
- particle[i].normal.ny *= 0.99f;
- particle[i].normal.nz *= 0.99f;
- particle[i].life -= particle[i].fade;
- particle[i].rotate +=6.0f;
-
- glPushMatrix();
-
- glTranslatef(particle[i].pos.xpos, particle[i].pos.ypos, particle[i].pos.zpos);
- glRotated(particle[i].rotate,1.f,0,0);
- glTranslatef(-particle[i].pos.xpos, -particle[i].pos.ypos, -particle[i].pos.zpos);
-
- glColor4d(1,1,1,1);//particle[i].life);
- //glColor4d(srccolor[26][0],srccolor[26][1],srccolor[26][2],particle[i].life);
- /////////// rock
- if(i<rocknum)
- {
- glBegin(GL_TRIANGLE_STRIP);
- glTexCoord2d(0,0);
- glVertex3d(particle[i].pos.xpos-particle[i].size*2, particle[i].pos.ypos-particle[i].size*2, particle[i].pos.zpos-particle[i].size*2);
- glTexCoord2d(0,1);
- glVertex3d(particle[i].pos.xpos-particle[i].size*2, particle[i].pos.ypos+particle[i].size*2, particle[i].pos.zpos-particle[i].size*2);
- glTexCoord2d(1,0);
- glVertex3d(particle[i].pos.xpos+particle[i].size*2, particle[i].pos.ypos-particle[i].size*1.5f, particle[i].pos.zpos-particle[i].size*2);
- glTexCoord2d(1,1);
- glVertex3d(particle[i].pos.xpos+particle[i].size*2, particle[i].pos.ypos+particle[i].size, particle[i].pos.zpos-particle[i].size*2);
-
- glTexCoord2d(0,0);
- glVertex3d(particle[i].pos.xpos+particle[i].size*1.5f, particle[i].pos.ypos-particle[i].size*1.2f, particle[i].pos.zpos+particle[i].size*1.3f);
- glTexCoord2d(0,1);
- glVertex3d(particle[i].pos.xpos+particle[i].size*1.5f, particle[i].pos.ypos+particle[i].size*0.3f, particle[i].pos.zpos+particle[i].size*1);
- glTexCoord2d(1,0);
- glVertex3d(particle[i].pos.xpos, particle[i].pos.ypos-particle[i].size*1.9f, particle[i].pos.zpos+particle[i].size*2.0f);
- glTexCoord2d(1,1);
- glVertex3d(particle[i].pos.xpos, particle[i].pos.ypos+particle[i].size*1.3f, particle[i].pos.zpos+particle[i].size*2.2f);
- glTexCoord2d(0,0);
- glVertex3d(particle[i].pos.xpos-particle[i].size*2, particle[i].pos.ypos-particle[i].size*2, particle[i].pos.zpos-particle[i].size*2);
- glTexCoord2d(0,1);
- glVertex3d(particle[i].pos.xpos-particle[i].size*2, particle[i].pos.ypos+particle[i].size*2, particle[i].pos.zpos-particle[i].size*2);
- glEnd();
- glBegin(GL_TRIANGLE_FAN);
- glTexCoord2d(0,0);
- glVertex3d(particle[i].pos.xpos-particle[i].size*2, particle[i].pos.ypos-particle[i].size*2, particle[i].pos.zpos-particle[i].size*2);
- glTexCoord2d(0,1);
- glVertex3d(particle[i].pos.xpos+particle[i].size*2, particle[i].pos.ypos-particle[i].size*1.5f, particle[i].pos.zpos-particle[i].size*2);
-
- glTexCoord2d(1,1);
- glVertex3d(particle[i].pos.xpos+particle[i].size*1.5f, particle[i].pos.ypos-particle[i].size*1.2f, particle[i].pos.zpos+particle[i].size*1.3f);
- glTexCoord2d(1,0);
- glVertex3d(particle[i].pos.xpos, particle[i].pos.ypos-particle[i].size*1.9f, particle[i].pos.zpos+particle[i].size*2.0f);
- glEnd();
- glBegin(GL_TRIANGLE_FAN);
- glTexCoord2d(0,0);
- glVertex3d(particle[i].pos.xpos-particle[i].size*2, particle[i].pos.ypos+particle[i].size*2, particle[i].pos.zpos-particle[i].size*2);
- glTexCoord2d(1,0);
- glVertex3d(particle[i].pos.xpos+particle[i].size*2, particle[i].pos.ypos+particle[i].size, particle[i].pos.zpos-particle[i].size*2);
- glTexCoord2d(1,1);
- glVertex3d(particle[i].pos.xpos+particle[i].size*1.5f, particle[i].pos.ypos+particle[i].size*0.3f, particle[i].pos.zpos+particle[i].size*1);
- glTexCoord2d(0,1);
- glVertex3d(particle[i].pos.xpos, particle[i].pos.ypos+particle[i].size*1.3f, particle[i].pos.zpos+particle[i].size*2.2f);
- glEnd();
- }else
- {
-
- glBegin(GL_TRIANGLE_FAN);
- glTexCoord2d(1,0);
- glVertex3d(particle[i].pos.xpos, particle[i].pos.ypos, particle[i].pos.zpos);
- glTexCoord2d(1,1);
- glVertex3d(particle[i].pos.xpos+particle[i].size, particle[i].pos.ypos, particle[i].pos.zpos);
- glTexCoord2d(0,1);
- glVertex3d(particle[i].pos.xpos+particle[i].size*1.2f, particle[i].pos.ypos+particle[i].size, particle[i].pos.zpos);
- glTexCoord2d(1,1);
- glVertex3d(particle[i].pos.xpos+particle[i].size*0.4f, particle[i].pos.ypos+particle[i].size*2, particle[i].pos.zpos);
- glEnd();
- }
- glPopMatrix();
- }
- }
- //////////////draw smoke
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,m_pTexResource[2] );
- // glDisable(GL_DEPTH_TEST);
- glEnable(GL_BLEND);
- //
- for( i=0;i<smokenum;i++)
- {
- if(i>20)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
- else glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- if (particle[i].life > 0 && particle[i].pos.ypos>0)
- {
- particle[i].pos.xpos += particle[i].normal.nx;
- particle[i].pos.ypos += particle[i].normal.ny;
- particle[i].pos.zpos += particle[i].normal.nz;
- particle[i].normal.ny -= 0.03f; // cheap simulated gravity
- particle[i].normal.nx *= 0.9f;
- particle[i].normal.ny *= 0.9f;
- particle[i].normal.nz *= 0.9f;
- particle[i].life -= particle[i].fade;
-
- // glColor4d(0.28f,0.27f,0.25f,particle[i].life);
- glColor4d(0.6f,0.45f,0.2f,particle[i].life);
- // glColor4d(srccolor[26][0],srccolor[26][1],srccolor[26][2],particle[i].life);
- glBegin(GL_QUADS);
- glTexCoord2d(1,1);
- glVertex3d( particle[i].pos.xpos+particle[i].size,particle[i].pos.ypos+ particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(1,0);
- glVertex3d( particle[i].pos.xpos+particle[i].size,particle[i].pos.ypos-particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(0,0);
- glVertex3d(particle[i].pos.xpos-particle[i].size,particle[i].pos.ypos-particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(0,1);
- glVertex3d(particle[i].pos.xpos-particle[i].size,particle[i].pos.ypos+ particle[i].size,particle[i].pos.zpos);
- glEnd();
- }
- }
- glColor4d(1,1,1,1);
- glEnable(GL_DEPTH_TEST);
- glDisable(GL_BLEND);
- }
- /////////////////////////////////////////////////////////
- bool CParticle::InitBulletParticle(VERTEX startPos)
- {
- smokenum=maxnum;
- for(int i=0 ;i<maxnum;i++)
- {
- particle[i].size =float(rand()%80)*0.01f+0.1f;
-
- particle[i].pos.xpos = startPos.xpos+float((rand()%4)-2)*particle[i].size;// /75.f;
- particle[i].pos.ypos = startPos.ypos+float((rand()%4)-2)*particle[i].size;
- particle[i].pos.zpos = startPos.zpos+i*0.1f;
- particle[i].rotate = float(i);
- if(i<smokenum)
- {
- particle[i].normal.nx = float((rand()%50)-25)*0.0f;
- particle[i].normal.ny = float((rand()%25)-0)*0.0f;//+0.1f;
- particle[i].normal.nz = float((rand()%50)-25)*0.0f;
- particle[i].fade =float(rand()%100)*0.01f + 0.05f;
- particle[i].size =float(rand()%100)*0.0005f+0.001f;
- }
- else
- {
- particle[i].normal.nx = float((rand()%50)-25)*0.05f;
- particle[i].normal.ny = float((rand()%50)-25)*0.05f;
- particle[i].normal.nz = float((rand()%50)-25)*0.05f;
- particle[i].fade =float(rand()%100)*0.003f + 0.01f;
- }
- particle[i].life = 1;
- }
-
- return true;
- }
- void CParticle::DrawBulletParticles(VERTEX startPos)
- {
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_CULL_FACE);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,m_pTexResource[1] );
- for(int i=smokenum;i<maxnum;i++)
- {
- if (particle[i].life > 0)
- {
- particle[i].pos.xpos += particle[i].normal.nx;
- particle[i].pos.ypos += particle[i].normal.ny;
- particle[i].pos.zpos += particle[i].normal.nz;
- particle[i].normal.ny -= 0.001f; // cheap simulated gravity
- particle[i].normal.nx *= 0.9f;
- particle[i].normal.ny *= 0.9f;
- particle[i].normal.nz *= 0.9f;
- particle[i].life -= particle[i].fade;
- particle[i].rotate +=6.0f;
- // glColor4d(particle[i].color.r,particle[i].color.g,particle[i].color.b,particle[i].life);
- glColor4d(srccolor[26][0],srccolor[26][1],srccolor[26][2],particle[i].life);
- glBegin(GL_QUADS);
- glTexCoord2d(1,1);
- glVertex3d( particle[i].pos.xpos+particle[i].size,particle[i].pos.ypos+ particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(1,0);
- glVertex3d( particle[i].pos.xpos+particle[i].size,particle[i].pos.ypos-particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(0,0);
- glVertex3d(particle[i].pos.xpos-particle[i].size,particle[i].pos.ypos-particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(0,1);
- glVertex3d(particle[i].pos.xpos-particle[i].size,particle[i].pos.ypos+ particle[i].size,particle[i].pos.zpos);
- glEnd();
- }
- else ResetParticle(i,startPos);
- }
- //////////////draw smoke
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,m_pTexResource[2] );
- glBlendFunc(GL_SRC_ALPHA,GL_ONE);
- // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- for( i=0;i<smokenum;i++)
- {
- if (particle[i].life > 0)
- {
- particle[i].pos.xpos += particle[i].normal.nx;
- particle[i].pos.ypos += particle[i].normal.ny;
- particle[i].pos.zpos += particle[i].normal.nz;
- particle[i].normal.ny += 0.006f; // cheap simulated gravity
- particle[i].normal.nx *= 0.9f;
- particle[i].normal.ny *= 0.9f;
- particle[i].normal.nz *= 0.9f;
- particle[i].life -= particle[i].fade;
-
- // glColor4d(0.1f,0.1f,0.1f,particle[i].life);
- glColor4d(0.2f,0.5f,0.6f,particle[i].life);
- // glColor4d(0.3f,0.23f,0.0f,particle[i].life);
- glBegin(GL_QUADS);
- glTexCoord2d(1,1);
- glVertex3d( particle[i].pos.xpos+particle[i].size,particle[i].pos.ypos+ particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(1,0);
- glVertex3d( particle[i].pos.xpos+particle[i].size,particle[i].pos.ypos-particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(0,0);
- glVertex3d(particle[i].pos.xpos-particle[i].size,particle[i].pos.ypos-particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(0,1);
- glVertex3d(particle[i].pos.xpos-particle[i].size,particle[i].pos.ypos+ particle[i].size,particle[i].pos.zpos);
- glEnd();
- }
- else ResetParticle(i,startPos);
- }
- glColor4d(1,1,1,1);
- glEnable(GL_DEPTH_TEST);
- glDisable(GL_BLEND);
- }
- void CParticle::ResetParticle(int num,VERTEX startPos)
- {
- if(num>(maxnum-1))return;
- particle[num].size =float(rand()%80)*0.01f+0.1f;
-
- particle[num].pos.xpos = startPos.xpos+float((rand()%4)-2)*particle[num].size;// /75.f;
- particle[num].pos.ypos = startPos.ypos+float((rand()%4)-2)*particle[num].size;
- particle[num].pos.zpos = startPos.zpos+float((rand()%4)-2)*particle[num].size;
- particle[num].rotate = float(num);
- if(num<smokenum)
- {
- particle[num].normal.nx = float((rand()%50)-25)*0.04f;
- particle[num].normal.ny = float((rand()%25)-0)*0.04f;//+0.1f;
- particle[num].normal.nz = float((rand()%50)-25)*0.04f;
- particle[num].fade =float(rand()%100)*0.004f + 0.02f;
- particle[num].size =float(rand()%100)*0.01f+0.3f;
- }
- else
- {
- particle[num].normal.nx = float((rand()%50)-25)*0.05f;
- particle[num].normal.ny = float((rand()%50)-25)*0.05f;
- particle[num].normal.nz = float((rand()%50)-25)*0.05f;
- particle[num].fade =float(rand()%100)*0.008f + 0.015f;
- }
- particle[num].life = 1;
- }
- /////////////////////////////////////////////////////////
- bool CParticle::InitSmokeParticle()
- {
- for(int i=0 ;i<maxnum;i++)
- {
- particle[i].size =float(rand()%80)*0.01f+1;
-
- particle[i].pos.xpos = 0;// /75.f;
- particle[i].pos.ypos = 0;
- particle[i].pos.zpos = float(i-maxnum/2)*0.1f;
- particle[i].normal.nx = float((rand()%50)-25)*0.004f;
- particle[i].normal.ny = float((rand()%50)-0)*0.04f+0.1f;
- particle[i].fade =float(rand()%100)*0.003f + 0.01f;
- particle[i].life = 1;
- }
-
- return true;
- }
- void CParticle::DrawSmokeParticles()
- {
- //////////////draw smoke
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D,m_pTexResource[3] );
- glEnable(GL_BLEND);
- for(int i=0;i<maxnum;i++)
- {
- // if(i>20)glBlendFunc(GL_SRC_ALPHA,GL_ONE);
- // else
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- if (particle[i].life > 0)
- {
- particle[i].pos.xpos += particle[i].normal.nx;
- particle[i].pos.ypos += particle[i].normal.ny;
- // particle[i].pos.zpos += particle[i].normal.nz;
- // particle[i].normal.ny += 0.003f; // cheap simulated gravity
- particle[i].normal.nx *= 1.01f;
- particle[i].normal.ny *= 0.96f;
- // particle[i].normal.nz *= 0.9f;
- particle[i].size *=1.02f;
- particle[i].life -= particle[i].fade;
-
- glColor4d(0.5f,0.5f,0.5f,particle[i].life);
- glBegin(GL_QUADS);
- glTexCoord2d(1,1);
- glVertex3d( particle[i].pos.xpos+particle[i].size,particle[i].pos.ypos+ particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(1,0);
- glVertex3d( particle[i].pos.xpos+particle[i].size,particle[i].pos.ypos-particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(0,0);
- glVertex3d(particle[i].pos.xpos-particle[i].size,particle[i].pos.ypos-particle[i].size,particle[i].pos.zpos);
- glTexCoord2d(0,1);
- glVertex3d(particle[i].pos.xpos-particle[i].size,particle[i].pos.ypos+ particle[i].size,particle[i].pos.zpos);
- glEnd();
- }
- else ResetSmokeParticle(i);
- }
- glColor4d(1,1,1,1);
- glDisable(GL_BLEND);
- }
- void CParticle::ResetSmokeParticle(int num)
- {
- if(num>(maxnum-1))return;
- particle[num].size =float(rand()%100)*0.01f+2;
-
- particle[num].pos.xpos = 0;// /75.f;
- particle[num].pos.ypos = 0;
- particle[num].pos.zpos = float(num-maxnum/2)*0.1f;
- particle[num].normal.nx =-float((rand()%50)-0)*0.004f;
- particle[num].normal.ny = float((rand()%50)-0)*0.04f+0.2f;
- particle[num].fade =float(rand()%100)*0.0001f + 0.01f;
- particle[num].life = 1;
-
- }
- CParticle::~CParticle()
- {
- if(particle!=NULL)
- delete [] particle;
- }