Example #1
0
/* ugg, should be a priority queue if next event times known */
static void update_particles(providencestruct *mp) 
{
  int i;

  for(i = 0; i < PARTICLE_COUNT; ++i) {
    /* check for time elapse */
    if(mp->currenttime > mp->particles[i][3] + mp->particles[i][4])
      init_particle(mp, mp->particles[i]);
  }

  /* now update eye particles */
  for(i = 0; i < EYE_PARTICLE_COUNT; ++i) {
/*     int x = eyeparticles[i][1] + random()%16; */
    int x = mp->eyeparticles[i][1] + random()%(cos(mp->theta) < 0.0 ? 8 : 16);

    /* reset if dead */
    if(x > EYELENGTH || random()%(cos(mp->theta) < 0.0 ? 40 : 10) == 0) {

/*     if(x > EYELENGTH || (x > EYELENGTH/(2/3.0) && random()%7 == 0)) { */
      mp->eyeparticles[i][0] = random()%LOOKUPSIZE;
      mp->eyeparticles[i][1] = random()%40;
    }
    else {
      mp->eyeparticles[i][1] = x;
    }    
  }
}
Example #2
0
int main(int argc, char* argv[]) {
	particle p_list[NUM_PARTICLES];
	png_file png;
	float t;
	int i;

	int num_nodes,id;
	MPI_Status status;

	/* init MPI */
    MPI_Init(&argv,&argc);
    MPI_Comm_rank(MPI_COMM_WORLD,&id);
    MPI_Comm_size(MPI_COMM_WORLD,&num_nodes);

	/* create datatypes */


	/* init the particle list */
	for(i=0; i < NUM_PARTICLES; i++) {
		init_particle(&p_list[i],0,0,0);
		set_x_pos_fnt(&p_list[i],&position_x);
		set_y_pos_fnt(&p_list[i],&position_y);
		set_z_pos_fnt(&p_list[i],&position_z);
		p_list[i].parm_list = (float*)malloc(sizeof(float) * NUM_PARMS);
		p_list[i].parm_list[MASS] = 1.0F;  /* kg */
		p_list[i].parm_list[X_V0] = 15.0F; /* m/s */
		p_list[i].parm_list[Y_V0] = 0.0F;  /* m/s */
		p_list[i].parm_list[Z_V0] = 0.0F;  /* m/s */
	}

	/* open the png file */
	open_file(&png,"test.png",1024,1024,0,2000,-2000,0);

	/* do some work */
	for(t=0.0F; t < 20.0F; t+=0.05F) {
		for(i=0; i < NUM_PARTICLES; i++) {
			update_particle(&p_list[i],t);
			printf("%F %F %F\n",p_list[i].x,p_list[i].y,p_list[i].z);
			plot_point(&png,(int)p_list[i].x,(int)p_list[i].y,255-i,255-i,255-i);
		}
	}

	/* write out the png file */
	write_file(&png);

	/* close the png file */
	close_file(&png);

	/* destory particle list */
	for(i=0; i < NUM_PARTICLES; i++) {
		free(p_list[i].parm_list);
	}

	/* shutdown MPI */
	MPI_Finalize();

	return(0);
}
Example #3
0
void local_place_particle(int part, double p[3], int _new)
{
  Cell *cell;
  double pp[3];
  int i[3], rl;
  Particle *pt;

  i[0] = 0;
  i[1] = 0;
  i[2] = 0;
  pp[0] = p[0];
  pp[1] = p[1];
  pp[2] = p[2];

#ifdef LEES_EDWARDS
  double vv[3]={0.,0.,0.};
  fold_position(pp, vv, i);
#else
  fold_position(pp, i);
#endif 
  
  if (_new) {
    /* allocate particle anew */
    cell = cell_structure.position_to_cell(pp);
    if (!cell) {
      fprintf(stderr, "%d: INTERNAL ERROR: particle %d at %f(%f) %f(%f) %f(%f) does not belong on this node\n",
	      this_node, part, p[0], pp[0], p[1], pp[1], p[2], pp[2]);
      errexit();
    }
    rl = realloc_particlelist(cell, ++cell->n);
    pt = &cell->part[cell->n - 1];
    init_particle(pt);

    pt->p.identity = part;
    if (rl)
      update_local_particles(cell);
    else
      local_particles[pt->p.identity] = pt;
  }
  else
    pt = local_particles[part];

  PART_TRACE(fprintf(stderr, "%d: local_place_particle: got particle id=%d @ %f %f %f\n",
		     this_node, part, p[0], p[1], p[2]));

#ifdef LEES_EDWARDS
  pt->m.v[0] += vv[0];  
  pt->m.v[1] += vv[1];  
  pt->m.v[2] += vv[2];  
#endif

  memcpy(pt->r.p, pp, 3*sizeof(double));
  memcpy(pt->l.i, i, 3*sizeof(int));
#ifdef BOND_CONSTRAINT
  memcpy(pt->r.p_old, pp, 3*sizeof(double));
#endif
}
Example #4
0
System *init_system(int nr_particles, int dims) {
    System *system = (System *) malloc(sizeof(System) +
                                       nr_particles*sizeof(Particle *));
    system->dims = dims;
    system->nr_particles = nr_particles;
    for (int i = 0; i < nr_particles; i++)
        system->particle[i] = init_particle(dims);
    return system;
}
Example #5
0
/* init glory particles */
static void init_particles(providencestruct *mp) 
{
  int i;
  for(i = 0; i < PARTICLE_COUNT; ++i) {
    init_particle(mp, mp->particles[i]);

    /* set initial time */
    mp->particles[i][3] = mp->currenttime - (random()%1250)/1000.0;
  }

  /* init eye particles */
  for(i = 0; i < EYE_PARTICLE_COUNT; ++i) {
    mp->eyeparticles[i][0] = random()%LOOKUPSIZE;
    mp->eyeparticles[i][1] = random()%EYELENGTH;
  }
}
Example #6
0
int main(int argc, char* argv[]) {
	particle p_list[NUM_PARTICLES];
	png_file png;
	float t;
	int i;

	/* init the particle engine */
	init_particle_engine();
	set_x_pos_fnt(&p_list[i],&position_x);
	set_y_pos_fnt(&p_list[i],&position_y);
	set_z_pos_fnt(&p_list[i],&position_z);


	/* init the particle list */
	for(i=0; i < NUM_PARTICLES; i++) {
		init_particle(&p_list[i],0,0,0);
		p_list[i].parm_list[MASS] = 1.0F;  /* kg */
		p_list[i].parm_list[X_V0] = 15.0F; /* m/s */
		p_list[i].parm_list[Y_V0] = 0.0F;  /* m/s */
		p_list[i].parm_list[Z_V0] = 0.0F;  /* m/s */
	}

	/* open the png file */
	open_file(&png,"test.png",1024,1024,0,2000,-2000,0);

	/* do some work */
	for(t=0.0F; t < 20.0F; t+=0.05F) {
		for(i=0; i < NUM_PARTICLES; i++) {
			update_particle(&p_list[i],t);
			plot_point(&png,(int)p_list[i].x,(int)p_list[i].y,255,255,255);
		}
	}

	//plot_point(&png,0,0,255,255,255);

	/* write out the png file */
	write_file(&png);

	/* close the png file */
	close_file(&png);

	return(0);
}
Example #7
0
static void particle_engine(double t, float dt)
{
    int i;
    float dt2;

    // Update particles (iterated several times per frame if dt is too large)
    while (dt > 0.f)
    {
        // Calculate delta time for this iteration
        dt2 = dt < MIN_DELTA_T ? dt : MIN_DELTA_T;

        for (i = 0;  i < MAX_PARTICLES;  i++)
            update_particle(&particles[i], dt2);

        min_age += dt2;

        // Should we create any new particle(s)?
        while (min_age >= BIRTH_INTERVAL)
        {
            min_age -= BIRTH_INTERVAL;

            // Find a dead particle to replace with a new one
            for (i = 0;  i < MAX_PARTICLES;  i++)
            {
                if (!particles[i].active)
                {
                    init_particle(&particles[i], t + min_age);
                    update_particle(&particles[i], min_age);
                    break;
                }
            }
        }

        dt -= dt2;
    }
}
Example #8
0
void ParticlePart(int crtl) {
    tex= plx_txr_load("/rd/gfx/particle.png",1,0);

    init_particle();
    // float theta = 0;
    int done, loop, cnt=0;
    uint32 color;
    plx_dr_state_t dr;
    float x,y,z;



    // Setup the context


    //pvr_set_bg_color(0.0f,0.0f,0.0f);

    // Init 3D stuff. mat3d is like KGL.
    //plx_mat3d_init();
    plx_mat3d_mode(PLX_MAT_PROJECTION);
    plx_mat3d_identity();
    plx_mat3d_perspective(45.0f, 640.0f / 480.0f, 0.1f, 100.0f);
    plx_mat3d_mode(PLX_MAT_MODELVIEW);


    for (done = 0; !done;) {
        // Check for start
        MAPLE_FOREACH_BEGIN(MAPLE_FUNC_CONTROLLER, cont_state_t, st)
        if (st->buttons & CONT_START)
            done = 1;
        if (st->buttons & CONT_X) {
            printf("\nTime: %d",cnt);
            /* vid_screen_shot("/pc/shots/demo_part_f");*/
        }
        MAPLE_FOREACH_END()
        if(col<12)
            col++;
        else
            col=0;
        // Setup the frame

        plx_cxt_texture(tex);

        //pvr_wait_ready();
        //pvr_scene_begin();
        //pvr_list_begin(PLX_LIST_TR_POLY);

        // Submit the context
        plx_cxt_send(PLX_LIST_TR_POLY);

        // plx_fcxt_setcolor4f(cxt,particle[loop].life,particle[loop].r, particle[loop].g, particle[loop].r);
        //PrintString("Driver's High - L'Arc-en-Ciel",80.0f,22.0,30.0f);


        plx_mat3d_identity();

        for (loop=0; loop<MAX_PARTICLES; loop++)	{				// Loop Through All The Particl
            if (particle[loop].active) {					// If The Particle Is Active
                x=particle[loop].x;				// Grab Our Particle X Position
                y=particle[loop].y;				// Grab Our Particle Y Position
                z=particle[loop].z+zoom;				// Particle Z Pos + Zoom

                //printf("\nR: %f - G: %f - B: %f",particle[loop].r,particle[loop].g,particle[loop].b);
                color = plx_pack_color(particle[loop].life,particle[loop].r,particle[loop].g,particle[loop].b);
                // printf("\nColor: %d",color); //0xff0a0a0a;


                plx_mat3d_identity();
                plx_mat3d_translate(x, y, z);

                plx_mat_identity();
                plx_mat3d_apply(PLX_MAT_SCREENVIEW);
                plx_mat3d_apply(PLX_MAT_PROJECTION);
                plx_mat3d_apply(PLX_MAT_MODELVIEW);

                plx_dr_init(&dr);
                plx_cxt_init();

                plx_cxt_culling(PLX_CULL_NONE);
                plx_txr_send_hdr(tex,PLX_LIST_TR_POLY,1);

                plx_spr_fnp(32,32,320.0+particle[loop].x,240.0+particle[loop].y,particle[loop].z,particle[loop].life,particle[loop].r,particle[loop].g,particle[loop].b);
                /*
                plx_vert_indm3(&dr, PLX_VERT,-0.5,0.5,-0.5,color);
                plx_vert_indm3(&dr, PLX_VERT,-0.5,-0.5,-0.5, color);
                plx_vert_indm3(&dr, PLX_VERT,0.5,0.5,-0.5, color);
                plx_vert_indm3(&dr, PLX_VERT_EOS,0.5,-0.5,-0.5, color);

                      */


                particle[loop].x+=particle[loop].xi/(slowdown*250);	// Move On The X Axis By X Speed
                particle[loop].y+=particle[loop].yi/(slowdown*250);	// Move On The Y Axis By Y Speed
                particle[loop].z+=particle[loop].zi/(slowdown*250);	// Move On The Z Axis By Z Speed

                particle[loop].xi+=particle[loop].xg;			// Take Pull On X Axis Into Account
                particle[loop].yi+=particle[loop].yg;			// Take Pull On Y Axis Into Account
                particle[loop].zi+=particle[loop].zg;			// Take Pull On Z Axis Into Account

                particle[loop].life-=particle[loop].fade;		// Reduce Particles Life By 'Fade'

                if (particle[loop].life<0.0f)	{				// If Particle Is Burned Out
                    particle[loop].life=1.0f;				// Give It New Life
                    particle[loop].fade=(float)(rand()%100)/1000.0f+0.003f;	// Random Fade Value

                    particle[loop].x=0.0f;					// Center On X Axis
                    particle[loop].y=0.0f;					// Center On Y Axis
                    particle[loop].z=0.0f;					// Center On Z Axis

                    particle[loop].xi=xspeed+(float)((rand()%60)-32.0f);	// X Axis Speed And Direction
                    particle[loop].yi=yspeed+(float)((rand()%60)-30.0f);	// Y Axis Speed And Direction
                    particle[loop].zi=(float)((rand()%60)-30.0f);		// Z Axis Speed And Direction

                    particle[loop].r=colors[col][0];			// Select Red From Color Table
                    particle[loop].g=colors[col][1];			// Select Green From Color Table
                    particle[loop].b=colors[col][2];			// Select Blue From Color Table
                }
#ifdef PC50
                if ((cnt>402+(MUSIC_TIMER_OFFSET) && cnt <405+(MUSIC_TIMER_OFFSET)) || (cnt>467+(MUSIC_TIMER_OFFSET) && cnt<469+(MUSIC_TIMER_OFFSET)) ||
                        (cnt>528+(MUSIC_TIMER_OFFSET) && cnt <530+(MUSIC_TIMER_OFFSET)) || (cnt>594+(MUSIC_TIMER_OFFSET) && cnt<596+(MUSIC_TIMER_OFFSET)) ||
                        (cnt>649+(MUSIC_TIMER_OFFSET) && cnt <651+(MUSIC_TIMER_OFFSET)) || (cnt>712+(MUSIC_TIMER_OFFSET) && cnt<714+(MUSIC_TIMER_OFFSET)) ||
                        (cnt>778+(MUSIC_TIMER_OFFSET) && cnt <780+(MUSIC_TIMER_OFFSET))) {
                    particle[loop].x=0.0f;					// Center On X Axis
                    particle[loop].y=0.0f;					// Center On Y Axis
                    particle[loop].z=0.0f;					// Center On Z Axis
                    particle[loop].xi=(float)((rand()%50)-26.0f)*10.0f;	// Random Speed On X Axis
                    particle[loop].yi=(float)((rand()%50)-25.0f)*10.0f;	// Random Speed On Y Axis
                    particle[loop].zi=(float)((rand()%50)-25.0f)*10.0f;	// Random Speed On Z Axis
                }
#endif

#ifdef VGA
                if ((cnt>402+(MUSIC_TIMER_OFFSET) && cnt <405+(MUSIC_TIMER_OFFSET)) || (cnt>467+(MUSIC_TIMER_OFFSET) && cnt<469+(MUSIC_TIMER_OFFSET)) ||
                        (cnt>528+(MUSIC_TIMER_OFFSET) && cnt <530+(MUSIC_TIMER_OFFSET)) || (cnt>594+(MUSIC_TIMER_OFFSET) && cnt<596+(MUSIC_TIMER_OFFSET)) ||
                        (cnt>649+(MUSIC_TIMER_OFFSET) && cnt <651+(MUSIC_TIMER_OFFSET)) || (cnt>712+(MUSIC_TIMER_OFFSET) && cnt<714+(MUSIC_TIMER_OFFSET)) ||
                        (cnt>778+(MUSIC_TIMER_OFFSET) && cnt <780+(MUSIC_TIMER_OFFSET))) {
                    particle[loop].x=0.0f;					// Center On X Axis
                    particle[loop].y=0.0f;					// Center On Y Axis
                    particle[loop].z=0.0f;					// Center On Z Axis
                    particle[loop].xi=(float)((rand()%50)-26.0f)*10.0f;	// Random Speed On X Axis
                    particle[loop].yi=(float)((rand()%50)-25.0f)*10.0f;	// Random Speed On Y Axis
                    particle[loop].zi=(float)((rand()%50)-25.0f)*10.0f;	// Random Speed On Z Axis
                }
#endif
            }

        }
        // stars_one_frame();
        //do_sign_frame();
        //pvr_scene_finish();
        cnt++;
        if(cnt>846+MUSIC_TIMER_OFFSET)
            return;

    }
}