From: Richard V. <rt...@us...> - 2007-11-17 15:31:22
|
Update of /cvsroot/playerstage/code/stage/libstage In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10238 Modified Files: Tag: opengl Makefile.manual block.cc gl.c model.cc model_laser.cc stage.hh stest.cc world.cc Added Files: Tag: opengl Makefile.fl worldgui.cc Log Message: moved to fltk. gui 75% there --- NEW FILE: worldgui.cc --- #include "stage.hh" #include <FL/fl_draw.H> #include <FL/Fl_Menu_Button.H> extern void glPolygonOffsetEXT (GLfloat, GLfloat); void dummy_cb(Fl_Widget*, void* v) { } void view_toggle_cb(Fl_Widget* w, bool* view ) { assert(view); *view = !(*view); Fl_Menu_Item* item = (Fl_Menu_Item*)((Fl_Menu_*)w)->mvalue(); *view ? item->check() : item->clear(); } void timer_cb( void* v) { StgWorldGui* w = (StgWorldGui*)v; w->redraw(); if( w->show_clock ) w->redraw_overlay(); Fl::repeat_timeout(0.1, timer_cb, v); } StgWorldGui::StgWorldGui(int W,int H,const char*L) : Fl_Gl_Window(0,0,W,H,L) { //Fl_Menu_Bar* menubar = new Fl_Menu_Bar(0,0, W, 30);// 640, 30); //menubar->menu(menuitems); //menubar->show(); selected_models = NULL; graphics = true; dragging = false; startx = starty = 0; panx = pany = stheta = sphi = 0.0; scale = 15.0; fg = 1.0; bg = 0.0; resizable(this); end(); follow_selection = false; show_clock = true; show_quadtree = false; show_occupancy = false; show_geom = false; show_boxes = true; show_grid = false; show_data = true; show_cfg = false; show_cmd = false; show_thumbnail = false; show_trails = false; // build the menus menu = new Fl_Menu_Button( 0,0,0,0 ); menu->type( Fl_Menu_Button::POPUP3 ); //menu->add( "&File", 0, 0, 0, FL_SUBMENU ); //menu->add( "File/&Save File", FL_CTRL + 's', (Fl_Callback *)dummy_cb ); //menu->add( "File/Save File &As...", FL_CTRL + FL_SHIFT + 's', (Fl_Callback *)dummy_cb, 0, FL_MENU_DIVIDER ); //menu->add( "File/E&xit", FL_CTRL + 'q', (Fl_Callback *)dummy_cb, 0 ); //menu->add( "&View", 0, 0, 0, FL_SUBMENU ); menu->add( "Data", FL_CTRL+'z', (Fl_Callback *)view_toggle_cb, &show_data, FL_MENU_TOGGLE|FL_MENU_VALUE ); menu->add( "Blocks", FL_CTRL+'b', (Fl_Callback *)view_toggle_cb, &show_boxes, FL_MENU_TOGGLE|FL_MENU_VALUE ); //menu->add( "View/Clock", FL_CTRL+'c', (Fl_Callback *)view_toggle_cb, &show_clock, FL_MENU_TOGGLE|FL_MENU_VALUE ); menu->add( "Grid", FL_CTRL + 'c', (Fl_Callback *)view_toggle_cb, &show_grid, FL_MENU_TOGGLE|FL_MENU_VALUE ); menu->add( "Occupancy", FL_CTRL + 'o', (Fl_Callback *)view_toggle_cb, &show_occupancy, FL_MENU_TOGGLE|FL_MENU_VALUE ); menu->add( "Tree", FL_CTRL + 't', (Fl_Callback *)view_toggle_cb, &show_quadtree, FL_MENU_TOGGLE|FL_MENU_VALUE ); //menu->add( "Help", 0, 0, 0, FL_SUBMENU ); //menu->add( "Help/About Stage...", FL_CTRL + 'f', (Fl_Callback *)dummy_cb ); //menu->add( "Help/HTML Documentation", FL_CTRL + 'g', (Fl_Callback *)dummy_cb ); show(); // must do this so that the GL context is created before configuring GL // set gl state that won't change every redraw glClearColor ( 0.7, 0.7, 0.8, 1.0); glDisable(GL_LIGHTING); glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS); glCullFace( GL_BACK ); glEnable (GL_CULL_FACE); glEnable( GL_BLEND ); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glEnable( GL_LINE_SMOOTH ); glHint (GL_LINE_SMOOTH_HINT, GL_FASTEST); glDepthMask(GL_TRUE); // install a font gl_font( FL_HELVETICA, 12 ); // start the timer that causes regular redraws Fl::add_timeout( 0.1, timer_cb, this); } bool StgWorldGui::RealTimeUpdate() { // puts( "RTU" ); bool res = StgWorld::RealTimeUpdate(); Fl::check(); return res; } bool StgWorldGui::Update() { // puts( "RTU" ); bool res = StgWorld::Update(); Fl::check(); return res; } void StgWorldGui::AddModel( StgModel* mod ) { mod->InitGraphics(); StgWorld::AddModel( mod ); } StgModel* StgWorldGui::Select( int x, int y ) { // render all models in a unique color make_current(); // make sure the GL context is current glClearColor ( 0,0,0,1 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glDisable(GL_DITHER); // render all top-level, draggable models in a color that is their // id + a 100% alpha value for( GList* it=StgWorld::children; it; it=it->next ) { StgModel* mod = (StgModel*)it->data; if( mod->gui_mask & STG_MOVE_TRANS ) { uint32_t col = (mod->id | 0xFF000000); glColor4ubv( (GLubyte*)&col ); mod->DrawPicker(); } } // read the color of the pixel in the back buffer under the mouse // pointer GLint viewport[4]; glGetIntegerv(GL_VIEWPORT,viewport); uint32_t id; glReadPixels( x,viewport[3]-y,1,1, GL_RGBA,GL_UNSIGNED_BYTE,(void*)&id ); // strip off the alpha channel byte to retrieve the model id id &= 0x00FFFFFF; StgModel* mod = (StgModel*) g_hash_table_lookup( models_by_id, &id ); printf("%p %s %d\n", mod, mod ? mod->Token() : "", id ); glEnable(GL_DITHER); glClearColor ( 0.7, 0.7, 0.8, 1.0); if( mod ) // we clicked on a root model { // if it's already selected if( GList* link = g_list_find( selected_models, mod ) ) { // remove it from the selected list selected_models = g_list_remove_link( selected_models, link ); mod->disabled = false; } else { selected_models = g_list_prepend( selected_models, mod ); mod->disabled = true; } invalidate(); } return mod; } void StgWorldGui::CanvasToWorld( int px, int py, double *wx, double *wy, double* wz ) { // convert from window pixel to world coordinates //int width = widget->allocation.width; int viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); GLdouble modelview[16]; glGetDoublev(GL_MODELVIEW_MATRIX, modelview); GLdouble projection[16]; glGetDoublev(GL_PROJECTION_MATRIX, projection); GLfloat pz; glReadPixels( px, h()-py, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pz ); gluUnProject( px, w()-py, pz, modelview, projection, viewport, wx,wy,wz ); //printf( "Z: %.2f\n", pz ); //printf( "FINAL: x:%.2f y:%.2f z:%.2f\n", // *wx,*wy,zz ); } int StgWorldGui::handle(int event) { switch(event) { case FL_MOUSEWHEEL: if( selected_models ) { // rotate all selected models for( GList* it = selected_models; it; it=it->next ) { StgModel* mod = (StgModel*)it->data; mod->AddToPose( 0,0,0, 0.1*(double)Fl::event_dy() ); } redraw(); } else { scale -= 0.5 * (double)Fl::event_dy(); if( scale < 1 ) scale = 1; invalidate(); } return 1; case FL_MOVE: // moused moved while no button was pressed //printf( "mouse moved %d %d\n", Fl::event_x(), Fl::event_y() ); //printf( "mouse delta %d %d\n", Fl::event_dx(), Fl::event_dy() ); if( Fl::event_state( FL_CTRL ) ) { int dx = Fl::event_x() - startx; int dy = Fl::event_y() - starty; stheta -= 0.01 * (double)dy; sphi += 0.01 * (double)dx; stheta = constrain( stheta, 0, M_PI/2.0 ); invalidate(); } if( Fl::event_state( FL_ALT ) ) { int dx = Fl::event_x() - startx; int dy = Fl::event_y() - starty; panx -= dx; pany += dy; invalidate(); } startx = Fl::event_x(); starty = Fl::event_y(); return 1; case FL_PUSH: // button pressed puts( "PUSH" ); switch( Fl::event_button() ) { case 1: startx = Fl::event_x(); starty = Fl::event_y(); if( Select( startx, starty ) ) dragging = true; return 1; case 3: { puts( "POPUP" ); menu->popup(); return 1; } default: return 0; } case FL_DRAG: // mouse moved while button was pressed { int dx = Fl::event_x() - startx; int dy = Fl::event_y() - starty; if( Fl::event_button() == 1 ) { if( selected_models && dragging ) { double sx,sy,sz; CanvasToWorld( startx, starty, &sx, &sy, &sz ); double x,y,z; CanvasToWorld( Fl::event_x(), Fl::event_y(), &x, &y, &z ); // move all selected models to the mouse pointer for( GList* it = selected_models; it; it=it->next ) { StgModel* mod = (StgModel*)it->data; mod->AddToPose( x-sx, y-sy, 0, 0 ); } } else { panx -= dx; pany += dy; } } startx = Fl::event_x(); starty = Fl::event_y(); invalidate(); } return 1; case FL_RELEASE: // mouse button released // unselect everyone unless shift is pressed if( ! Fl::event_state( FL_SHIFT ) ) { for( GList* it=selected_models; it; it=it->next ) ((StgModel*)it->data)->disabled = false; g_list_free( selected_models ); selected_models = NULL; dragging = false; invalidate(); } return 1; case FL_FOCUS : case FL_UNFOCUS : //.... Return 1 if you want keyboard events, 0 otherwise return 1; case FL_KEYBOARD: switch( Fl::event_key() ) { case 'p': // pause paused = !paused; break; case ' ': // space bar sphi = stheta = 0.0; invalidate(); break; case FL_Left: panx += 10; break; case FL_Right: panx -= 10; break; case FL_Down: pany += 10; break; case FL_Up: pany -= 10; break; default: return 0; // keypress unhandled } invalidate(); return 1; //case FL_SHORTCUT: ///... shortcut, key is in Fl::event_key(), ascii in Fl::event_text() // ... Return 1 if you understand/use the shortcut event, 0 otherwise... //return 1; default: // pass other events to the base class... printf( "EVENT %d\n", event ); return Fl_Gl_Window::handle(event); } } void StgWorldGui::FixViewport(int W,int H) { glLoadIdentity(); glViewport(0,0,W,H); } void StgWorldGui::draw() { if (!valid()) { valid(1); FixViewport(w(), h()); double zclip = hypot(width, height) * scale; double pixels_width = w();//canvas->allocation.width; double pixels_height = h();//canvas->allocation.height ; //double width = w() / scale; //double height = h() / scale; glMatrixMode (GL_PROJECTION); glLoadIdentity (); // 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, zclip ); /* glFrustum( 0, pixels_width, */ /* 0, pixels_height, */ /* 0.1, zclip ); */ glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glTranslatef( -panx, -pany, -zclip / 2.0 ); glRotatef( RTOD(-stheta), 1,0,0); //glTranslatef( -panx * cos(sphi) - pany*sin(sphi), // panx*sin(sphi) - pany*cos(sphi), 0 ); glRotatef( RTOD(sphi), 0.0, 0.0, 1.0); // rotate about z - pitch // meter scale glScalef ( scale, scale, scale ); // zoom } // Clear screen to bg color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Draw 'X' in fg color //glColor3f(fg, fg, fg); //glBegin(GL_LINE_STRIP); glVertex2f(w(), h()); glVertex2f(-w(),-h()); glEnd(); //glBegin(GL_LINE_STRIP); glVertex2f(w(),-h()); glVertex2f(-w(), h()); glEnd(); //gluLookAt( 0,0,10, // 0,0,0, // 0,1,0 ); /* gluLookAt( win->panx, */ /* win->pany + win->stheta, */ /* 10, */ /* win->panx, */ /* win->pany, */ /* 0, */ /* sin(win->sphi), */ /* cos(win->sphi), */ /* 0 ); */ // if( follow_selection && selected_models ) // { // glTranslatef( 0,0,-zclip/2.0 ); // // meter scale // glScalef ( scale, scale, scale ); // zoom // // get the pose of the model at the head of the selected models // // list // stg_pose_t gpose; // ((StgModel*)selected_models->data)->GetGlobalPose( &gpose ); // //glTranslatef( -gpose.x + (pixels_width/2.0)/scale, // // -gpose.y + (pixels_height/2.0)/scale, // // -zclip/2.0 ); // // pixel scale // glTranslatef( -gpose.x, // -gpose.y, // 0 ); // } // else // { // pixel scale //glTranslatef( 0,0, -MAX(width,height) ); // TODO - rotate around the mouse pointer or window center, not the //origin - the commented code is close, but not quite right //glRotatef( RTOD(sphi), 0.0, 0.0, 1.0); // rotate about z - pitch //glTranslatef( -click_point.x, -click_point.y, 0 ); // shift back //printf( "panx %f pany %f scale %.2f stheta %.2f sphi %.2f\n", // panx, pany, scale, stheta, sphi ); //} // // draw the world size rectangle in white // // draw the floor a little pushed into the distance so it doesn't z-fight with the // models glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0, 1.0); glColor3f( 1,1,1 ); glRectf( -width/2.0, -height/2.0, width/2.0, height/2.0 ); glDisable(GL_POLYGON_OFFSET_FILL); // draw the model bounding boxes //g_hash_table_foreach( models, (GHFunc)model_draw_bbox, NULL); //PRINT_DEBUG1( "Colorstack depth %d", // colorstack.Length() ); if( show_quadtree || show_occupancy ) { glDisable( GL_LINE_SMOOTH ); glLineWidth( 1 ); glPushMatrix(); glTranslatef( -width/2.0, -height/2.0, 1 ); glScalef( 1.0/ppm, 1.0/ppm, 0 ); glPolygonMode( GL_FRONT, GL_LINE ); colorstack.Push(1,0,0); if( show_occupancy ) this->bgrid->Draw( false ); if( show_quadtree ) this->bgrid->Draw( true ); colorstack.Pop(); glPopMatrix(); glEnable( GL_LINE_SMOOTH ); } colorstack.Push( 1, 0, 0 ); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth( 4 ); for( GList* it=selected_models; it; it=it->next ) { ((StgModel*)it->data)->DrawSelected(); //((StgModel*)it->data)->DrawPicker(); } colorstack.Pop(); glLineWidth( 1 ); // draw the models GList* it; if( show_boxes ) for( it=StgWorld::children; it; it=it->next ) ((StgModel*)it->data)->Draw(); // draw the models' data if( show_data ) for( it=StgWorld::children; it; it=it->next ) ((StgModel*)it->data)->DrawData(); // draw anything in the assorted displaylist list // for( it = dl_list; it; it=it->next ) // { // int dl = (int)it->data; // printf( "Calling dl %d\n", dl ); // glCallList( dl ); // } } void StgWorldGui::draw_overlay() { if( show_clock ) { char clockstr[50]; ClockString( clockstr, 50 ); glPushMatrix(); glLoadIdentity(); colorstack.Push( 0,0,0 ); // black gl_draw( clockstr, -w()/2.0 + 5, -h()/2 + 5 ); colorstack.Pop(); glPopMatrix(); } } void StgWorldGui::resize(int X,int Y,int W,int H) { Fl_Gl_Window::resize(X,Y,W,H); FixViewport(W,H); invalidate(); } Index: stest.cc =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/Attic/stest.cc,v retrieving revision 1.1.2.12 retrieving revision 1.1.2.13 diff -C2 -d -r1.1.2.12 -r1.1.2.13 *** stest.cc 1 Nov 2007 07:18:53 -0000 1.1.2.12 --- stest.cc 17 Nov 2007 23:31:22 -0000 1.1.2.13 *************** *** 42,52 **** exit(0); } ! // initialize libstage - //StgWorld::Init( &argc, &argv ); //StgWorld world; ! StgWorldGtk::Init( &argc, &argv ); ! StgWorldGtk world; world.Load( argv[1] ); --- 42,56 ---- exit(0); } ! ! ! StgWorld::Init( &argc, &argv ); ! ! StgWorldGui world(800, 700, "Stage Test Program"); ! // initialize libstage //StgWorld world; ! //StgWorldGtk::Init( &argc, &argv ); ! //StgWorldGtk world; world.Load( argv[1] ); *************** *** 92,96 **** robots[i].ranger = (StgModelRanger*)world.GetModel( namebuf ); assert(robots[i].ranger); ! robots[i].ranger->Subscribe(); } --- 96,100 ---- robots[i].ranger = (StgModelRanger*)world.GetModel( namebuf ); assert(robots[i].ranger); ! //robots[i].ranger->Subscribe(); } *************** *** 106,111 **** // StgModelLaser* laser = lasers[1]; ! while( world.RealTimeUpdate() ) ! // while( world.Update() ) { // nothing --- 110,115 ---- // StgModelLaser* laser = lasers[1]; ! while( world.RealTimeUpdate() ) ! // while( world.Update() ) { // nothing *************** *** 113,116 **** --- 117,121 ---- //if( ! world.RealTimeUpdate() ) //break; + for( int i=0; i<POPSIZE; i++ ) Index: model_laser.cc =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/Attic/model_laser.cc,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -C2 -d -r1.1.2.9 -r1.1.2.10 *** model_laser.cc 1 Nov 2007 07:18:53 -0000 1.1.2.9 --- model_laser.cc 17 Nov 2007 23:31:21 -0000 1.1.2.10 *************** *** 15,20 **** #include <sys/time.h> ! #include <math.h> ! #include <GL/gl.h> #include "stage.hh" --- 15,20 ---- #include <sys/time.h> ! //#include <math.h> ! // #include <GL/gl.h> #include "stage.hh" Index: model.cc =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/Attic/model.cc,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -C2 -d -r1.1.2.11 -r1.1.2.12 *** model.cc 1 Nov 2007 07:18:53 -0000 1.1.2.11 --- model.cc 17 Nov 2007 23:31:21 -0000 1.1.2.12 *************** *** 110,117 **** #include <limits.h> ! #include <assert.h> ! #include <math.h> ! #include <GL/gl.h> ! #include <glib.h> //#define DEBUG --- 110,117 ---- #include <limits.h> ! //#include <assert.h> ! //#include <math.h> ! //#include <GL/gl.h> ! //#include <glib.h> //#define DEBUG *************** *** 236,240 **** this->dl_body = glGenLists(1); this->dl_data = glGenLists(1); ! this->dl_grid = glGenLists(1); } --- 236,240 ---- this->dl_body = glGenLists(1); this->dl_data = glGenLists(1); ! this->dl_grid = glGenLists(1); } *************** *** 710,713 **** --- 710,719 ---- void StgModel::DrawData( void ) { + if( this->data_dirty ) + { + this->DataVisualize(); + this->data_dirty = false; + } + glPushMatrix(); *************** *** 716,720 **** gl_pose_shift( &this->geom.pose ); ! //glCallList( this->dl_data ); glCallList( this->dl_raytrace ); --- 722,726 ---- gl_pose_shift( &this->geom.pose ); ! glCallList( this->dl_data ); glCallList( this->dl_raytrace ); *************** *** 750,754 **** glPushMatrix(); ! // move into this model's local coordinate frame gl_pose_shift( &this->pose ); --- 756,760 ---- glPushMatrix(); ! // move into this model's local coordinate frame gl_pose_shift( &this->pose ); *************** *** 763,773 **** glCallList( this->dl_body ); - if( this->data_dirty ) - { - this->DataVisualize(); - this->data_dirty = false; - } - - glCallList( this->dl_data ); //if( this->say_string ) --- 769,772 ---- *************** *** 775,779 **** // Call my various display lists ! //if( win->show_grid ) && this->gui_grid ) //glCallList( this->dl_grid ); --- 774,778 ---- // Call my various display lists ! //if( this->gui_grid ) //glCallList( this->dl_grid ); *************** *** 789,792 **** --- 788,815 ---- } + void StgModel::DrawPicker( void ) + { + //PRINT_DEBUG1( "Drawing %s", token ); + + glPushMatrix(); + + // move into this model's local coordinate frame + gl_pose_shift( &this->pose ); + gl_pose_shift( &this->geom.pose ); + + // draw the boxes + for( GList* it=blocks; it; it=it->next ) + ((StgBlock*)it->data)->DrawSolid() ; + + // shift up the CS to the top of this model + gl_coord_shift( 0,0, this->geom.size.z, 0 ); + + // recursively draw the tree below this model + LISTMETHOD( this->children, StgModel*, DrawPicker ); + + glPopMatrix(); // drop out of local coords + } + + // call this when the local physical appearance has changed void StgModel::DrawBody( void ) *************** *** 1276,1279 **** --- 1299,1305 ---- void StgModel::UpdatePose( void ) { + if( disabled ) + return; + //stg_velocity_t gvel; //this->GetGlostg_model_get_global_velocity( mod, &gvel ); --- NEW FILE: Makefile.fl --- HEADERS = \ ../config.h \ colors.h \ stage.hh \ worldfile.hh CC = g++ OBS = \ ancestor.o \ block.o \ blockgrid.o \ gl.o \ glcolorstack.o \ model.o \ model_callbacks.o \ model_laser.o \ model_load.o \ model_position.o \ model_props.o \ model_ranger.o \ stage.o \ stest.o \ typetable.o \ world.o \ worldfile.o \ worldgui.o CPPFLAGS= -g -Wall -I.. -I../replace -I/System/Library/Frameworks/OpenGL.framework/Headers `fltk-config --use-gl --cflags` `pkg-config --cflags glib-2.0 gdk-pixbuf-2.0` LIBS= `fltk-config --use-gl --ldflags` `pkg-config --libs gdk-pixbuf-2.0` -framework OpenGL #-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib all: stagefl stagefl: $(OBS) $(HEADERS) g++ -o $@ $(CPPFLAGS) $(OBS) $(LIBS) clean : rm -f *.o *.lo Index: gl.c =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/Attic/gl.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** gl.c 4 Oct 2007 01:17:02 -0000 1.1.2.1 --- gl.c 17 Nov 2007 23:31:21 -0000 1.1.2.2 *************** *** 1,3 **** ! #include <GL/gl.h> #include "stage.hh" --- 1,3 ---- ! #include <gl.h> #include "stage.hh" Index: world.cc =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/Attic/world.cc,v retrieving revision 1.1.2.13 retrieving revision 1.1.2.14 diff -C2 -d -r1.1.2.13 -r1.1.2.14 *** world.cc 1 Nov 2007 07:18:53 -0000 1.1.2.13 --- world.cc 17 Nov 2007 23:31:22 -0000 1.1.2.14 *************** *** 55,60 **** #include <string.h> // for strdup(3) #include <locale.h> ! #define DEBUG #include "stage.hh" --- 55,61 ---- #include <string.h> // for strdup(3) #include <locale.h> + #include <glib-object.h> // fior g_type_init() used by GDKPixbuf objects ! //#define DEBUG #include "stage.hh" *************** *** 206,209 **** --- 207,211 ---- double localratio = (double)interval_sim / (double)average_real_interval; + #ifdef DEBUG if( hours > 0 ) snprintf( str, maxlen, "Time: %uh%02um%02u.%03us\t[%.1f]\tsubs: %d %s", *************** *** 218,221 **** --- 220,235 ---- total_subs, paused ? "--PAUSED--" : "" ); + #else + if( hours > 0 ) + snprintf( str, maxlen, "%uh%02um%02u.%03us\t[%.1f] %s", + hours, minutes, seconds, msec, + localratio, + paused ? "--PAUSED--" : "" ); + else + snprintf( str, maxlen, "%02um%02u.%03us\t[%.1f] %s", + minutes, seconds, msec, + localratio, + paused ? "--PAUSED--" : "" ); + #endif } *************** *** 366,378 **** //PRINT_DEBUG( "StgWorld::Update()" ); ! if( interval_real > 0 || updates % 100 == 0 ) ! { ! char str[64]; ! ClockString( str, 64 ); ! //printf( "Stage timestep: %lu simtime: %lu\n", ! // updates, sim_time ); ! printf( "\r%s", str ); ! fflush(stdout); ! } // update any models that are due to be updated --- 380,392 ---- //PRINT_DEBUG( "StgWorld::Update()" ); ! // if( interval_real > 0 || updates % 100 == 0 ) ! // { ! // char str[64]; ! // ClockString( str, 64 ); ! // //printf( "Stage timestep: %lu simtime: %lu\n", ! // // updates, sim_time ); ! // printf( "\r%s", str ); ! // fflush(stdout); ! // } // update any models that are due to be updated Index: block.cc =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/Attic/block.cc,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** block.cc 30 Oct 2007 01:01:48 -0000 1.1.2.4 --- block.cc 17 Nov 2007 23:31:21 -0000 1.1.2.5 *************** *** 1,6 **** - #include <GL/gl.h> - //#define DEBUG 1 - #include "stage.hh" --- 1,3 ---- *************** *** 52,58 **** for( unsigned int p=0; p<pt_count; p++ ) ! { ! glVertex3f( pts[p].x, pts[p].y, zmax ); ! } glEnd(); --- 49,53 ---- for( unsigned int p=0; p<pt_count; p++ ) ! glVertex3f( pts[p].x, pts[p].y, zmax ); glEnd(); *************** *** 109,112 **** --- 104,113 ---- } + void StgBlock::DrawSolid( void ) + { + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL ); + DrawSides(); + DrawTop(); + } void StgBlock::Map() Index: Makefile.manual =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/Attic/Makefile.manual,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -C2 -d -r1.1.2.6 -r1.1.2.7 *** Makefile.manual 1 Nov 2007 07:18:53 -0000 1.1.2.6 --- Makefile.manual 17 Nov 2007 23:31:21 -0000 1.1.2.7 *************** *** 25,33 **** typetable.o \ world.o \ ! worldgtk.o \ worldfile.o CPPFLAGS= -g -Wall -I.. -I../replace `pkg-config --cflags gtkglext-1.0` ! LIBS= `pkg-config --libs gtkglext-1.0` --- 25,36 ---- typetable.o \ world.o \ ! worldfltk.o \ worldfile.o + # worldgtk.o + + CPPFLAGS= -g -Wall -I.. -I../replace `pkg-config --cflags gtkglext-1.0` ! LIBS= `pkg-config --libs gtkglext-1.0` -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib Index: stage.hh =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/Attic/stage.hh,v retrieving revision 1.1.2.13 retrieving revision 1.1.2.14 diff -C2 -d -r1.1.2.13 -r1.1.2.14 *** stage.hh 1 Nov 2007 07:18:53 -0000 1.1.2.13 --- stage.hh 17 Nov 2007 23:31:22 -0000 1.1.2.14 *************** *** 48,53 **** #include <string.h> #include <glib.h> ! #include <glib-object.h> ! #include <gtk/gtk.h> // todo: consider moving these out --- 48,53 ---- #include <string.h> #include <glib.h> ! //#include <glib-object.h> ! //#include <gtk/gtk.h> // todo: consider moving these out *************** *** 755,759 **** void* arg_off; // argument to callback_off //int default_state; // disabled = 0 ! GtkAction* action; // action associated with this toggle, may be NULL char* path; } stg_property_toggle_args_t; --- 755,759 ---- void* arg_off; // argument to callback_off //int default_state; // disabled = 0 ! //GtkAction* action; // action associated with this toggle, may be NULL char* path; } stg_property_toggle_args_t; *************** *** 1165,1168 **** --- 1165,1169 ---- { return this->token; } + // todo - should these be pure virtual? virtual void PushColor( stg_color_t col ){} // does nothing virtual void PushColor( double r, double g, double b, double a ){} // does nothing *************** *** 1229,1233 **** public: ! StgWorld( void ); StgWorld( const char* token, --- 1230,1234 ---- public: ! StgWorld( void ); StgWorld( const char* token, *************** *** 1435,1438 **** --- 1436,1440 ---- virtual void Save( void ); virtual void Draw( void ); + virtual void DrawPicker( void ); virtual void DrawBody( void ); virtual void DrawData( void ); *************** *** 1726,1729 **** --- 1728,1732 ---- void Draw(); // draw the block in OpenGL + void DrawSolid(); // draw the block in OpenGL as a solid single color stg_point_t* pts; //< points defining a polygon *************** *** 1762,1771 **** //#if _INCLUDE_GTK // TODO - conditional compilation of the GUI ! #include <GL/gl.h> ! #include <GL/glu.h> ! #include <GL/glext.h> ! #include <GL/glx.h> // for XFont for drawing text from X fonts ! #include <gtk/gtk.h> ! #include <gtk/gtkgl.h> // COLOR STACK CLASS --- 1765,1774 ---- //#if _INCLUDE_GTK // TODO - conditional compilation of the GUI ! #include <gl.h> ! #include <glu.h> ! //#include <GL/glext.h> ! //#include <glx.h> // for XFont for drawing text from X fonts ! //#include <gtk/gtk.h> ! //#include <gtk/gtkgl.h> // COLOR STACK CLASS *************** *** 1790,1976 **** }; ! // WORLDGTK class - a world plus a GUI ! class StgWorldGtk : public StgWorld ! { ! public: ! StgWorldGtk( void ); ! virtual ~StgWorldGtk( void ); ! void Configure( int width, ! int height, ! double xscale, ! double yscale, ! double xcenter, ! double ycenter ); ! static void Init( int* argc, char** argv[] ); ! virtual void Load( const char* filename ); ! virtual void Save( void ); ! virtual void Draw( void ); ! virtual bool Update( void ); ! virtual bool RealTimeUpdate( void ); ! virtual void PushColor( stg_color_t col ) ! { colorstack.Push( col ); } ! virtual void PushColor( double r, double g, double b, double a ) ! { colorstack.Push( r,g,b,a ); } ! virtual void PopColor() ! { colorstack.Pop(); } ! void AddViewItem( const gchar *name, ! const gchar *label, ! const gchar *tooltip, ! GCallback callback, ! gboolean is_active, ! void* userdata ); ! protected: ! GlColorStack colorstack; ! virtual void AddModel( StgModel* mod ); ! private: ! GList* selected_models; ///< a list of models that are currently selected by the user ! // Gtk stuff ! GtkWidget* frame; ! GtkWidget *layout; ! GtkWidget *menu_bar; ! //GtkWidget* scrolled_win; ! // The status bar widget ! GtkStatusbar *status_bar; ! GtkProgressBar *perf_bar; ! GtkProgressBar *rt_bar; ! GtkLabel *clock_label; ! GtkActionGroup *action_group; ! // the main drawing widget ! GtkWidget* canvas; ! int dirty; ! int draw_list; ! int debug_list; ! char clock[512]; ! stg_radians_t stheta; ///< view rotation about x axis ! stg_radians_t sphi; ///< view rotation about x y axis ! double scale; ///< view scale ! double panx; ///< pan along x axis in meters ! double pany; ///< pan along y axis in meters ! stg_point_t click_point; ///< The place where the most recent ! ///< mouse click happened, in world coords ! GtkStatusbar* statusbar; ! GtkLabel* timelabel; ! gboolean dragging; ! int frame_series; ! int frame_index; ! int frame_callback_tag; ! int frame_interval; ! stg_image_format_t frame_format; ! stg_pose_t selection_pose_start; ! stg_point_3d_t selection_pointer_start; ! GList* toggle_list; ! int wf_section; ! GdkGLConfig *glconfig; ! // mouse click position, for dragging ! int beginX, beginY; ! private: ! stg_msec_t redraw_interval; ! guint timer_handle; ! bool follow_selection; bool show_quadtree; bool show_occupancy; - bool show_fill; bool show_geom; ! bool show_polygons; bool show_grid; bool show_data; bool show_cfg; bool show_cmd; - bool show_alpha; bool show_thumbnail; - bool show_bboxes; bool show_trails; ! public: ! void SetFollowSelection( bool b ){ this->follow_selection = b; dirty=true; } ! void SetShowFill( bool b ){ this->show_fill = b; dirty=true; } ! void SetShowGeom( bool b ){ this->show_geom = b; dirty=true; } ! void SetShowPolygons( bool b ){ this->show_polygons = b; dirty=true; } ! void SetShowAlpha( bool b ){ this->show_alpha = b; dirty=true; } ! void SetShowThumbnail( bool b ){ this->show_thumbnail = b; dirty=true;} ! void SetShowBBoxes( bool b ){ this->show_bboxes = b; dirty=true; } ! void SetShowTrails( bool b ){ this->show_trails = b; dirty=true; } ! void SetShowGrid( bool b ){ this->show_grid = b; dirty=true; } ! void SetShowQuadtree( bool b ){ this->show_quadtree = b; dirty=true; } ! void SetShowOccupancy( bool b ){ this->show_occupancy = b; dirty=true; } ! ! ! // signal handlers ! //gboolean EvDelete( GtkWidget *widget ); ! //void EvDestroy( GtkWidget *widget, GdkEvent *event ); ! void Realize( GtkWidget *widget ); ! //void EvConfigure( GtkWidget *widget ); ! ! void CanvasMotionNotify( GdkEventMotion *event ); ! void CanvasButtonPress( GdkEventButton *event ); ! void CanvasButtonRelease( GdkEventButton *event ); ! ! gboolean DialogQuit( GtkWindow* parent ); ! void SetTitle( char* txt ); ! void RenderClock(); ! void SetWindowSize( unsigned int w, unsigned int h ); ! ! // exporting screen shots as image files ! void ExportSequenceStart(); ! void ExportSequenceStop(); ! void ExportSequence(); ! void ExportWindow(); ! void SetExportFormat( stg_image_format_t format); ! void SetExportInterval( int interval ); ! ! void Derotate(); ! void Zoom( double multiplier ); ///< multiply the scale factor by the argument ! void SetScale( double scale ); ///< set the scale factor directly ! void AboutBox(); ! GtkWidget* GetCanvas(){ return canvas; } ! ! void PushModelStatus( StgModel* mod, char* verb ); ! void PopModelStatus(); ! // convert canvas window pixel coordinate to 3d world coordinate ! void CanvasToWorld( int px, int py, ! double *wx, double *wy, double* wz ); ! StgModel* NearestRootModel( double wx, double wy ); ! }; ! /** @} */ ! //#ifndef TRUE ! //#define TRUE 1 ! //#endif ! //#ifndef FALSE ! //#define FALSE 0 ! //#endif #define THOUSAND (1e3) --- 1793,2061 ---- }; ! // // WORLDGTK class - a world plus a GUI ! // class StgWorldGtk : public StgWorld ! // { ! // public: ! // StgWorldGtk( void ); ! // virtual ~StgWorldGtk( void ); ! // void Configure( int width, ! // int height, ! // double xscale, ! // double yscale, ! // double xcenter, ! // double ycenter ); ! // static void Init( int* argc, char** argv[] ); ! // virtual void Load( const char* filename ); ! // virtual void Save( void ); ! // virtual void Draw( void ); ! // virtual bool Update( void ); ! // virtual bool RealTimeUpdate( void ); ! // virtual void PushColor( stg_color_t col ) ! // { colorstack.Push( col ); } ! // virtual void PushColor( double r, double g, double b, double a ) ! // { colorstack.Push( r,g,b,a ); } ! // virtual void PopColor() ! // { colorstack.Pop(); } ! // void AddViewItem( const gchar *name, ! // const gchar *label, ! // const gchar *tooltip, ! // GCallback callback, ! // gboolean is_active, ! // void* userdata ); ! // protected: ! // GlColorStack colorstack; ! // virtual void AddModel( StgModel* mod ); ! // private: ! // GList* selected_models; ///< a list of models that are currently selected by the user ! // // Gtk stuff ! // GtkWidget* frame; ! // GtkWidget *layout; ! // GtkWidget *menu_bar; ! // //GtkWidget* scrolled_win; ! // // The status bar widget ! // GtkStatusbar *status_bar; ! // GtkProgressBar *perf_bar; ! // GtkProgressBar *rt_bar; ! // GtkLabel *clock_label; ! // GtkActionGroup *action_group; ! // // the main drawing widget ! // GtkWidget* canvas; ! // int dirty; ! // int draw_list; ! // int debug_list; ! // char clock[512]; ! // stg_radians_t stheta; ///< view rotation about x axis ! // stg_radians_t sphi; ///< view rotation about x y axis ! // double scale; ///< view scale ! // double panx; ///< pan along x axis in meters ! // double pany; ///< pan along y axis in meters ! // stg_point_t click_point; ///< The place where the most recent ! // ///< mouse click happened, in world coords ! // GtkStatusbar* statusbar; ! // GtkLabel* timelabel; ! // gboolean dragging; ! // int frame_series; ! // int frame_index; ! // int frame_callback_tag; ! // int frame_interval; ! // stg_image_format_t frame_format; ! // stg_pose_t selection_pose_start; ! // stg_point_3d_t selection_pointer_start; ! // GList* toggle_list; ! // int wf_section; ! // //GdkGLConfig *glconfig; ! // // mouse click position, for dragging ! // int beginX, beginY; ! // private: ! // stg_msec_t redraw_interval; ! // guint timer_handle; ! // bool follow_selection; ! // bool show_quadtree; ! // bool show_occupancy; ! // bool show_fill; ! // bool show_geom; ! // bool show_polygons; ! // bool show_grid; ! // bool show_data; ! // bool show_cfg; ! // bool show_cmd; ! // bool show_alpha; ! // bool show_thumbnail; ! // bool show_bboxes; ! // bool show_trails; + // public: + // void SetFollowSelection( bool b ){ this->follow_selection = b; dirty=true; } + // void SetShowFill( bool b ){ this->show_fill = b; dirty=true; } + // void SetShowGeom( bool b ){ this->show_geom = b; dirty=true; } + // void SetShowPolygons( bool b ){ this->show_polygons = b; dirty=true; } + // void SetShowAlpha( bool b ){ this->show_alpha = b; dirty=true; } + // void SetShowThumbnail( bool b ){ this->show_thumbnail = b; dirty=true;} + // void SetShowBBoxes( bool b ){ this->show_bboxes = b; dirty=true; } + // void SetShowTrails( bool b ){ this->show_trails = b; dirty=true; } + // void SetShowGrid( bool b ){ this->show_grid = b; dirty=true; } + // void SetShowQuadtree( bool b ){ this->show_quadtree = b; dirty=true; } + // void SetShowOccupancy( bool b ){ this->show_occupancy = b; dirty=true; } + + + // // signal handlers + // //gboolean EvDelete( GtkWidget *widget ); + // //void EvDestroy( GtkWidget *widget, GdkEvent *event ); + // void Realize( GtkWidget *widget ); + // //void EvConfigure( GtkWidget *widget ); + + // void CanvasMotionNotify( GdkEventMotion *event ); + // void CanvasButtonPress( GdkEventButton *event ); + // void CanvasButtonRelease( GdkEventButton *event ); + + // gboolean DialogQuit( GtkWindow* parent ); + // void SetTitle( char* txt ); + // void RenderClock(); + // void SetWindowSize( unsigned int w, unsigned int h ); + + // // exporting screen shots as image files + // void ExportSequenceStart(); + // void ExportSequenceStop(); + // void ExportSequence(); + // void ExportWindow(); + // void SetExportFormat( stg_image_format_t format); + // void SetExportInterval( int interval ); + + // void Derotate(); + // void Zoom( double multiplier ); ///< multiply the scale factor by the argument + // void SetScale( double scale ); ///< set the scale factor directly + // void AboutBox(); + // GtkWidget* GetCanvas(){ return canvas; } + + // void PushModelStatus( StgModel* mod, char* verb ); + // void PopModelStatus(); + + // // convert canvas window pixel coordinate to 3d world coordinate + // void CanvasToWorld( int px, int py, + // double *wx, double *wy, double* wz ); + + // StgModel* NearestRootModel( double wx, double wy ); + + // }; + + /** @} */ + + /* FLTK code - experimenting with replacing GTK with a more portable + and less bulky framework */ + #include <FL/Fl.H> + #include <FL/Fl_Window.H> + #include <FL/Fl_Value_Slider.H> + #include <FL/Fl_Menu_Button.H> + #include <FL/Fl_Gl_Window.H> + #include <FL/gl.h> + + class StgGlWindow; + + class StgWorldGui : public StgWorld, public Fl_Gl_Window + { + protected: + GlColorStack colorstack; + double scale; + + double fg; // foreground brightness + double bg; // background brightness + double panx, pany, stheta, sphi; + + int startx, starty; + bool dragging; + + //int overlay_sides; + //bool ctrl_down; + + GList* selected_models; ///< a list of models that are currently selected by the user + + public: + StgWorldGui(int W,int H,const char*L=0); + StgGlWindow* gl; + //Fl_Menu_Bar* menubar; + + bool follow_selection; bool show_quadtree; bool show_occupancy; bool show_geom; ! bool show_boxes; bool show_grid; bool show_data; bool show_cfg; bool show_cmd; bool show_thumbnail; bool show_trails; + bool show_clock; ! //bool show_bboxes; ! //bool show_alpha; ! //bool show_fill; ! ! bool graphics; ! void FixViewport(int W,int H); ! virtual void draw(); ! virtual void draw_overlay(); ! virtual int handle( int event ); ! void resize(int X,int Y,int W,int H); ! //Fl_Menu_Item* menuitems; ! Fl_Menu_Button* menu; ! void PopupMenu( int x, int y); ! // overloaded StgWorld methods ! virtual bool RealTimeUpdate(); ! virtual bool Update(); ! virtual void AddModel( StgModel* mod ); ! void CanvasToWorld( int px, int py, ! double *wx, double *wy, double* wz ); ! StgModel* Select( int x, int y ); ! ! virtual void PushColor( stg_color_t col ) ! { colorstack.Push( col ); } ! ! virtual void PushColor( double r, double g, double b, double a ) ! { colorstack.Push( r,g,b,a ); } ! ! virtual void PopColor() ! { colorstack.Pop(); } ! }; ! #ifndef TRUE ! #define TRUE 1 ! #endif ! ! #ifndef FALSE ! #define FALSE 0 ! #endif #define THOUSAND (1e3) |