01 #ifndef PARTICS_HH 02 #define PARTICS_HH 21 03 #include "Primtives3D.HC"; 04 class CParticle:CQue { 05 F64 start_tS; 06 F64 duration; 07 I64 color; 08 F64 x,y,z; 09 F64 rotx,roty,rotz; 10 F64 dx,dy,dz; 11 F64 drotx,droty,drotz; 12 F64 decay; 13 CD6 *mesh; 14 F64 _scale; 15 }; 16 U0 UpdateParticles() { 17 CParticle *head=&game.particles; 18 CParticle *next,*cur; 19 F64 now=Game_tS,drag; 20 for(cur=head->next;cur!=head;cur=next) { 21 next=cur->next; 22 if(now-cur->start_tS>=cur->duration) { 23 QueRem(cur); 24 } else { 25 //Grow big then small. 26 cur->_scale=Sin((now-cur->start_tS)/cur->duration*pi); 27 cur->x+=cur->dx; 28 cur->y+=cur->dy; 29 cur->z+=cur->dz; 30 31 cur->rotx+=cur->drotx; 32 cur->roty+=cur->droty; 33 cur->rotz+=cur->drotz; 34 35 cur->dx*=drag=cur->decay; 36 cur->dy*=drag; 37 cur->dz*=drag; 38 39 cur->rotx*=drag; 40 cur->roty*=drag; 41 cur->rotz*=drag; 42 } 43 } 44 } 45 46 U0 DrawParticles(CDC *dc) { 47 CParticle *head=&game.particles; 48 CParticle *cur; 49 I64 mat[16]; 50 for(cur=head->next;cur!=head;cur=cur->next) { 51 Mat4x4IdentEqu(mat); 52 Mat4x4RotX(mat,cur->rotx); 53 Mat4x4RotY(mat,cur->roty); 54 Mat4x4RotZ(mat,cur->rotz); 55 Mat4x4Scale(mat,cur->_scale); 56 Mat4x4TranslationEqu(mat,cur->x,cur->y,cur->z); 57 if(cur->color==-1) 58 dc->color=RandU16&7+7; 59 else 60 dc->color=cur->color; 61 dc->thick=1; 62 CD6Draw(cur->mesh,0,0,0,dc,mat); 63 } 64 } 65 //-1 for random 66 CParticle *ParticleNew(F64 x,F64 y,F64 angle,F64 force,I64 color=-1) { 67 F64 z=1; 68 CParticle *p=GCCAlloc(sizeof(CParticle)); 69 angle+=(Rand-Rand); 70 p->mesh=PrimitiveRect3D(25,25,25); 71 p->x=x; 72 p->y=y; 73 p->z=z; 74 p->decay=.99; 75 p->duration=1.5; 76 p->start_tS=Game_tS; 77 p->color=color; 78 p->dx=force*Cos(angle); 79 p->dy=force*Sin(angle); 80 p->dz=force*(Rand-Rand)/2.; //??? 81 p->rotx=(Rand*Rand)*2*pi/30.*force; 82 p->drotx=(Rand*Rand)*2*pi/30.*force; 83 p->droty=(Rand*Rand)*2*pi/30.*force; 84 p->drotz=(Rand*Rand)*2*pi/30.*force; 85 QueIns(p,&game.particles); 86 return p; 87 } 88 #endif