void partUpdate() { simulationFrameNumber++; // DIFFUSE (@TODO: replace w more realisitic simulation, see CheY paper) for( int i=0; i<partCount; i++ ) { IVec2 p = part[i].pos; static IVec2 dirs[4] = { IVec2(1,0), IVec2(-1,0), IVec2(0,1), IVec2(0,-1) }; p.add( dirs[zrandI(0,4)] ); if( partInBounds(p) ) { Part *react = partAt(p); if( react ) { int hit = (*partReactCallback)( react, &part[i] ); if( !hit ) { (*partReactCallback)( &part[i], react ); } } else if( part[i].diffuses ) { partMove( &part[i], p ); } } } }
void renderParticles() // main render function { int currentParticleType = PART_EMPTY; float tx = 640.0/screen_width; float ty = 480.0/screen_height; glBegin(GL_QUADS); for(int y = 0; y < screen_height; y++) { for(int x = 0; x < screen_width; x++) { float cx = tx*x; float cy = ty*y; currentParticleType = partAt(x,y).type; if(currentParticleType != PART_EMPTY ) { switch(currentParticleType) { case PART_EMPTY: break; case PART_FIRE: simFire(x,y); glColor3ub(255,32,32); break; case PART_PROPANE: simPropane(x,y); glColor3ub(255,255,255); break; case PART_WALL: simWall(x,y); glColor3ub(128,128,128); break; case PART_NAPALM: simNapalm(x,y); glColor3ub(128,128,0); break; case PART_WATER: simWater(x,y); glColor3ub(64,64,255); break; case PART_SAND: simSand(x,y); glColor3ub(255,255,130); break; case PART_GUNPOWDER: simGunPowder(x,y); glColor3ub(200,200,200); break; case PART_NITRO: simNitro(x,y); glColor3ub(25,230,25); break; case PART_STEAM: simSteam(x,y); glColor3ub(200,200,250); break; } } else { glColor3f(0,0,0); } glVertex2f(cx,cy); glVertex2f(cx+tx,cy); glVertex2f(cx+tx,cy+ty); glVertex2f(cx,cy+ty); } } glEnd(); }
void cheReactionUpdate() { framesSinceLastReset++; int i; if( Band_signalOmega != oldOmega ) { cheReactionReset(); } avgBuf[avgBufCount++] = (float)outputHits; if( avgBufCount == avgBufSize ) { float sum = 0.f; for( i=0; i<avgBufCount; i++ ) { sum += avgBuf[i]; } fftBuf[fftBufCount] = sum / (float)avgBufCount; fftBufCount++; avgBufCount = 0; if( fftBufCount == fftBufSize ) { FFT fft( fftBuf, fftBufSize ); fft.fft(); float *p = fft.computePowerSpectrum(); for( i=0; i<fftBufCount/2-1; i++ ) { cumPowerSpectrum[i] += p[i]; cumPowerSpectrumLog[i] = logf( 1.f + cumPowerSpectrum[i] ); } fftBufCount = 0; cumPowerSpectrumCount++; FILE *file = fopen( ZTmpStr("/transfer/fft/fft-diff-%d.txt",cumPowerSpectrumCount), "wt" ); for( i=1; i<100; i++ ) { fprintf( file, "%f\n", cumPowerSpectrum[i] / (float)cumPowerSpectrumCount ); } fclose( file ); } } if( !(simulationFrameNumber % 100 ) ) { spatialHistogramCount++; for( int x=0; x<DIMX; x++ ) { for( int y=0; y<DIMY; y++ ) { Part *p = partAt( IVec2(x,y) ); if( p && p->type == TYPE_CHEYP ) { spatialHistogram[x]++; } } } } outputHistory.setAvgWindow( Band_plotWindowRadius ); outputHistory.add( (float)outputHits ); // COMPUTE input signal signal = Band_signal; if( Band_useSinSignal ) { signal = (float)( Band_signalTop * 0.5*( 1.0+sin( Band_signalOmega * (double)simulationFrameNumber ) ) ); } inputHistory.add( signal ); // SETUP for next computation outputHits = 0; }