From: Richard V. <rt...@us...> - 2007-03-01 20:09:55
|
Update of /cvsroot/playerstage/code/stage/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14994/src Modified Files: Tag: opengl gui_gl.c model.c stage_internal.h world.c Log Message: messed up viewing geom Index: gui_gl.c =================================================================== RCS file: /cvsroot/playerstage/code/stage/src/Attic/gui_gl.c,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -C2 -d -r1.1.2.10 -r1.1.2.11 *** gui_gl.c 27 Feb 2007 02:54:08 -0000 1.1.2.10 --- gui_gl.c 2 Mar 2007 04:09:50 -0000 1.1.2.11 *************** *** 74,77 **** --- 74,81 ---- stg_model_t* stg_world_nearest_root_model( stg_world_t* world, double wx, double wy ); + // foward-declare some callbacks + void model_draw_cb( stg_model_t* mod, void* user ); + void model_bbox_cb( gpointer key, stg_model_t* mod, void* user ); + static int recticle_list = 0; *************** *** 95,124 **** /* Storage for 96 characters */ base = glGenLists( 96 ); - - //if( base == 0 ) - //perror( "attempting to generate 96 displaylists" ); assert( base > 0 ); ! ! ! /* Get our current display long enough to get the fonts */ dpy = XOpenDisplay( NULL ); ! /* Get the font information */ ! //fontInfo = XLoadQueryFont( dpy, "-adobe-helvetica-medium-r-normal--18-*-*-*-p-*-iso8859-1" ); ! fontInfo = XLoadQueryFont( dpy, "fixed" ); ! ! /* If the above font didn't exist try one that should */ ! if ( fontInfo == NULL ) ! { ! fontInfo = XLoadQueryFont( dpy, "fixed" ); ! /* If that font doesn't exist, something is wrong */ ! if ( fontInfo == NULL ) ! { ! fprintf( stderr, "no X font available?\n" ); ! Quit( 1 ); ! } ! } ! /* generate the list */ glXUseXFont( fontInfo->fid, 32, 96, base ); --- 99,115 ---- /* Storage for 96 characters */ base = glGenLists( 96 ); assert( base > 0 ); ! /* Get our current display long enough to get the fonts */ dpy = XOpenDisplay( NULL ); ! /* Get the font information */ ! if( (fontInfo = XLoadQueryFont( dpy, "fixed" )) == NULL ) ! { ! /* If that font doesn't exist, something is wrong */ ! PRINT_ERR( "no X font \"fixed\" available. Giving up." ); ! Quit( 1 ); ! } ! /* generate the list */ glXUseXFont( fontInfo->fid, 32, 96, base ); *************** *** 214,217 **** --- 205,221 ---- } + + // a convenience wrapper around push_color(), with a=1 + void push_color_rgb( double r, double g, double b ) + { + GLdouble col[4]; + col[0] = r; + col[1] = g; + col[2] = b; + col[3] = 1.0; + + push_color( col ); + } + // a convenience wrapper around push_color() void push_color_rgba( double r, double g, double b, double a ) *************** *** 663,667 **** ! void gl_model_grid( stg_model_t* mod, void* user ) { // get the display list associated with this model --- 667,671 ---- ! int gl_model_grid( stg_model_t* mod, void* user ) { // get the display list associated with this model *************** *** 718,721 **** --- 722,727 ---- pop_color(); glEndList(); + + return 0; // callback runs until removed } *************** *** 878,882 **** // draw each poly ! g_list_foreach( mod->polys, gl_draw_polygon2d_cb, NULL ); //if( 1 )// mod->boundary ) --- 884,888 ---- // draw each poly ! g_list_foreach( mod->polys, (GFunc)gl_draw_polygon2d_cb, NULL ); //if( 1 )// mod->boundary ) *************** *** 899,903 **** // draw each poly ! g_list_foreach( mod->polys, gl_draw_polygon3d_cb, NULL ); --- 905,909 ---- // draw each poly ! g_list_foreach( mod->polys, (GFunc)gl_draw_polygon3d_cb, NULL ); *************** *** 952,956 **** } ! int gl_model_draw( stg_model_t* mod, void* userp ) { //puts( "model render polygons" ); --- 958,962 ---- } ! void gl_model_draw( stg_model_t* mod ) { //puts( "model render polygons" ); *************** *** 1027,1079 **** glCallList( selectedlist ); } ! if( mod->children ) ! { ! ! // recursively draw the tree below this model ! GList *it;; ! for( it=mod->children; it; it=it->next ) ! { ! gl_model_draw( (stg_model_t*)it->data, NULL ); ! } ! } glPopMatrix(); // drop out of local coords - if( mod->sense_poly && (mod->world->win->selection_active == mod )) - { - push_color_stgcolor( stg_lookup_color( "green" )); - - gl_draw_polygon_bbox( mod->sense_poly ); - pop_color(); - - // outline the polgons that the selected robot intersects with - push_color_stgcolor( stg_lookup_color( "blue" )); - - GList *a, *b; - //for( a=mod->polys ; a; a=a->next ) - //for( b = ((stg_polygon_t*)a->data)->intersectors; b; b=b->next ) - for( b = mod->sense_poly->intersectors; b; b=b->next ) - { - stg_polygon_t* p = (stg_polygon_t*)b->data; - - glPushMatrix(); - - stg_pose_t pose; - stg_model_get_global_pose( p->mod, &pose ); - - // move into this model's coordinate frame - glTranslatef( pose.x, pose.y, pose.z ); - glRotatef( RTOD(pose.a), 0,0,1 ); - - //gl_draw_polygon_bbox( p ); - gl_draw_polygon3d( p ); - - glPopMatrix(); - } - - pop_color(); - } - pop_color(); glEndList(); --- 1033,1048 ---- glCallList( selectedlist ); } + + + g_list_foreach( mod->children, (GFunc)model_draw_cb, NULL ); ! /* // recursively draw the tree below this model */ ! /* GList *it;; */ ! /* for( it=mod->children; it; it=it->next ) */ ! /* gl_model_draw( (stg_model_t*)it->data ); */ ! /* } */ glPopMatrix(); // drop out of local coords pop_color(); glEndList(); *************** *** 1086,1091 **** make_dirty(mod); - - return 0; } --- 1055,1058 ---- *************** *** 1189,1203 **** } ! void model_draw_cb( gpointer key, stg_model_t* mod, void* user ) { ! // TODO - fix this - this gets called way too much. ! // the models draw their children recursively, so only draw root models ! if( mod->parent == NULL ) ! gl_model_draw( mod, user ); } void model_bbox_cb( gpointer key, stg_model_t* mod, void* user ) { ! g_list_foreach( mod->polys, gl_draw_polygon_bbox_cb, NULL ); } --- 1156,1167 ---- } ! void model_draw_cb( stg_model_t* mod, void* user ) { ! gl_model_draw( mod ); } void model_bbox_cb( gpointer key, stg_model_t* mod, void* user ) { ! g_list_foreach( mod->polys, (GFunc)gl_draw_polygon_bbox_cb, NULL ); } *************** *** 1241,1249 **** world->win->show_data = 0; world->win->show_grid = 0; ! //g_hash_table_foreach( world->models, (GHFunc)model_draw_cb, NULL ); world->win->show_grid = keep_grid; world->win->show_data = keep_data; double left = -seex/2.0 * world->width - world->win->panx; double top = -seey/2.0 * world->height - world->win->pany; --- 1205,1218 ---- world->win->show_data = 0; world->win->show_grid = 0; ! ! g_list_foreach( world->children, (GFunc)model_draw_cb, NULL ); ! world->win->show_grid = keep_grid; world->win->show_data = keep_data; + // if we're in 2d mode - show the visble region + + double left = -seex/2.0 * world->width - world->win->panx; double top = -seey/2.0 * world->height - world->win->pany; *************** *** 1279,1283 **** glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); ! glColor3f( 1.0,0,0 ); glRectf( left, top, right, bottom ); --- 1248,1252 ---- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); ! glColor3f( 1.0,0,0.1 ); glRectf( left, top, right, bottom ); *************** *** 1290,1357 **** } - /* void model_draw_bbox( stg_model_t* mod, gpointer dummy ) */ - /* { */ - /* if( mod->polygons_count ) */ - /* { */ - /* stg_endpoint_t *epts = mod->polygons[0].epts; */ - - /* double xmin = epts[0].value; */ - /* double xmax = epts[1].value; */ - /* double ymin = epts[2].value; */ - /* double ymax = epts[3].value; */ - /* double zmin = epts[4].value; */ - /* double zmax = epts[5].value; */ - - /* // model's body color */ - /* push_color_stgcolor( mod->color ); */ - - /* // draw rectangles on the axes indicating the extent of bboxes. */ - /* glBegin(GL_LINE_LOOP ); */ - /* glVertex3f( xmin, 0, zmin); */ - /* glVertex3f( xmin, 0, zmax); */ - /* glVertex3f( xmax, 0, zmax); */ - /* glVertex3f( xmax, 0, zmin); */ - /* glEnd(); */ - - /* glBegin(GL_LINE_LOOP ); */ - /* glVertex3f( 0, ymin, zmin); */ - /* glVertex3f( 0, ymin, zmax); */ - /* glVertex3f( 0, ymax, zmax); */ - /* glVertex3f( 0, ymax, zmin); */ - /* glEnd(); */ - - /* // bottom rectangle */ - /* glBegin(GL_LINE_LOOP ); */ - /* glVertex3f( xmin, ymin, zmin ); */ - /* glVertex3f( xmin, ymax, zmin ); */ - /* glVertex3f( xmax, ymax, zmin ); */ - /* glVertex3f( xmax, ymin, zmin ); */ - /* glEnd(); */ - - /* // top rectangle */ - /* glBegin(GL_LINE_LOOP ); */ - /* glVertex3f( xmin, ymin, zmax ); */ - /* glVertex3f( xmin, ymax, zmax ); */ - /* glVertex3f( xmax, ymax, zmax ); */ - /* glVertex3f( xmax, ymin, zmax ); */ - /* glEnd(); */ - - /* // verticals */ - /* glBegin( GL_LINES ); */ - /* glVertex3f( xmin, ymin, zmin ); */ - /* glVertex3f( xmin, ymin, zmax ); */ - /* glVertex3f( xmax, ymin, zmin ); */ - /* glVertex3f( xmax, ymin, zmax ); */ - /* glVertex3f( xmin, ymax, zmin ); */ - /* glVertex3f( xmin, ymax, zmax ); */ - /* glVertex3f( xmax, ymax, zmin ); */ - /* glVertex3f( xmax, ymax, zmax ); */ - /* glEnd(); */ - - /* pop_color(); */ - /* } */ - /* } */ - - void draw_endpoints( stg_world_t* world ) { --- 1259,1262 ---- *************** *** 1471,1482 **** glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); ! int perspective = 0; // perspective is a little distorted, so leave this zero until fixed ! ! if( perspective || world->win->sphi || world->win->stheta ) { glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); } ! else // orthographic with zero rotation allows a speed-up { glDisable(GL_DEPTH_TEST); --- 1376,1385 ---- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); ! if( world->win->sphi || world->win->stheta ) { glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); } ! else // zero rotation allows a speed-up { glDisable(GL_DEPTH_TEST); *************** *** 1505,1526 **** // map the viewport to pixel units by scaling it the same as the window ! if( perspective ) ! { ! glFrustum( 0, pixels_width, ! 0, pixels_height, ! zclip, 2*zclip ); ! } ! else ! { ! glOrtho( 0, pixels_width, ! 0, pixels_height, ! 0, zclip ); ! } glMatrixMode (GL_MODELVIEW); glLoadIdentity (); ! if( world->win->follow_selection && world->win->selection_last ) { --- 1408,1435 ---- // map the viewport to pixel units by scaling it the same as the window ! // glOrtho( 0, pixels_width, ! // 0, pixels_height, ! glOrtho( -pixels_width/2.0, pixels_width/2.0, ! -pixels_height/2.0, pixels_height/2.0, ! 0, MAX(pixels_width,pixels_height) ); + /* glFrustum( 0, pixels_width, */ + /* 0, pixels_height, */ + /* 0.1, zclip ); */ + glMatrixMode (GL_MODELVIEW); glLoadIdentity (); ! //gluLookAt( 0,0,10, ! // 0,0,0, ! // 0,1,0 ); + gluLookAt( win->panx + pixels_width * cos(win->stheta), win->pany + pixels_height * sin( win->sphi), 10, + win->panx, win->pany, 0, + 0,1,0 ); + + //glTranslatef( win->click_point.x, win->click_point.y, 0 ); // shift to rotation point + //glTranslatef( -win->click_point.x, -win->click_point.y, 0 ); // shift to rotation point + if( world->win->follow_selection && world->win->selection_last ) { *************** *** 1535,1551 **** else { ! if( perspective ) ! glTranslatef( pixels_width / 2 + win->panx, ! pixels_height / 2 + win->pany, ! -1.5*zclip ); // x,y in pixel coords, z in 0-1 depth ! else ! glTranslatef( pixels_width / 2 + win->panx, ! pixels_height / 2 + win->pany, ! -zclip/2.0 ); // x,y in pixel coords, z in 0-1 depth ! glScalef ( win->scale, win->scale, 1.0 ); // zoom // rotate about x - roll ! glRotatef( RTOD(-win->stheta), 1.0, 0.0, 0.0); --- 1444,1470 ---- else { ! push_color_rgb( 1,0,0 ); ! glRecti( 0,0,1,1 ); ! pop_color(); ! ! // still in pixelcoords ! glTranslatef( win->panx*win->scale, ! win->pany*win->scale, ! 0 );//-zclip ); // x,y in pixel coords, z in 0-1 depth ! ! push_color_rgb( 0,1,0 ); ! glRecti( 0,0,1,1 ); ! pop_color(); ! ! // shift into meters glScalef ( win->scale, win->scale, 1.0 ); // zoom // rotate about x - roll ! //glRotatef( RTOD(-win->stheta), 1.0, 0.0, 0.0); ! ! push_color_rgb( 0,0,1 ); ! glRecti( 0,0,1,1 ); ! pop_color(); ! *************** *** 1553,1558 **** //origin - the commented code is close, but not quite right ! //glTranslatef( win->click_point.x, win->click_point.y, 0 ); // shift to rotation point ! glRotatef( RTOD(win->sphi), 0.0, 0.0, 1.0); // rotate about z - pitch //glTranslatef( -win->click_point.x, -win->click_point.y, 0 ); // shift back //printf( "panx %f pany %f scale %.2f stheta %.2f sphi %.2f\n", --- 1472,1479 ---- //origin - the commented code is close, but not quite right ! ! //glRotatef( RTOD(win->sphi), 0.0, 0.0, 1.0); // rotate about z - pitch ! ! //glTranslatef( -win->click_point.x, -win->click_point.y, 0 ); // shift back //printf( "panx %f pany %f scale %.2f stheta %.2f sphi %.2f\n", *************** *** 1576,1580 **** // draw the models ! g_hash_table_foreach( world->models, (GHFunc)model_draw_cb, NULL ); if( win->show_bboxes ) // draw bounding boxes --- 1497,1503 ---- // draw the models ! //g_hash_table_foreach( world->models, (GHFunc)model_draw_cb, NULL ); ! ! g_list_foreach( world->children, (GFunc)model_draw_cb, NULL ); if( win->show_bboxes ) // draw bounding boxes *************** *** 1593,1596 **** --- 1516,1611 ---- g_hash_table_foreach( world->models, (GHFunc)model_draw_data_cb, NULL ); + if( world->win->selection_active + && world->win->selection_active->sense_poly ) + { + stg_model_t* mod = world->win->selection_active; + + push_color_stgcolor( stg_lookup_color( "green" )); + + gl_draw_polygon_bbox( mod->sense_poly ); + pop_color(); + + // outline the polgons that the selected robot intersects with + push_color_stgcolor( stg_lookup_color( "blue" )); + + GList *a, *b; + //for( a=mod->polys ; a; a=a->next ) + //for( b = ((stg_polygon_t*)a->data)->intersectors; b; b=b->next ) + for( b = mod->sense_poly->intersectors; b; b=b->next ) + { + stg_polygon_t* p = (stg_polygon_t*)b->data; + + glPushMatrix(); + + stg_pose_t pose; + stg_model_get_global_pose( p->mod, &pose ); + + // move into this model's coordinate frame + glTranslatef( pose.x, pose.y, pose.z ); + glRotatef( RTOD(pose.a), 0,0,1 ); + + //gl_draw_polygon_bbox( p ); + gl_draw_polygon3d( p ); + + glPopMatrix(); + } + + + //glMatrixMode( GL_PROJECTION ); + /* glPushMatrix(); */ + + /* glLoadIdentity(); */ + /* glFrustum( 0, 361, */ + /* 0, 100, */ + /* zclip, 2*zclip ); */ + + /* glScalef ( 1, 1, 1.0 ); // zoom */ + + + // 1 pixel-per unit + } + /* else */ + /* { */ + /* push_color_rgb( 1,0,0 ); */ + /* glRecti( 0,0,1,1 ); */ + /* pop_color(); */ + + /* for( GList* b = mod->sense_poly->intersectors; b; b=b->next ) */ + /* { */ + /* stg_polygon_t* p = (stg_polygon_t*)b->data; */ + + /* glPushMatrix(); */ + + /* //stg_pose_t gpose; */ + /* //stg_model_get_global_pose( world->win->selection_last, &gpose ); */ + + /* //glTranslatef( -gpose.x + (pixels_width/2.0)/win->scale, */ + /* // -gpose.y + (pixels_height/2.0)/win->scale, */ + /* // -zclip/2.0 ); */ + + + /* /\* stg_pose_t pose; *\/ */ + /* /\* stg_model_get_global_pose( p->mod, &pose ); *\/ */ + + /* /\* // move into this model's coordinate frame *\/ */ + /* /\* glTranslatef( pose.x, pose.y, pose.z ); *\/ */ + /* /\* glRotatef( RTOD(pose.a), 0,0,1 ); *\/ */ + + /* /\* //gl_draw_polygon_bbox( p ); *\/ */ + /* /\* gl_draw_rectpolygon3d( p ); *\/ */ + + /* push_color_rgba( 1,0,0,1 ); */ + /* glRectf( 0, 0, 1, 1 ); */ + /* pop_color(); */ + + /* glPopMatrix(); */ + /* //glMatrixMode( GL_MODELVIEW ); */ + /* } */ + /* // glPopMatrix(); */ + + + /* pop_color(); */ + /* } */ + //glEndList(); *************** *** 1789,1794 **** // world, &lobx, &loby, &lobz ); ! world->win->panx += (event->x - beginX) ;//(obx - lobx); ! world->win->pany -= (event->y - beginY); //(oby - loby); redraw = TRUE; --- 1804,1809 ---- // world, &lobx, &loby, &lobz ); ! world->win->panx -= (event->x - beginX) ;//(obx - lobx); ! world->win->pany += (event->y - beginY); //(oby - loby); redraw = TRUE; Index: world.c =================================================================== RCS file: /cvsroot/playerstage/code/stage/src/world.c,v retrieving revision 1.63.4.5 retrieving revision 1.63.4.6 diff -C2 -d -r1.63.4.5 -r1.63.4.6 *** world.c 27 Feb 2007 02:54:08 -0000 1.63.4.5 --- world.c 2 Mar 2007 04:09:50 -0000 1.63.4.6 *************** *** 119,219 **** } - /* void model_clear_intersectors( gpointer key, stg_model_t* mod, gpointer user ) */ - /* { */ - /* g_list_free( mod->intersectors ); */ - /* mod->intersectors = NULL; */ - /* } */ - - /* void world_intercept_array_print( stg_world_t* world ) */ - /* { */ - /* int i,j; */ - /* /\* printf( " " ); *\/ */ - /* /\* for( j=0; j<world->section_count; j++ ) *\/ */ - /* /\* printf( "%d", j); *\/ */ - /* /\* puts(""); *\/ */ - - /* /\* for( i=0; i<world->section_count; i++ ) *\/ */ - /* /\* { *\/ */ - /* /\* printf( "%d ", i ); *\/ */ - /* /\* for( j=0; j<world->section_count; j++ ) *\/ */ - /* /\* printf( "%d", world->intersections[i][j] ); *\/ */ - /* /\* puts(""); *\/ */ - /* /\* } *\/ */ - /* /\* puts(""); *\/ */ - - /* printf( " " ); */ - /* for( j=0; j<world->section_count; j++ ) */ - /* printf( "%d", j); */ - /* puts(""); */ - - /* for( i=0; i<world->section_count; i++ ) */ - /* { */ - /* printf( "%d ", i ); */ - /* for( j=0; j<world->section_count; j++ ) */ - /* printf( "%c", world->intersections[i * world->section_count + j] > 2 ? 'X' : ' ' ); */ - /* puts(""); */ - /* } */ - /* puts(""); */ - - /* for( i=0; i<world->section_count; i++ ) */ - /* { */ - /* stg_model_t* mod = stg_world_get_model( world, i ); */ - - /* if( mod ) */ - /* { */ - /* printf( "%s intersects with ", mod->token ); */ - - /* for( j=0; j<world->section_count; j++ ) */ - /* { */ - /* if( world->intersections[i* world->section_count + j ] > 2 ) */ - /* { */ - /* stg_model_t* hit = stg_world_get_model( world, j ); */ - /* if( hit ) */ - /* printf( "%s ", hit->token ); */ - /* else */ - /* printf( "<bad pointer> " ); */ - /* } */ - /* } */ - /* puts( "" ); */ - /* } */ - /* } */ - /* } */ - - /* void world_intersect_incr( stg_world_t* world, */ - /* stg_model_t* a, */ - /* stg_model_t* b ) */ - /* { */ - /* int a_index = a->id * world->section_count + b->id; */ - /* int b_index = b->id * world->section_count + a->id; */ - - /* world->intersections[ a_index ]++; */ - /* world->intersections[ b_index ]++; */ - - /* if( world->intersections[ a_index ] == 3 ) */ - /* { */ - /* a->intersectors = g_list_prepend( a->intersectors, b ); */ - /* b->intersectors = g_list_prepend( b->intersectors, a ); */ - /* } */ - /* // print_intercept_array( world ); */ - /* } */ - - /* void world_intersect_decr( stg_world_t* world, */ - /* stg_model_t* a, */ - /* stg_model_t* b ) */ - /* { */ - /* int a_index = a->id * world->section_count + b->id; */ - /* int b_index = b->id * world->section_count + a->id; */ - - /* world->intersections[ a_index ]--; */ - /* world->intersections[ b_index ]--; */ - - /* if( world->intersections[ a_index ] == 2 ) */ - /* { */ - /* a->intersectors = g_list_remove( a->intersectors, b ); */ - /* b->intersectors = g_list_remove( b->intersectors, a ); */ - /* } */ - - /* //print_intercept_array( world ); */ - /* } */ stg_endpoint_t* endpoint_list_sort( stg_endpoint_t* list ) --- 119,122 ---- *************** *** 348,357 **** int section_count = wf_section_count(); ! ! // there can't be more models than sections, so we'll use the number ! // of sections to build an intersection test array ! //world->intersections = calloc( section_count*section_count, sizeof(unsigned short) ); ! //world->intersections = calloc( 1024*1024, sizeof(unsigned short) ); ! world->section_count = section_count; --- 251,255 ---- int section_count = wf_section_count(); ! world->section_count = section_count; *************** *** 410,427 **** // then // scan axis lists for intersections - - - // clear the intersection table (TODO - speed this up) - //memset( world->intersections, 0, - // world->section_count * world->section_count * sizeof(unsigned short)); - compute_intersections( world->endpts.x ); compute_intersections( world->endpts.y ); compute_intersections( world->endpts.z ); - //puts( "FINISHED CREATING WORLD. ARRAY IS:" ); - //print_intercept_array( world ); - //print_endpoint_list( "Z lIST", world->endpts.z ); - global_world = world; --- 308,315 ---- *************** *** 450,455 **** world->id = id; world->token = strdup( token ); ! world->models = g_hash_table_new_full( g_int_hash, g_int_equal, ! NULL, stg_model_destroy ); world->models_by_name = g_hash_table_new( g_str_hash, g_str_equal ); world->sim_time = 0.0; --- 338,346 ---- world->id = id; world->token = strdup( token ); ! world->models = g_hash_table_new_full( g_int_hash, ! g_int_equal, ! NULL, ! (GDestroyNotify)stg_model_destroy ); ! world->models_by_name = g_hash_table_new( g_str_hash, g_str_equal ); world->sim_time = 0.0; *************** *** 621,667 **** - - - /* // return a list of pointers to all the models who have bounds that */ - /* // intersect the given bbox. */ - /* GList* stg_world_models_in_bbox3d( stg_world_t* world, stg_bbox3d_t* bbox ) */ - /* { */ - /* // TODO - this just does the X axis for now, and very inefficiently */ - /* // at that :) */ - - /* /\* GList* x_intersectors = NULL; *\/ */ - /* /\* GList* it; *\/ */ - /* /\* for( it=world->endpts.x; it; it=it->next ) *\/ */ - /* /\* { *\/ */ - /* /\* stg_endpoint_t* ep = (stg_endpoint_t*)it->data; *\/ */ - - /* /\* if( ep->value > bbox->x.min && *\/ */ - /* /\* ep->value < bbox->x.max && *\/ */ - /* /\* ep->mod *\/ */ - - /* /\* ) *\/ */ - /* /\* intersectors = g_list_prepend( intersectors, ep->mod ); *\/ */ - /* /\* } *\/ */ - - /* /\* GList* intersectors = NULL; *\/ */ - /* /\* GList* it; *\/ */ - /* /\* for( it=world->children; it; it=it->next ) *\/ */ - /* /\* { *\/ */ - /* /\* stg_model_t* mod = (stg_model_t*)it->data; *\/ */ - - /* /\* if( mod->endpts[0].value < bbox->x.max && *\/ */ - /* /\* mod->endpts[1].value > bbox->x.min && *\/ */ - /* /\* mod->endpts[2].value < bbox->y.max && *\/ */ - /* /\* mod->endpts[3].value > bbox->y.min && *\/ */ - /* /\* mod->endpts[4].value < bbox->z.max && *\/ */ - /* /\* mod->endpts[5].value > bbox->z.min ) *\/ */ - - /* /\* intersectors = g_list_prepend( intersectors, mod ); *\/ */ - /* /\* } *\/ */ - - /* /\* return intersectors; *\/ */ - /* return NULL; */ - /* } */ - int stg_world_model_destroy( stg_world_t* world, stg_id_t model ) { --- 512,515 ---- Index: stage_internal.h =================================================================== RCS file: /cvsroot/playerstage/code/stage/src/stage_internal.h,v retrieving revision 1.58.2.8 retrieving revision 1.58.2.9 diff -C2 -d -r1.58.2.8 -r1.58.2.9 *** stage_internal.h 27 Feb 2007 02:54:08 -0000 1.58.2.8 --- stage_internal.h 2 Mar 2007 04:09:50 -0000 1.58.2.9 *************** *** 520,523 **** --- 520,530 ---- + // bounding box intersection ----------------------------------------------------= + + stg_endpoint_t* insert_endpoint_sorted( stg_endpoint_t* head, stg_endpoint_t* ep ); + stg_endpoint_t* remove_endpoint( stg_endpoint_t* head, stg_endpoint_t* ep ); + void stg_polygons_intersect_incr( stg_polygon_t* poly1, stg_polygon_t* poly2 ); + void stg_polygons_intersect_decr( stg_polygon_t* poly1, stg_polygon_t* poly2 ); + // RAYTRACE ITERATORS ------------------------------------------------------------- Index: model.c =================================================================== RCS file: /cvsroot/playerstage/code/stage/src/model.c,v retrieving revision 1.153.2.11 retrieving revision 1.153.2.12 diff -C2 -d -r1.153.2.11 -r1.153.2.12 *** model.c 27 Feb 2007 02:54:08 -0000 1.153.2.11 --- model.c 2 Mar 2007 04:09:50 -0000 1.153.2.12 *************** *** 205,216 **** } - /* GList* add_endpoint_to_list( GList* list, stg_endpoint_t* ep ) */ - /* { */ - /* // add the endpoint to the list, while stashing a pointer to the new */ - /* // list element inside the endpoint for fast access to its neighbors */ - /* // later. */ - /* list = ep->list = g_list_prepend( list, ep ); */ - /* return g_list_sort( list, (GCompareFunc)endpoint_sort ); */ - /* } */ // careful: no error checking - this must be fast --- 205,208 ---- *************** *** 375,380 **** // endpoints // this is clunky ! int e; ! for( e=0; e<6; e++ ) { mod->sense_poly->epts[e].polygon = mod->sense_poly; --- 367,371 ---- // endpoints // this is clunky ! for( int e=0; e<6; e++ ) { mod->sense_poly->epts[e].polygon = mod->sense_poly; *************** *** 547,554 **** return TRUE; ! //assert( mod->children ); ! ! GList* it; ! for(it=mod->children; it; it=it->next ) { if( stg_model_is_descendent( (stg_model_t*)it->data, testmod )) --- 538,542 ---- return TRUE; ! for( GList* it=mod->children; it; it=it->next ) { if( stg_model_is_descendent( (stg_model_t*)it->data, testmod )) *************** *** 651,656 **** { // call this function for all the model's children ! GList* it; ! for( it=mod->children; it; it=it->next ) stg_model_map_with_children( (stg_model_t*)it->data, render); --- 639,643 ---- { // call this function for all the model's children ! for( GList* it=mod->children; it; it=it->next ) stg_model_map_with_children( (stg_model_t*)it->data, render); *************** *** 880,886 **** printf( "%s (list at %p)\n", prefix, ep ); ! int i=0; ! for( ; ep; ep=ep->next ) { //assert( i < 30 ); --- 867,873 ---- printf( "%s (list at %p)\n", prefix, ep ); ! // int i=0; ! for( int i=0; ep; ep=ep->next ) { //assert( i < 30 ); *************** *** 959,964 **** // poly, poly->mod->token ); ! int r; ! for( r=0; r<poly->points->len; r++ ) { pt = & g_array_index( poly->points, stg_point_t, r ); --- 946,950 ---- // poly, poly->mod->token ); ! for( int r=0; r<poly->points->len; r++ ) { pt = & g_array_index( poly->points, stg_point_t, r ); *************** *** 1122,1127 **** // endpoints // this is clunky ! int e; ! for( e=0; e<6; e++ ) { poly->epts[e].polygon = poly; --- 1108,1112 ---- // endpoints // this is clunky ! for( int e=0; e<6; e++ ) { poly->epts[e].polygon = poly; *************** *** 1232,1237 **** void stg_model_clear_polygons( stg_model_t* mod ) { ! GList* it; ! for( it=mod->polys; it; it=it->next ) stg_polygon_destroy( (stg_polygon_t*)it->data ); --- 1217,1221 ---- void stg_model_clear_polygons( stg_model_t* mod ) { ! for( GList* it=mod->polys; it; it=it->next ) stg_polygon_destroy( (stg_polygon_t*)it->data ); *************** *** 1409,1420 **** memcpy( &mod->pose, pose, sizeof(stg_pose_t)); - // TODO - can we do this less frequently? maybe not... ! GList *it; ! for( it=mod->children; it; it=it->next ) //model_update_bbox( (stg_model_t*)it->data ); g_list_foreach( ((stg_model_t*)it->data)->polys, ! polygon_global_bounds_calc_cb, NULL ); double hitx, hity; --- 1393,1402 ---- memcpy( &mod->pose, pose, sizeof(stg_pose_t)); // TODO - can we do this less frequently? maybe not... ! for( GList* it=mod->children; it; it=it->next ) //model_update_bbox( (stg_model_t*)it->data ); g_list_foreach( ((stg_model_t*)it->data)->polys, ! (GFunc)polygon_global_bounds_calc_cb, NULL ); double hitx, hity; *************** *** 1425,1429 **** } ! g_list_foreach( mod->polys, polygon_global_bounds_calc_cb, NULL ); // also deal with the sensor volume --- 1407,1411 ---- } ! g_list_foreach( mod->polys, (GFunc)polygon_global_bounds_calc_cb, NULL ); // also deal with the sensor volume *************** *** 1470,1475 **** geom->size.y ); ! g_list_foreach( mod->polys, polygon_local_bounds_calc_cb, NULL ); ! g_list_foreach( mod->polys, polygon_global_bounds_calc_cb, NULL ); // re-render int the matrix --- 1452,1457 ---- geom->size.y ); ! g_list_foreach( mod->polys, (GFunc)polygon_local_bounds_calc_cb, NULL ); ! g_list_foreach( mod->polys, (GFunc)polygon_global_bounds_calc_cb, NULL ); // re-render int the matrix *************** *** 1672,1677 **** printf( "Polyline %p contains %d points [", l, (int)l->points_count ); ! int p; ! for( p=0; p<l->points_count; p++ ) printf( "[%.2f,%.2f] ", l->points[p].x, l->points[p].y ); --- 1654,1659 ---- printf( "Polyline %p contains %d points [", l, (int)l->points_count ); ! ! for( int p=0; p<l->points_count; p++ ) printf( "[%.2f,%.2f] ", l->points[p].x, l->points[p].y ); *************** *** 1685,1690 **** l, (int)p_count ); ! int a; ! for( a=0; a<p_count; a++ ) stg_polyline_print( &l[a] ); } --- 1667,1671 ---- l, (int)p_count ); ! for( int a=0; a<p_count; a++ ) stg_polyline_print( &l[a] ); } |