void startRand(Particles *emitter, Particle* part, int partnumber) { //srand(time(0)); // smoke rises and spreads part->m_xVector = (r01()) * .25 - 0.25; part->m_yVector = -0.2 - (r01()); part->m_timeDie = 15000 + floor(r01() * 9000); //printf( "partnum = %d timedie = %f rand = %f\n", partnumber, part->m_timeDie , r01()); double invDist = 1.0 / sqrt(part->m_xVector * part->m_xVector + part->m_yVector * part->m_yVector); // normalise speed part->m_xVector = part->m_xVector * invDist * emitter->m_speed; part->m_yVector = part->m_yVector * invDist * emitter->m_speed; // starting position within a 20 pixel area part->m_x = (emitter->m_x + floor(r01() * 20) - 10); part->m_y = (emitter->m_y + floor(r01() * 20) - 10); // the initial age may be > 0. This is so there is already a smoke trail in // place at the start part->m_x += (part->m_xVector + emitter->m_windVelocity) * part->m_age; part->m_y += part->m_yVector * part->m_age; part->m_scale = 0.01; part->m_alpha = 0; part->m_angle = round(rand_range(0, 360)); printf( "x = %f y =%f\n", part->m_x, part->m_y); }
int rbinom(int nTrials, double pLeaving, boost::mt19937& rng) { // THIS PRNG ONLY WORKS FOR SMALL TRIALS. If large trials needed, investigate TR1 or GSL PRNGS int successes = 0; for(int n = 0; n < nTrials; n++) { if(r01(rng) < pLeaving) { successes++; } } return successes; }
void loop(void *passedEmit) { //runs long enough and something is getting gced and x and y get off //change dead routine to use local copy of emitter Particles * emit = (Particles *)passedEmit; //make a local copy of the emitter Particles lemit = *emit; double angle = 0.0; SDL_Rect *clip = NULL; //variable maybe getting optimized out //printf("wind %f x = %f y = %f\n", lemit.m_windVelocity, lemit.particles[1].m_x, lemit.particles[1].m_y); //Event handler SDL_Event ev; //Handle events on queue while ( SDL_PollEvent( &ev ) != 0 ) { //User requests quit if ( ev.type == SDL_QUIT ) { quit = TRUE; } } //emitter->m_speed = 0.02; lemit.m_windVelocity += (r01() - 0.5) * 0.0015; if (lemit.m_windVelocity > 0.015) { lemit.m_windVelocity = 0.015; } if (lemit.m_windVelocity < 0.0) { lemit.m_windVelocity = 0.0; } SDL_RenderClear(renderer); SDL_RenderCopyEx(renderer, bgTexture, clip, &bg, angle, NULL, SDL_FLIP_NONE); for (int i = 0; i < PART_COUNT; i++) { //Particle *cparticle = &emitter->particles[i]; update(&lemit, &(lemit.particles[i]), i); renderParticle(&(lemit.particles[i]), i); } //lastmill = getMilliCount(); SDL_RenderPresent(renderer); //Update the surface SDL_UpdateWindowSurface( gWindow ); lemit.m_lastRender = getMilliCount(); //save the local copy back into the main emitter *((Particles *)passedEmit) = lemit; //logEmitter( emitter, 0 ); }
inline T math_rand_subnormal(RNGType &rng) { mckl::U01OODistribution<T> r01; return r01(rng) * std::numeric_limits<T>::min(); }