[Tuxracer-checkins] CVS: tuxracer/src ui_mgr.c,1.4,1.5 ui_snow.c,1.1,1.2 ui_snow.h,1.1,1.2
Status: Beta
Brought to you by:
jfpatry
From: Jasmin P. <jf...@us...> - 2000-10-01 19:59:59
|
Update of /cvsroot/tuxracer/tuxracer/src In directory slayer.i.sourceforge.net:/tmp/cvs-serv10399 Modified Files: ui_mgr.c ui_snow.c ui_snow.h Log Message: Added generation of snow particles using middle and right mouse buttons. Index: ui_mgr.c =================================================================== RCS file: /cvsroot/tuxracer/tuxracer/src/ui_mgr.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** ui_mgr.c 2000/10/01 15:17:12 1.4 --- ui_mgr.c 2000/10/01 19:59:56 1.5 *************** *** 37,40 **** --- 37,43 ---- static char key_buffer[12]; /* enough to hold a pointer in hex */ static point2d_t cursor_pos = { 0, 0 }; + static bool_t left_mouse_button_down = False; + static bool_t middle_mouse_button_down = False; + static bool_t right_mouse_button_down = False; #define OFFSET_AMT 0.0; *************** *** 432,435 **** --- 435,448 ---- } + if ( button == GLUT_LEFT_BUTTON ) { + left_mouse_button_down = ( state == GLUT_DOWN ); + } + if ( button == GLUT_MIDDLE_BUTTON ) { + middle_mouse_button_down = ( state == GLUT_DOWN ); + } + if ( button == GLUT_RIGHT_BUTTON ) { + right_mouse_button_down = ( state == GLUT_DOWN ); + } + ui_check_dirty(); } *************** *** 459,463 **** /* Update UI snow */ if ( getparam_ui_snow() ) { ! push_ui_snow( cursor_pos ); } --- 472,484 ---- /* Update UI snow */ if ( getparam_ui_snow() ) { ! if ( right_mouse_button_down ) { ! make_ui_snow( cursor_pos ); ! reset_ui_snow_cursor_pos( cursor_pos ); ! } else if ( middle_mouse_button_down ) { ! make_ui_snow( cursor_pos ); ! push_ui_snow( cursor_pos ); ! } else { ! push_ui_snow( cursor_pos ); ! } } Index: ui_snow.c =================================================================== RCS file: /cvsroot/tuxracer/tuxracer/src/ui_snow.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** ui_snow.c 2000/10/01 15:15:13 1.1 --- ui_snow.c 2000/10/01 19:59:56 1.2 *************** *** 27,38 **** #include "textures.h" #include "ui_mgr.h" ! #define NUM_PARTICLES 400 #define GRAVITY_FACTOR 0.015 #define BASE_VELOCITY 0.05 #define VELOCITY_RANGE 0.02 ! #define PUSH_DECAY_FACTOR 0.8 #define PUSH_DIST_DECAY 100 ! #define PUSH_FACTOR 1.0 #define WIND_FORCE 0.03 #define AIR_DRAG 0.4 --- 27,41 ---- #include "textures.h" #include "ui_mgr.h" + #include "loop.h" ! #define MAX_NUM_PARTICLES 10000 ! #define BASE_NUM_PARTICLES 400 #define GRAVITY_FACTOR 0.015 #define BASE_VELOCITY 0.05 #define VELOCITY_RANGE 0.02 ! #define PUSH_DECAY_TIME_CONSTANT 0.2 #define PUSH_DIST_DECAY 100 ! #define PUSH_FACTOR 0.5 ! #define MAX_PUSH_FORCE 100 #define WIND_FORCE 0.03 #define AIR_DRAG 0.4 *************** *** 45,49 **** typedef struct _particle_t { point2d_t pt; ! vector2d_t size; vector2d_t vel; point2d_t tex_min; --- 48,52 ---- typedef struct _particle_t { point2d_t pt; ! scalar_t size; vector2d_t vel; point2d_t tex_min; *************** *** 51,61 **** } particle_t; ! static particle_t particles[NUM_PARTICLES]; ! static GLfloat particle_colour[4] = { 1, 1, 1, 0.5 }; ! static point2d_t push_position; ! static vector2d_t push_vector; ! static bool_t last_push_set; ! static scalar_t last_push_time; ! static scalar_t push_timestep; static scalar_t frand() --- 54,63 ---- } particle_t; ! static particle_t particles[MAX_NUM_PARTICLES]; ! static int num_particles = BASE_NUM_PARTICLES; ! static GLfloat particle_colour[4] = { 1, 1, 1, 0.4 }; ! static point2d_t push_position = {0, 0}; ! static point2d_t last_push_position; ! static scalar_t last_update_time = -1; static scalar_t frand() *************** *** 64,101 **** } ! void init_ui_snow( void ) { scalar_t p_dist; - int i; int type; ! for( i=0; i<NUM_PARTICLES; i++) { ! particles[i].pt.x = frand(); ! particles[i].pt.y = frand(); ! p_dist = frand(); ! particles[i].size.x = particles[i].size.y = ! PARTICLE_MIN_SIZE + (1.0 - p_dist)*PARTICLE_SIZE_RANGE; ! particles[i].vel.x = 0; ! particles[i].vel.y = -BASE_VELOCITY-p_dist*VELOCITY_RANGE; ! type = (int) (frand() * (4.0 - EPS)); ! if (type == 0) { ! particles[i].tex_min = make_point2d( 0.0, 0.0 ); ! particles[i].tex_max = make_point2d( 0.5, 0.5 ); ! } else if (type == 1) { ! particles[i].tex_min = make_point2d( 0.5, 0.0 ); ! particles[i].tex_max = make_point2d( 1.0, 0.5 ); ! } else if (type == 2) { ! particles[i].tex_min = make_point2d( 0.5, 0.5 ); ! particles[i].tex_max = make_point2d( 1.0, 1.0 ); ! } else { ! particles[i].tex_min = make_point2d( 0.0, 0.5 ); ! particles[i].tex_max = make_point2d( 0.5, 1.0 ); ! } } ! push_position = make_point2d( 0.0, 0.0 ); ! push_vector.x = 0.0; ! push_vector.y = 0.0; ! last_push_set = False; } --- 66,104 ---- } ! static void make_particle( int i, scalar_t x, scalar_t y ) { scalar_t p_dist; int type; ! particles[i].pt.x = x; ! particles[i].pt.y = y; ! p_dist = frand(); ! particles[i].size = PARTICLE_MIN_SIZE + (1.0 - p_dist)*PARTICLE_SIZE_RANGE; ! particles[i].vel.x = 0; ! particles[i].vel.y = -BASE_VELOCITY-p_dist*VELOCITY_RANGE; ! type = (int) (frand() * (4.0 - EPS)); ! if (type == 0) { ! particles[i].tex_min = make_point2d( 0.0, 0.0 ); ! particles[i].tex_max = make_point2d( 0.5, 0.5 ); ! } else if (type == 1) { ! particles[i].tex_min = make_point2d( 0.5, 0.0 ); ! particles[i].tex_max = make_point2d( 1.0, 0.5 ); ! } else if (type == 2) { ! particles[i].tex_min = make_point2d( 0.5, 0.5 ); ! particles[i].tex_max = make_point2d( 1.0, 1.0 ); ! } else { ! particles[i].tex_min = make_point2d( 0.0, 0.5 ); ! particles[i].tex_max = make_point2d( 0.5, 1.0 ); } ! } ! void init_ui_snow( void ) ! { ! int i; ! ! for( i=0; i<num_particles; i++) { ! make_particle( i, frand(), frand() ); ! } ! push_position = make_point2d( 0.0, 0.0 ); } *************** *** 104,115 **** vector2d_t *v, f; point2d_t *pt; ! vector2d_t *size; scalar_t dist_from_push, p_dist; int i; ! for ( i=0; i<NUM_PARTICLES; i++) { pt = &particles[i].pt; v = &particles[i].vel; ! size = &particles[i].size; f.x = 0; --- 107,134 ---- vector2d_t *v, f; point2d_t *pt; ! scalar_t size; scalar_t dist_from_push, p_dist; + vector2d_t push_vector; int i; + scalar_t push_timestep, time; + + time = get_clock_time(); ! push_vector.x = 0; ! push_vector.y = 0; ! push_timestep = 0; ! ! if ( last_update_time > 0 ) { ! push_vector.x = push_position.x - last_push_position.x; ! push_vector.y = push_position.y - last_push_position.y; ! push_timestep = time - last_update_time; ! } ! last_push_position = push_position; ! last_update_time = time; ! ! for ( i=0; i<num_particles; i++) { pt = &particles[i].pt; v = &particles[i].vel; ! size = particles[i].size; f.x = 0; *************** *** 120,132 **** pow((pt->y - push_position.y), 2)); if ( push_timestep > 0 ) { ! f.x += (PUSH_FACTOR * ! push_vector.x / push_timestep / ! (PUSH_DIST_DECAY*dist_from_push + 1)) * ! size->x/PARTICLE_SIZE_RANGE; ! f.y += (PUSH_FACTOR * ! push_vector.y / push_timestep / ! (PUSH_DIST_DECAY*dist_from_push + 1)) * ! size->y/PARTICLE_SIZE_RANGE; } --- 139,155 ---- pow((pt->y - push_position.y), 2)); if ( push_timestep > 0 ) { ! f.x = PUSH_FACTOR * push_vector.x / push_timestep; ! f.y = PUSH_FACTOR * push_vector.y / push_timestep; ! ! f.x = min( MAX_PUSH_FORCE, f.x ); ! f.x = max( -MAX_PUSH_FORCE, f.x ); ! f.y = min( MAX_PUSH_FORCE, f.y ); ! f.y = max( -MAX_PUSH_FORCE, f.y ); ! ! f.x *= 1.0/(PUSH_DIST_DECAY*dist_from_push + 1) * ! size/PARTICLE_SIZE_RANGE; ! f.y *= 1.0/(PUSH_DIST_DECAY*dist_from_push + 1) * ! size/PARTICLE_SIZE_RANGE; } *************** *** 138,154 **** /* Update position */ ! pt->x += v->x * time_step * ( size->x / PARTICLE_SIZE_RANGE ); ! pt->y += v->y * time_step * ( size->y / PARTICLE_SIZE_RANGE ); - if (pt->y < -0.05) { - pt->x = frand(); - pt->y = 1+frand()*BASE_VELOCITY; - p_dist = frand(); - size->x = size->y = PARTICLE_MIN_SIZE + - ( 1.0 - p_dist ) * PARTICLE_SIZE_RANGE; - v->x = 0; - v->y = -BASE_VELOCITY-p_dist*VELOCITY_RANGE; - } - if ( pt->x < 0 ) { pt->x = 1; --- 161,167 ---- /* Update position */ ! pt->x += v->x * time_step * ( size / PARTICLE_SIZE_RANGE ); ! pt->y += v->y * time_step * ( size / PARTICLE_SIZE_RANGE ); if ( pt->x < 0 ) { pt->x = 1; *************** *** 156,163 **** pt->x = 0.0; } } ! push_vector.x *= PUSH_DECAY_FACTOR; ! push_vector.y *= PUSH_DECAY_FACTOR; } --- 169,204 ---- pt->x = 0.0; } + } + /* Kill off & regenerate particles */ + for (i=0; i<num_particles; i++) { + particle_t *p = &particles[i]; + + if (p->pt.y < -0.05) { + /* If we have an excess of particles, kill off with + 50% probability */ + if ( num_particles > BASE_NUM_PARTICLES && frand() > 0.5 ) { + /* Delete the particle */ + *p = particles[num_particles-1]; + num_particles -= 1; + } else { + p->pt.x = frand(); + p->pt.y = 1+frand()*BASE_VELOCITY; + p_dist = frand(); + p->size = PARTICLE_MIN_SIZE + + ( 1.0 - p_dist ) * PARTICLE_SIZE_RANGE; + p->vel.x = 0; + p->vel.y = -BASE_VELOCITY-p_dist*VELOCITY_RANGE; + } + } } ! ! if ( time_step < PUSH_DECAY_TIME_CONSTANT ) { ! push_vector.x *= 1.0 - time_step/PUSH_DECAY_TIME_CONSTANT; ! push_vector.y *= 1.0 - time_step/PUSH_DECAY_TIME_CONSTANT; ! } else { ! push_vector.x = 0.0; ! push_vector.y = 0.0; ! } } *************** *** 167,171 **** char *binding; point2d_t *pt, *tex_min, *tex_max; ! vector2d_t *size; scalar_t xres, yres; int i; --- 208,212 ---- char *binding; point2d_t *pt, *tex_min, *tex_max; ! scalar_t size; scalar_t xres, yres; int i; *************** *** 195,203 **** glPushMatrix(); { ! glLoadIdentity(); ! ! for ( i=0; i<NUM_PARTICLES; i++) { pt = &particles[i].pt; ! size = &particles[i].size; tex_min = &particles[i].tex_min; tex_max = &particles[i].tex_max; --- 236,242 ---- glPushMatrix(); { ! for ( i=0; i<num_particles; i++) { pt = &particles[i].pt; ! size = particles[i].size; tex_min = &particles[i].tex_min; tex_max = &particles[i].tex_max; *************** *** 210,218 **** glVertex2f( 0, 0 ); glTexCoord2f( tex_max->x, tex_min->y ); ! glVertex2f( size->x, 0 ); glTexCoord2f( tex_max->x, tex_max->y ); ! glVertex2f( size->x, size->y ); glTexCoord2f( tex_min->x, tex_max->y ); ! glVertex2f( 0, size->y ); } glEnd(); --- 249,257 ---- glVertex2f( 0, 0 ); glTexCoord2f( tex_max->x, tex_min->y ); ! glVertex2f( size, 0 ); glTexCoord2f( tex_max->x, tex_max->y ); ! glVertex2f( size, size ); glTexCoord2f( tex_min->x, tex_max->y ); ! glVertex2f( 0, size ); } glEnd(); *************** *** 225,248 **** } void push_ui_snow( point2d_t pos ) { scalar_t xres, yres; - point2d_t current_pos; xres = getparam_x_resolution(); yres = getparam_y_resolution(); ! current_pos = make_point2d( pos.x/(scalar_t)xres, ! pos.y/(scalar_t)yres ); ! if (last_push_set) { ! push_vector.x = current_pos.x - push_position.x; ! push_vector.y = current_pos.y - push_position.y; ! push_timestep = g_game.secs_since_start - last_push_time; ! } else { ! push_timestep = 0; ! } ! last_push_time = g_game.secs_since_start; ! push_position = current_pos; ! last_push_set = True; } --- 264,300 ---- } + void + reset_ui_snow_cursor_pos( point2d_t pos ) + { + scalar_t xres, yres; + + xres = getparam_x_resolution(); + yres = getparam_y_resolution(); + push_position = make_point2d( pos.x/(scalar_t)xres, + pos.y/(scalar_t)yres ); + last_push_position = push_position; + } + void push_ui_snow( point2d_t pos ) { scalar_t xres, yres; xres = getparam_x_resolution(); yres = getparam_y_resolution(); ! push_position = make_point2d( pos.x/(scalar_t)xres, ! pos.y/(scalar_t)yres ); ! } ! ! void ! make_ui_snow( point2d_t pos ) { ! scalar_t xres, yres; ! xres = getparam_x_resolution(); ! yres = getparam_y_resolution(); ! ! if ( num_particles < MAX_NUM_PARTICLES ) { ! make_particle( num_particles, pos.x/xres, pos.y/yres ); ! num_particles++; ! } } Index: ui_snow.h =================================================================== RCS file: /cvsroot/tuxracer/tuxracer/src/ui_snow.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** ui_snow.h 2000/10/01 15:15:13 1.1 --- ui_snow.h 2000/10/01 19:59:56 1.2 *************** *** 30,33 **** --- 30,35 ---- void push_ui_snow( point2d_t pos ); void draw_ui_snow( void ); + void make_ui_snow( point2d_t pos ); + void reset_ui_snow_cursor_pos( point2d_t pos ); #endif /* _UI_SNOW_H_ */ |