00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "gSparks.h"
00029 #include "eTimer.h"
00030 #include "rRender.h"
00031 #include "tRandom.h"
00032
00033 #ifdef USEPARTICLES
00034 #include "papi.h"
00035 #endif
00036
00037 bool white_sparks=false;
00038
00039 gSpark::gSpark(eGrid *grid, const eCoord &pos,const eCoord &dir,REAL time,REAL ocolor_r,REAL ocolor_g,REAL ocolor_b,REAL ecolor_r,REAL ecolor_g,REAL ecolor_b)
00040 :eReferencableGameObject(grid, pos, dir , NULL, true),
00041
00042 createTime(time){
00043 lastTime=createTime;
00044
00045 #ifndef USEPARTICLES
00046 sparkowncolor_r=ocolor_r;
00047 sparkowncolor_g=ocolor_g;
00048 sparkowncolor_b=ocolor_b;
00049
00050 sparkenemycolor_r=ecolor_r;
00051 sparkenemycolor_g=ecolor_g;
00052 sparkenemycolor_b=ecolor_b;
00053
00054 for (int i=SPARKS-1;i>=0;i--){
00055 lastX[i]=preLastX[i]=x[i]=Vec3(pos.x,pos.y,.5);
00056
00057 static const REAL fak=4;
00058
00059 tRandomizer & randomizer = tRandomizer::GetInstance();
00060 REAL a=fak*( randomizer.Get() - .5f );
00061 REAL b=fak*( randomizer.Get() - .5f );
00062
00063
00064 REAL c=1;
00065
00066 eCoord xy(eCoord(c,b).Turn(dir));
00067
00068 xDot[i]=Vec3(xy.x,xy.y,a);
00069 xDot[i]=xDot[i]*(1/xDot[i].Norm());
00070 xDot[i].x[2]+=1;
00071
00072 heat[i]=2+randomizer.Get();
00073
00074 lastBreak[i]=createTime;
00075 }
00076 #else
00077 #ifndef DEDICATED
00078 particle_handle = pGenParticleGroups(1, SPARKS);
00079
00080 pCurrentGroup(particle_handle);
00081
00082 pSource(SPARKS, PDLine(pVec(Position().x, Position().y, 0.3), pVec(Position().x, Position().y, 0.8)));
00083 #endif
00084 #endif
00085
00086 this->AddToList();
00087 }
00088
00089 gSpark::~gSpark(){ }
00090
00091
00092
00093 bool gSpark::Timestep(REAL currentTime){
00094 #ifndef USEPARTICLES
00095 REAL ts=currentTime-lastTime;
00096
00097 for (int i=SPARKS-1;i>=0;i--){
00098 x[i]+=xDot[i]*ts;
00099 xDot[i].x[2]-=5*ts;
00100 heat[i]-=ts;
00101
00102 if (x[i].x[2]<0){
00103 x[i].x[2]*=-1;
00104 xDot[i].x[2]*=-.5;
00105 lastBreak[i]=currentTime;
00106 }
00107 }
00108
00109 if (currentTime>createTime+4)
00110 return true;
00111 else
00112 return false;
00113 #else
00114 #ifndef DEDICATED
00115 pCurrentGroup(particle_handle);
00116
00117 pVelocityD(PDCylinder(pVec(0.0, 0.0, 0.0), pVec(0.0, 0.0, 0.01), 0.01, 0.007));
00118 pColorD(PDLine(pVec(1.0, 1.0, 1.0), pVec(1.0, 1.0, 1.0)));
00119 pSize(40.0);
00120
00121
00122
00123
00124
00125 pGravity(pVec(0.0, 0.0, -0.001));
00126
00127
00128 pBounce(-0.05, 1.0, 0.1, PDDisc(pVec(0, 0, 0), pVec(0, 0, 1), 5000000));
00129
00130
00131 pSink(false, PDPlane(pVec(0,0,0), pVec(0,0,1)));
00132
00133 pKillOld(40);
00134
00135
00136 pMove();
00137
00138
00139 if (pGetGroupCount() < SPARKS/10) {
00140 pDeleteParticleGroups(particle_handle, particle_handle);
00141 return true;
00142 }
00143 #endif // dedicated
00144 #endif // particles
00145
00146 lastTime=currentTime;
00147
00148 return false;
00149 }
00150
00151 void gSpark::InteractWith(eGameObject *,REAL ,int){}
00152 void gSpark::PassEdge(const eWall *,REAL ,REAL ,int){}
00153
00154 void gSpark::Kill(){createTime=lastTime-100000;}
00155
00156
00157 #ifndef DEDICATED
00158 void gSpark::Render(const eCamera *cam){
00159 #ifndef USEPARTICLES
00160 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
00161
00162
00163
00164
00165
00166
00167 glDisable(GL_TEXTURE_2D);
00168
00169 BeginLines();
00170 for (int i=SPARKS-1;i>=0;i--){
00171 #define rmax 1.2
00172 #define gmax 1.1
00173 REAL ago=.2;
00174 if (ago>se_GameTime()-lastBreak[i])
00175 ago=se_GameTime()- lastBreak[i];
00176
00177 REAL a=heat[i]+1.5;
00178 if (a>1) a=1;
00179 if (a<0) a=0;
00180
00181 if(!white_sparks) {
00182 if(i%2)
00183 glColor4f(sparkowncolor_r,sparkowncolor_g,sparkowncolor_b,a);
00184 else
00185 glColor4f(sparkenemycolor_r,sparkenemycolor_g,sparkenemycolor_b,a);
00186 }
00187 else {
00188 REAL r=heat[i]+1;
00189 if (r>rmax) r=rmax;
00190 if (r>1) r=2-r;
00191 if (r<0) r=0;
00192 REAL g=heat[i]+.5;
00193 if (g>gmax) g=gmax;
00194 if (g>1) g=2-g;
00195 if (g<0) g=0;
00196 REAL b=heat[i];
00197 if (b>1) b=1;
00198 if (b<0) b=0;
00199
00200 glColor4f(r,g,b,a);
00201 }
00202
00203 x[i].RenderVertex();
00204 preLastX[i]=x[i];
00205 preLastX[i]+=xDot[i]*(-ago*.8);
00206
00207 preLastX[i].RenderVertex();
00208 preLastX[i]=lastX[i];
00209 lastX[i]=x[i];
00210 }
00211 RenderEnd();
00212 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00213
00214 #else
00215 pCurrentGroup(particle_handle);
00216 int cnt = (int)pGetGroupCount();
00217 if(cnt < 1) return;
00218
00219 float *ptr;
00220 size_t flstride, pos3Ofs, posB3Ofs, size3Ofs, vel3Ofs, velB3Ofs, color3Ofs, alpha1Ofs, age1Ofs;
00221
00222 cnt = (int)pGetParticlePointer(ptr, flstride, pos3Ofs, posB3Ofs,
00223 size3Ofs, vel3Ofs, velB3Ofs, color3Ofs, alpha1Ofs, age1Ofs);
00224 if(cnt < 1) return;
00225
00226 glEnableClientState(GL_COLOR_ARRAY);
00227 glColorPointer(4, GL_FLOAT, int(flstride) * sizeof(float), ptr + color3Ofs);
00228
00229 glEnableClientState(GL_VERTEX_ARRAY);
00230 glVertexPointer(3, GL_FLOAT, int(flstride) * sizeof(float), ptr + pos3Ofs);
00231
00232 glDrawArrays(GL_POINTS, 0, cnt);
00233 glDisableClientState(GL_VERTEX_ARRAY);
00234 glDisableClientState(GL_COLOR_ARRAY);
00235 #endif
00236 }
00237
00238
00239
00240
00241
00242
00243 #endif