Revision: 6462
http://playerstage.svn.sourceforge.net/playerstage/?rev=6462&view=rev
Author: rtv
Date: 2008-06-03 10:18:26 -0700 (Tue, 03 Jun 2008)
Log Message:
-----------
many GL and FLTK improvements
Modified Paths:
--------------
code/stage/trunk/libstage/CMakeLists.txt
code/stage/trunk/libstage/block.cc
code/stage/trunk/libstage/canvas.cc
code/stage/trunk/libstage/gl.cc
code/stage/trunk/libstage/main.cc
code/stage/trunk/libstage/model.cc
code/stage/trunk/libstage/model_load.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/stage_internal.hh
code/stage/trunk/libstage/world.cc
code/stage/trunk/libstage/worldgui.cc
code/stage/trunk/todo
code/stage/trunk/worlds/fasr.world
code/stage/trunk/worlds/pioneer.inc
Modified: code/stage/trunk/libstage/CMakeLists.txt
===================================================================
--- code/stage/trunk/libstage/CMakeLists.txt 2008-06-01 02:05:23 UTC (rev
6461)
+++ code/stage/trunk/libstage/CMakeLists.txt 2008-06-03 17:18:26 UTC (rev
6462)
@@ -13,43 +13,42 @@
glcolorstack.cc
model.cc
model_blinkenlight.cc
+ model_blobfinder.cc
model_callbacks.cc
model_fiducial.cc
model_laser.cc
model_load.cc
model_position.cc
- model_ranger.cc
- model_blobfinder.cc
model_props.cc
+ model_ranger.cc
resource.cc
stage.cc
typetable.cc
world.cc
worldfile.cc
- worldgui.cc
+ worldgui.cc
)
-
target_link_libraries( stage
${GLIB_LIBRARIES}
- ${FLTK_LIBRARIES}
${OPENGL_LIBRARIES}
+ ${FLTK_LIBRARIES}
ltdl
)
-add_executable( stagebinary main.cc
-)
+add_executable( stagebinary main.cc )
set_target_properties( stagebinary PROPERTIES
OUTPUT_NAME stage )
target_link_libraries( stagebinary
- stage
+ stage
)
INSTALL(TARGETS stagebinary stage
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
)
+
INSTALL(FILES stage.hh
DESTINATION include/stage-3.0)
Modified: code/stage/trunk/libstage/block.cc
===================================================================
--- code/stage/trunk/libstage/block.cc 2008-06-01 02:05:23 UTC (rev 6461)
+++ code/stage/trunk/libstage/block.cc 2008-06-03 17:18:26 UTC (rev 6462)
@@ -26,7 +26,6 @@
this->pts = (stg_point_t*)g_memdup( pts, pt_count * sizeof(stg_point_t));
// allocate space for the integer version of the block vertices
this->pts_global_pixels = new stg_point_int_t[pt_count];
- this->global_vertices = new stg_vertex_t[2*pt_count+2];
this->zmin = zmin;
this->zmax = zmax;
@@ -38,18 +37,6 @@
// flag these as unset until StgBlock::Map() is called.
this->global_zmin = -1;
this->global_zmax = -1;
-
- this->edge_indices = new GLubyte[ 6 * pt_count ];
- for( int i=0; i<pt_count; i++ )
- {
- this->edge_indices[6*i] = 2*i;
- this->edge_indices[6*i+1] = 2*i+1;
- this->edge_indices[6*i+2] = 2*i;
- this->edge_indices[6*i+3] = 2*i+2;
- this->edge_indices[6*i+4] = 2*i+1;
- this->edge_indices[6*i+5] = 2*i+3;
- }
-
}
StgBlock::~StgBlock()
@@ -58,7 +45,7 @@
g_free( pts );
g_array_free( rendered_points, TRUE );
- delete[] edge_indices;
+ //delete[] edge_indices;
}
void Stg::stg_block_list_destroy( GList* list )
@@ -111,18 +98,18 @@
// draw filled color polygons
stg_color_t color = Color();
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
- PushColor( color );
- glEnable(GL_POLYGON_OFFSET_FILL);
- glPolygonOffset(1.0, 1.0);
- DrawSides();
- DrawTop();
- glDisable(GL_POLYGON_OFFSET_FILL);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
+ PushColor( color );
+ glEnable(GL_POLYGON_OFFSET_FILL);
+ glPolygonOffset(1.0, 1.0);
+ DrawSides();
+ DrawTop();
+ glDisable(GL_POLYGON_OFFSET_FILL);
- // draw the block outline in a darker version of the same color
- double r,g,b,a;
- stg_color_unpack( color, &r, &g, &b, &a );
- PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
+// // draw the block outline in a darker version of the same color
+ double r,g,b,a;
+ stg_color_unpack( color, &r, &g, &b, &a );
+ PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE );
glDepthMask(GL_FALSE);
@@ -134,74 +121,6 @@
PopColor();
}
-void StgBlock::DrawGlobal()
-{
- // draw filled color polygons
- stg_color_t color = Color();
-
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
- PushColor( color );
- glEnable(GL_POLYGON_OFFSET_FILL);
- glPolygonOffset(1.0, 1.0);
-
- // glColorPointer(3, GL_UNSIGNED_BYTE, 0, colors );
-
- // top - we skip every 2nd vertex
- glVertexPointer( 3, GL_FLOAT, 6*sizeof(GLfloat), global_vertices );
- glDrawArrays( GL_TRIANGLE_FAN, 0, pt_count );
-
- // sides - we use all vertices
- glVertexPointer( 3, GL_FLOAT, 0, global_vertices );
- glDrawArrays( GL_TRIANGLE_STRIP, 0, pt_count*2+2 );
-
- glDisable(GL_POLYGON_OFFSET_FILL);
-
- // draw the block outline in a darker version of the same color
- double r,g,b,a;
- stg_color_unpack( color, &r, &g, &b, &a );
- PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
-
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE );
- glDepthMask(GL_FALSE);
-
- // we use the array of vertices
- glDrawElements( GL_LINES, pt_count*6, GL_UNSIGNED_BYTE, edge_indices );
-
- glDepthMask(GL_TRUE);
-
- PopColor();
- PopColor();
-}
-
-void StgBlock::Draw2D()
-{
- // draw filled color polygons
- stg_color_t color = Color();
-
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
- PushColor( color );
- glEnable(GL_POLYGON_OFFSET_FILL);
- glPolygonOffset(1.0, 1.0);
- //DrawSides();
- DrawTop();
- glDisable(GL_POLYGON_OFFSET_FILL);
-
- // draw the block outline in a darker version of the same color
- double r,g,b,a;
- stg_color_unpack( color, &r, &g, &b, &a );
- PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
-
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE );
- glDepthMask(GL_FALSE);
- DrawTop();
- //DrawSides(); // skip this in 2d mode - faster!
- glDepthMask(GL_TRUE);
-
- PopColor();
- PopColor();
-}
-
-
void StgBlock::DrawSolid( void )
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
@@ -215,34 +134,21 @@
mod->Token(),
(int)pt_count );
- double ppm = mod->GetWorld()->ppm;
-
// update the global coordinate list
-
stg_point3_t global;
-
+ stg_point3_t local;
+
for( unsigned int p=0; p<pt_count; p++ )
{
- stg_point3_t local;
local.x = pts[p].x;
local.y = pts[p].y;
local.z = zmin;
global = mod->LocalToGlobal( local );
-
- // top surface vertex
- global_vertices[2*p].x = global.x;
- global_vertices[2*p].y = global.y;
- global_vertices[2*p].z = global.z + zmax;
- // bottom surface vertex
- global_vertices[2*p+1].x = global.x;
- global_vertices[2*p+1].y = global.y;
- global_vertices[2*p+1].z = global.z;
+ pts_global_pixels[p].x = mod->GetWorld()->MetersToPixels( global.x );
+ pts_global_pixels[p].y = mod->GetWorld()->MetersToPixels( global.y );
- pts_global_pixels[p].x = (int32_t)floor(global.x*ppm);
- pts_global_pixels[p].y = (int32_t)floor(global.y*ppm);
-
PRINT_DEBUG2("loc [%.2f %.2f]",
pts[p].x,
pts[p].y );
@@ -251,13 +157,7 @@
pts_global_pixels[p].x,
pts_global_pixels[p].y );
}
-
- // close the strip
- // top surface vertex
- global_vertices[2*pt_count] = global_vertices[0];
- global_vertices[2*pt_count+1] = global_vertices[1];
-
-
+
// store the block's global vertical bounds for inspection by the
// raytracer
global_zmin = global.z;
@@ -329,7 +229,7 @@
// examine all the points in the polygon
StgBlock* block = (StgBlock*)it->data;
- block->UnMap();
+ block->UnMap(); // just in case
for( unsigned int p=0; p < block->pt_count; p++ )
{
@@ -375,8 +275,6 @@
// todo - scale min properly
block->zmax *= scalez;
block->zmin *= scalez;
-
- //block->Map();
}
}
Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-06-01 02:05:23 UTC (rev 6461)
+++ code/stage/trunk/libstage/canvas.cc 2008-06-03 17:18:26 UTC (rev 6462)
@@ -6,6 +6,8 @@
#include "stage_internal.hh"
+using namespace Stg;
+
void StgCanvas::TimerCallback( StgCanvas* c )
{
c->redraw();
@@ -27,10 +29,10 @@
selected_models = NULL;
last_selection = NULL;
- startx = starty = 0;
+ startx = starty = 0;
panx = pany = stheta = sphi = 0.0;
scale = 15.0;
- interval = 100; //msec between redraws
+ interval = 50; //msec between redraws
graphics = true;
dragging = false;
@@ -288,6 +290,7 @@
redraw();
}
return 1;
+
case FL_FOCUS :
case FL_UNFOCUS :
//.... Return 1 if you want keyboard events, 0 otherwise
@@ -338,7 +341,8 @@
void StgCanvas::draw()
{
// static int centerx = 0, centery = 0;
-
+ //puts( "CANVAS" );
+
if (!valid())
{
valid(1);
@@ -393,13 +397,13 @@
// enable vertex arrays
glEnableClientState( GL_VERTEX_ARRAY );
//glEnableClientState( GL_COLOR_ARRAY );
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}
+ if( ! (showflags & STG_SHOW_TRAILS) )
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- // Clear screen to bg color
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
-
-
// if following selected, shift the view to above the selected robot
if( (showflags & STG_SHOW_FOLLOW) && last_selection )
{
@@ -472,7 +476,7 @@
glEnable( GL_DEPTH_TEST );
}
- if( showflags & STG_SHOW_TRAILS )
+ if( showflags & STG_SHOW_TRAILRISE )
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL );
@@ -494,12 +498,32 @@
if( showflags & STG_SHOW_BLOCKS )
{
for( GList* it=world->children; it; it=it->next )
- ((StgModel*)it->data)->DrawBlocks();
+ {
+ StgModel* mod = ((StgModel*)it->data);
+
+ if( mod->displaylist == 0 )
+ {
+ mod->displaylist = glGenLists(1);
+ mod->BuildDisplayList( showflags ); // ready to be rendered
+ }
+
+ // move into this model's local coordinate frame
+ glPushMatrix();
+ gl_pose_shift( &mod->pose );
+ gl_pose_shift( &mod->geom.pose );
+
+ // render the pre-recorded graphics for this model and
+ // its children
+ glCallList( mod->displaylist );
+
+ glPopMatrix();
+ }
}
+ //mod->Draw( showflags ); // draw the stuff that changes every update
// draw everything else
for( GList* it=world->children; it; it=it->next )
- ((StgModel*)it->data)->Draw( showflags );
+ ((StgModel*)it->data)->Draw( showflags );
}
if( world->GetRayList() )
@@ -526,6 +550,14 @@
glLoadIdentity();
glDisable( GL_DEPTH_TEST );
+ // if trails are on, we need to clear the clock background
+
+ glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+
+ colorstack.Push( 0.8,0.8,1.0 ); // pale blue
+ glRectf( -w()/2, -h()/2, -w()/2 +120, -h()/2+20 );
+ colorstack.Pop();
+
char clockstr[50];
world->ClockString( clockstr, 50 );
Modified: code/stage/trunk/libstage/gl.cc
===================================================================
--- code/stage/trunk/libstage/gl.cc 2008-06-01 02:05:23 UTC (rev 6461)
+++ code/stage/trunk/libstage/gl.cc 2008-06-03 17:18:26 UTC (rev 6462)
@@ -1,7 +1,6 @@
#include "stage_internal.hh"
-
// transform the current coordinate frame by the given pose
void Stg::gl_coord_shift( double x, double y, double z, double a )
{
@@ -16,15 +15,20 @@
}
// TODO - this could be faster, but we don't draw a lot of text
-void Stg::gl_draw_string( float x, float y, float z, char *str )
+void Stg::gl_draw_string( float x, float y, float z, const char *str )
{
- char *c;
+ const char *c;
glRasterPos3f(x, y,z);
for (c=str; *c != '\0'; c++)
glutBitmapCharacter( GLUT_BITMAP_HELVETICA_12, *c);
}
+void Stg::gl_speech_bubble( float x, float y, float z, const char* str )
+{
+ gl_draw_string( x, y, z, str );
+}
+
void Stg::gl_draw_grid( stg_bounds3d_t vol )
{
glBegin(GL_LINES);
Modified: code/stage/trunk/libstage/main.cc
===================================================================
--- code/stage/trunk/libstage/main.cc 2008-06-01 02:05:23 UTC (rev 6461)
+++ code/stage/trunk/libstage/main.cc 2008-06-03 17:18:26 UTC (rev 6462)
@@ -49,11 +49,10 @@
// initialize libstage
Stg::Init( &argc, &argv );
- StgWorld* world = usegui ? new StgWorldGui(800, 700, argv[0]) : new
StgWorld();
+ StgWorldGui world( 800, 700, argv[0]);
- world->Load( argv[argc-1] );
+ world.Load( argv[argc-1] );
- while( ! world->TestQuit() )
- world->RealTimeUpdate();
+ world.Run();
}
Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc 2008-06-01 02:05:23 UTC (rev 6461)
+++ code/stage/trunk/libstage/model.cc 2008-06-03 17:18:26 UTC (rev 6462)
@@ -44,6 +44,8 @@
)
@endverbatim
+TODO PLAN: single array of all polygon vertices - model just keeps an index
+
@par Details
- pose [x_pos:float y_pos:float heading:float]
- specify the pose of the model in its parent's coordinate system
@@ -169,6 +171,8 @@
world->AddModel( this );
bzero( &pose, sizeof(pose));
+ if( parent )
+ pose.z = parent->geom.size.z;
bzero( &global_pose, sizeof(global_pose));
this->trail = g_array_new( false, false, sizeof(stg_trail_item_t) );
@@ -184,6 +188,8 @@
this->subs = 0;
this->stall = false;
+ this->displaylist = 0;
+
this->geom.size.x = STG_DEFAULT_MOD_GEOM_SIZEX;
this->geom.size.y = STG_DEFAULT_MOD_GEOM_SIZEX;
this->geom.size.z = STG_DEFAULT_MOD_GEOM_SIZEX;
@@ -349,7 +355,6 @@
const void* arg,
stg_raytrace_sample_t* sample )
{
- //LocalToGlobal( &pose );
world->Raytrace( LocalToGlobal(pose),
range,
func,
@@ -379,7 +384,6 @@
stg_raytrace_sample_t* samples,
uint32_t sample_count )
{
- //LocalToGlobal( &pose );
world->Raytrace( LocalToGlobal(pose),
range,
fov,
@@ -441,7 +445,7 @@
// pose->x, pose->y, pose->a );
}
-void StgModel::Say( char* str )
+void StgModel::Say( const char* str )
{
if( say_string )
free( say_string );
@@ -614,19 +618,19 @@
{
//PRINT_DEBUG1( "%s.Map()", token );
- if( world->graphics && this->debug )
- {
- double scale = 1.0 / world->ppm;
- glPushMatrix();
- glTranslatef( 0,0,1 );
- glScalef( scale,scale,scale );
- }
+// if( world->graphics && this->debug )
+// {
+// double scale = 1.0 / world->ppm;
+// glPushMatrix();
+// glTranslatef( 0,0,1 );
+// glScalef( scale,scale,scale );
+// }
for( GList* it=blocks; it; it=it->next )
((StgBlock*)it->data)->Map();
- if( world->graphics && this->debug )
- glPopMatrix();
+// if( world->graphics && this->debug )
+// glPopMatrix();
}
void StgModel::UnMap()
@@ -814,7 +818,7 @@
glPushMatrix();
gl_pose_shift( &pose );
gl_pose_shift( &geom.pose );
- LISTMETHOD( this->blocks, StgBlock*, Draw );
+ glCallList( displaylist);
glPopMatrix();
}
}
@@ -827,8 +831,6 @@
double dx = 0.2;
double dy = 0.07;
- //double z;
-
double timescale = 0.0000001;
for( unsigned int i=0; i<trail->len; i++ )
@@ -880,18 +882,25 @@
void StgModel::DrawBlocks( )
{
- LISTMETHOD( this->children, StgModel*, DrawBlocks );
+ LISTMETHOD( this->blocks, StgBlock*, Draw );
+
+ // recursively draw the tree below this model
+ for( GList* it=children; it; it=it->next )
+ {
+ StgModel* child = ((StgModel*)it->data);
- LISTMETHOD( this->blocks, StgBlock*, DrawGlobal );
-}
+ glPushMatrix();
+ gl_pose_shift( &child->pose );
+ gl_pose_shift( &child->geom.pose );
+
+ child->DrawBlocks();
-void StgModel::DrawBlocks( gpointer dummykey,
- StgModel* mod, void* dummyarg )
-{
- mod->DrawBlocks();
+ glPopMatrix();
+ }
}
+
void StgModel::Draw( uint32_t flags )
{
//PRINT_DEBUG1( "Drawing %s", token );
@@ -902,9 +911,31 @@
gl_pose_shift( &this->pose );
gl_pose_shift( &this->geom.pose );
- //if( this->say_string )
- // gl_speech_bubble( 0,0,0, this->say_string );
-
+
+ if( this->say_string )
+ {
+ glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+
+ glPushMatrix();
+
+ PushColor( 0.8,0.8,1.0,1.0 ); // pale blue
+
+
+ glRotatef( -rtod(global_pose.a), 0,0,1 ); // out of the robot pose CS
+ // out of the world view CS
+ glRotatef( 90, 1,0,0 ); // out of the ground plane
+
+ glRectf( 0,0,1,1 );
+ PopColor();
+
+ PushColor( color );
+ gl_speech_bubble( 0.3,0.3,0, this->say_string );
+ PopColor();
+
+ glPopMatrix();
+ }
+
+
if( flags & STG_SHOW_DATA )
DataVisualize();
@@ -918,7 +949,7 @@
DrawBlinkenlights();
if( stall )
- gl_draw_string( 0,0,0.5, "!" );
+ gl_draw_string( 0,0,0.5, "X" );
// shift up the CS to the top of this model
gl_coord_shift( 0,0, this->geom.size.z, 0 );
@@ -986,7 +1017,7 @@
//stg_pose_t gpose = GetGlobalPose();
//glRotatef( 180 + rtod(-gpose.a),0,0,1 );
- glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+ //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
for( unsigned int i=0; i<blinkenlights->len; i++ )
{
@@ -1035,7 +1066,16 @@
glPopMatrix(); // drop out of local coords
}
+void StgModel::BuildDisplayList( int flags )
+{
+ glNewList( displaylist, GL_COMPILE );
+ //printf("Model %s blocks %d\n", token, g_list_length( blocks ) );
+ DrawBlocks();
+
+ glEndList();
+}
+
void StgModel::DataVisualize( void )
{
// do nothing - subclasses will do more here
@@ -1105,14 +1145,8 @@
pose.a = normalize( pose.a );
this->pose = pose;
-
- //memcpy( &this->pose, &pose, sizeof(stg_pose_t));
-
- //this->pose.a = normalize(this->pose.a);
+ this->pose.a = normalize(this->pose.a);
- //double hitx, hity;
- //stg_model_test_collision2( mod, &hitx, &hity );
-
this->NeedRedraw();
this->GPoseDirtyTree(); // global pose may have changed
Modified: code/stage/trunk/libstage/model_load.cc
===================================================================
--- code/stage/trunk/libstage/model_load.cc 2008-06-01 02:05:23 UTC (rev
6461)
+++ code/stage/trunk/libstage/model_load.cc 2008-06-03 17:18:26 UTC (rev
6462)
@@ -343,6 +343,9 @@
else
LoadControllerModule( lib );
}
+
+ if( wf->PropertyExists( this->id, "say" ))
+ this->Say( wf->ReadString(this->id, "say", NULL ));
// call any type-specific load callbacks
this->CallCallbacks( &this->load );
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2008-06-01 02:05:23 UTC (rev 6461)
+++ code/stage/trunk/libstage/stage.hh 2008-06-03 17:18:26 UTC (rev 6462)
@@ -518,6 +518,7 @@
const uint32_t STG_SHOW_ARROWS = (1<<9);
const uint32_t STG_SHOW_FOOTPRINT = (1<<10);
const uint32_t STG_SHOW_BLOCKS_2D = (1<<10);
+ const uint32_t STG_SHOW_TRAILRISE = (1<<11);
// forward declare
class StgWorld;
@@ -550,7 +551,8 @@
};
/** Render a string at [x,y,z] in the current color */
- void gl_draw_string( float x, float y, float z, char *string);
+ void gl_draw_string( float x, float y, float z, const char *string);
+ void gl_speech_bubble( float x, float y, float z, const char* str );
void stg_block_list_scale( GList* blocks,
@@ -926,9 +928,9 @@
friend class StgTime;
private:
-
+
static bool quit_all; // quit all worlds ASAP
- static unsigned int next_id; //< initialized to zero, used to
+ static unsigned int next_id; //< initialized to zero, used tob
//allocate unique sequential world ids
static int AddBlockPixel( int x, int y, int z,
stg_render_info_t* rinfo ) ; //< used as a
callback by StgModel
@@ -938,17 +940,13 @@
bool quit; // quit this world ASAP
-
- inline void MetersToPixels( stg_meters_t mx, stg_meters_t my,
- int32_t *px, int32_t *py );
-
+ // convert a distance in meters to a distance in world occupancy grid
pixels
+ int32_t MetersToPixels( stg_meters_t x ){ return (int32_t)floor(x * ppm) ;
};
+
void Initialize( const char* token,
stg_msec_t interval_sim,
stg_msec_t interval_real,
double ppm );
- // double width,
- // double height );
-
virtual void PushColor( stg_color_t col ) { /* do nothing */ };
virtual void PushColor( double r, double g, double b, double a ) { /* do
nothing */ };
@@ -974,7 +972,6 @@
bool dirty; ///< iff true, a gui redraw would be required
- stg_usec_t interval_sleep_max;
stg_usec_t interval_sim; ///< temporal resolution: milliseconds that
elapse between simulated time steps
stg_usec_t interval_log[INTERVAL_LOG_LEN];
@@ -989,8 +986,6 @@
void StartUpdatingModel( StgModel* mod );
void StopUpdatingModel( StgModel* mod );
-
- //void MapBlock( StgBlock* block );
SuperRegion* CreateSuperRegion( int32_t x, int32_t y );
void DestroySuperRegion( SuperRegion* sr );
@@ -1019,6 +1014,8 @@
GHashTable* superregions;
+ static void UpdateCb( StgWorld* world);
+
GList* ray_list;
// store rays traced for debugging purposes
void RecordRay( double x1, double y1, double x2, double y2 );
@@ -1061,9 +1058,6 @@
virtual void Reload();
virtual void Save();
virtual bool Update(void);
- virtual bool RealTimeUpdate(void);
- virtual bool RealTimeUpdateWithIdler( int (*idler)(void) );
-
virtual void AddModel( StgModel* mod );
virtual void RemoveModel( StgModel* mod );
@@ -1275,6 +1269,12 @@
GPtrArray* blinkenlights;
void DrawBlinkenlights();
+ /** OpenGL display list identifier */
+ int displaylist;
+
+ /** Compile the display list for this model */
+ void BuildDisplayList( int flags );
+
public:
// constructor
@@ -1283,7 +1283,7 @@
// destructor
virtual ~StgModel();
- void Say( char* str );
+ void Say( const char* str );
stg_id_t Id(){ return id; };
@@ -1295,7 +1295,7 @@
/** Should be called after all models are loaded, to do any last-minute
setup */
void Init();
-
+
void AddFlag( StgFlag* flag );
void RemoveFlag( StgFlag* flag );
@@ -1351,7 +1351,7 @@
StgModel* GetModel( const char* name );
bool Stall(){ return this->stall; }
int GuiMask(){ return this->gui_mask; };
- StgWorld* GetWorld(){ return this->world; }
+ inline StgWorld* GetWorld(){ return this->world; }
/// return the root model of the tree containing this model
StgModel* Root()
@@ -1601,7 +1601,7 @@
void DrawGlobal(); // draw the block in OpenGL using pts_global coords
void Draw(); // draw the block in OpenGL
- void Draw2D(); // draw the block in OpenGL
+ //void Draw2D(); // draw the block in OpenGL
void DrawSolid(); // draw the block in OpenGL as a solid single color
void DrawFootPrint(); // draw the projection of the block onto the z=0
plane
@@ -1631,9 +1631,7 @@
StgModel* mod; //< model to which this block belongs
stg_point_int_t* pts_global_pixels; //< points defining a polygon in
global coords
- stg_vertex_t* global_vertices; //< points defining a polygon in global
coords
- //GLubyte* colors;
- GLubyte* edge_indices;
+ //GLubyte* edge_indices;
stg_color_t color;
bool inherit_color;
@@ -1674,110 +1672,120 @@
GQueue* colorstack;
};
+// FLTK Gui includes
+#include <FL/Fl.H>
+//#include <FL/Fl_Box.H>
+//#include <FL/Fl_Double_Window.H>
+#include <FL/Fl_Gl_Window.H>
+#include <FL/Fl_Menu_Bar.H>
+#include <FL/Fl_Menu_Button.H>
+#include <FL/Fl_Value_Slider.H>
+#include <FL/Fl_Window.H>
+#include <FL/Fl_Box.H>
+#include <FL/fl_draw.H>
+#include <FL/gl.h> // FLTK takes care of platform-specific GL stuff
+#include <FL/glut.H>
-/** Implements a FLTK / OpenGL graphical user interfae.
-*/
- class StgCanvas : public Fl_Gl_Window
- {
- friend class StgWorldGui; // allow access to private members
-
- private:
- GlColorStack colorstack;
- double scale;
- double panx, pany, stheta, sphi;
- int startx, starty;
- bool dragging;
- bool rotating;
- GList* selected_models; ///< a list of models that are currently
- ///selected by the user
- StgModel* last_selection; ///< the most recently selected model
- ///(even if it is now unselected).
- uint32_t showflags;
- stg_msec_t interval; // window refresh interval in ms
-
- GList* ray_list;
- void RecordRay( double x1, double y1, double x2, double y2 );
- void DrawRays();
- void ClearRays();
- void DrawGlobalGrid();
-
- public:
- StgCanvas( StgWorld* world, int x, int y, int W,int H);
- ~StgCanvas();
+class StgCanvas : public Fl_Gl_Window
+{
+ friend class StgWorldGui; // allow access to private members
- bool graphics;
+private:
+ GlColorStack colorstack;
+ double scale;
+ double panx, pany, stheta, sphi;
+ int startx, starty;
+ bool dragging;
+ bool rotating;
+ GList* selected_models; ///< a list of models that are currently
+ ///selected by the user
+ StgModel* last_selection; ///< the most recently selected model
+ ///(even if it is now unselected).
+ uint32_t showflags;
+ stg_msec_t interval; // window refresh interval in ms
+
+ GList* ray_list;
+ void RecordRay( double x1, double y1, double x2, double y2 );
+ void DrawRays();
+ void ClearRays();
+ void DrawGlobalGrid();
+
+public:
+ StgCanvas( StgWorld* world, int x, int y, int W,int H);
+ ~StgCanvas();
+
+ bool graphics;
StgWorld* world;
-
- void FixViewport(int W,int H);
- virtual void draw();
- virtual int handle( int event );
- void resize(int X,int Y,int W,int H);
-
- void CanvasToWorld( int px, int py,
- double *wx, double *wy, double* wz );
-
- StgModel* Select( int x, int y );
- inline void PushColor( stg_color_t col )
- { colorstack.Push( col ); }
+ void FixViewport(int W,int H);
+ virtual void draw();
+ virtual int handle( int event );
+ void resize(int X,int Y,int W,int H);
- void PushColor( double r, double g, double b, double a )
- { colorstack.Push( r,g,b,a ); }
+ void CanvasToWorld( int px, int py,
+ double *wx, double *wy, double* wz );
- void PopColor(){ colorstack.Pop(); }
+ StgModel* Select( int x, int y );
- void InvertView( uint32_t invertflags );
+ inline void PushColor( stg_color_t col )
+ { colorstack.Push( col ); }
+
+ void PushColor( double r, double g, double b, double a )
+ { colorstack.Push( r,g,b,a ); }
+
+ void PopColor(){ colorstack.Pop(); }
+
+ void InvertView( uint32_t invertflags );
+
+ uint32_t GetShowFlags(){ return showflags; }
+
+ void SetShowFlags( uint32_t flags ){ showflags = flags; }
+
+ static void TimerCallback( StgCanvas* canvas );
+};
- uint32_t GetShowFlags(){ return showflags; }
- void SetShowFlags( uint32_t flags ){ showflags = flags; }
- static void TimerCallback( StgCanvas* canvas );
- };
- /** Extends StgWorld to present an OpenGL-based GUI to the user */
- class StgWorldGui : public StgWorld, public Fl_Window
- {
- friend class StgCanvas;
+/** Extends StgWorld to implements an FLTK / OpenGL graphical user
+ interface.
+*/
+class StgWorldGui : public StgWorld, public Fl_Window
+{
+ friend class StgCanvas;
- private:
- int wf_section;
- StgCanvas* canvas;
- Fl_Menu_Bar* mbar;
- //StgBlockGrid* GetBlockGrid(){ return bgridx; };
-
- public:
- StgWorldGui(int W,int H,const char*L=0);
- ~StgWorldGui();
-
- // overload inherited methods
- virtual bool RealTimeUpdate();
- virtual bool Update();
-
- virtual void Load( const char* filename );
- virtual void Save();
+private:
+ int wf_section;
+ StgCanvas* canvas;
+ Fl_Menu_Bar* mbar;
- // static callback functions
- static void SaveCallback( Fl_Widget* wid, StgWorldGui* world );
+public:
+ StgWorldGui(int W,int H,const char*L=0);
+ ~StgWorldGui();
- virtual void PushColor( stg_color_t col )
- { canvas->PushColor( col ); }
+ /** Start the simulation and GUI. Does not return */
+ void Run();
- virtual void PushColor( double r, double g, double b, double a )
- { canvas->PushColor( r,g,b,a ); }
+ virtual void Load( const char* filename );
+ virtual void Save();
- virtual void PopColor()
- { canvas->PopColor(); }
+ // static callback functions
+ static void SaveCallback( Fl_Widget* wid, StgWorldGui* world );
+
+ virtual void PushColor( stg_color_t col )
+ { canvas->PushColor( col ); }
+
+ virtual void PushColor( double r, double g, double b, double a )
+ { canvas->PushColor( r,g,b,a ); }
+
+ virtual void PopColor()
+ { canvas->PopColor(); }
+
+ void DrawTree( bool leaves );
+ void DrawFloor();
+};
- void DrawTree( bool leaves );
- void DrawFloor();
- };
-
-
- // end doc group libstage_utilities
-
-
// BLOBFINDER MODEL --------------------------------------------------------
/** blobfinder data packet
Modified: code/stage/trunk/libstage/stage_internal.hh
===================================================================
--- code/stage/trunk/libstage/stage_internal.hh 2008-06-01 02:05:23 UTC (rev
6461)
+++ code/stage/trunk/libstage/stage_internal.hh 2008-06-03 17:18:26 UTC (rev
6462)
@@ -1,4 +1,4 @@
-/** Stage internal header file - all libstage implementation *.cpp
+/** Stage internal header file - all libstage implementation *.cc
files include this header
Author: Richard Vaughan ([EMAIL PROTECTED])
Date: 13 Jan 2008
Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc 2008-06-01 02:05:23 UTC (rev 6461)
+++ code/stage/trunk/libstage/world.cc 2008-06-03 17:18:26 UTC (rev 6462)
@@ -386,9 +386,11 @@
}
+#define DEBUG 1
+
bool StgWorld::Update()
{
- //PRINT_DEBUG( "StgWorld::Update()" );
+ PRINT_DEBUG( "StgWorld::Update()" );
if( paused )
return false;
@@ -408,30 +410,16 @@
if( (quit_time > 0) && (sim_time >= quit_time) )
quit = true;
- //interval_log[updates%INTERVAL_LOG_LEN] = RealTimeSinceStart() -
real_time_now;
-
- return true;
-}
+ stg_usec_t timenow = RealTimeSinceStart();
-bool StgWorld::RealTimeUpdate()
-
-{
- //PRINT_DEBUG( "StageWorld::RealTimeUpdate()" );
- bool updated = Update();
- if( interval_real )
- PauseUntilNextUpdateTime();
+ interval_log[updates%INTERVAL_LOG_LEN] = timenow - real_time_now;
- return updated;
-}
+ //interval_log[updates%INTERVAL_LOG_LEN] = timenow - real_time_now;
-bool StgWorld::RealTimeUpdateWithIdler( int (*idler)(void) )
-
-{
- //PRINT_DEBUG( "StageWorld::RealTimeUpdate()" );
- bool updated = Update();
- IdleUntilNextUpdateTime( idler );
-
- return updated;
+ real_time_now = timenow;
+ //real_time_next_update += interval_real;
+
+ return true;
}
void StgWorld::AddModel( StgModel* mod )
@@ -696,12 +684,10 @@
this->update_list = g_list_remove( this->update_list, mod );
}
-void StgWorld::MetersToPixels( stg_meters_t mx, stg_meters_t my,
- int32_t *px, int32_t *py )
-{
- *px = (int32_t)floor(mx* ppm);
- *py = (int32_t)floor(my* ppm);
-}
+// int32_t StgWorld::MetersToPixels( stg_meters_t m )
+// {
+// return (int32_t)floor(m * ppm);
+// }
int StgWorld::AddBlockPixel( int x, int y, int z,
stg_render_info_t* rinfo )
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2008-06-01 02:05:23 UTC (rev
6461)
+++ code/stage/trunk/libstage/worldgui.cc 2008-06-03 17:18:26 UTC (rev
6462)
@@ -95,7 +95,6 @@
*/
-//#include "config.h" // for PACKAGE strings etc
#include "stage_internal.hh"
#include "region.hh"
@@ -113,10 +112,11 @@
static const char* MITEM_VIEW_FOLLOW = "View/Follow";
static const char* MITEM_VIEW_CLOCK = "View/Clock";
static const char* MITEM_VIEW_FOOTPRINTS = "View/Trails/Footprints";
-static const char* MITEM_VIEW_TRAILS = "View/Trails/Blocks";
-static const char* MITEM_VIEW_ARROWS = "View/Trails/Arrows";
+static const char* MITEM_VIEW_BLOCKSRISING = "View/Trails/Blocks rising";
+static const char* MITEM_VIEW_ARROWS = "View/Trails/Arrows rising";
+static const char* MITEM_VIEW_TRAILS = "View/Trail";
-// hack - get this from somewhere sensible
+// hack - get this from somewhere sensible, like CMake's config file
const char* PACKAGE_STRING = "Stage-3.dev";
void dummy_cb(Fl_Widget*, void* v)
@@ -147,12 +147,6 @@
Fl::run();
}
-
-void StgWorldGui::SaveCallback( Fl_Widget* wid, StgWorldGui* world )
-{
- world->Save();
-}
-
void view_toggle_cb(Fl_Menu_Bar* menubar, StgCanvas* canvas )
{
char picked[128];
@@ -171,13 +165,14 @@
else if( strcmp(picked, MITEM_VIEW_FOOTPRINTS ) == 0 ) canvas->InvertView(
STG_SHOW_FOOTPRINT );
else if( strcmp(picked, MITEM_VIEW_ARROWS ) == 0 ) canvas->InvertView(
STG_SHOW_ARROWS );
else if( strcmp(picked, MITEM_VIEW_TRAILS ) == 0 ) canvas->InvertView(
STG_SHOW_TRAILS );
+ else if( strcmp(picked, MITEM_VIEW_BLOCKSRISING ) == 0 ) canvas->InvertView(
STG_SHOW_TRAILRISE );
else PRINT_ERR1( "Unrecognized menu item \"%s\" not handled", picked );
//printf( "value: %d\n", item->value() );
}
-StgWorldGui::StgWorldGui(int W,int H,const char*L)
+StgWorldGui::StgWorldGui(int W,int H,const char* L)
: Fl_Window(0,0,W,H,L)
{
//size_range( 100,100 ); // set minimum window size
@@ -213,15 +208,18 @@
mbar->add( MITEM_VIEW_CLOCK, 'c', (Fl_Callback*)view_toggle_cb,
(void*)canvas,
FL_MENU_TOGGLE| (canvas->showflags & STG_SHOW_CLOCK ?
FL_MENU_VALUE : 0 ));
+ mbar->add( MITEM_VIEW_TRAILS, 't', (Fl_Callback*)view_toggle_cb,
(void*)canvas,
+ FL_MENU_TOGGLE| (canvas->showflags & STG_SHOW_TRAILS ?
FL_MENU_VALUE : 0 ));
+
mbar->add( MITEM_VIEW_FOOTPRINTS, FL_CTRL+'f',
(Fl_Callback*)view_toggle_cb, (void*)canvas,
FL_MENU_TOGGLE| (canvas->showflags & STG_SHOW_FOOTPRINT ?
FL_MENU_VALUE : 0 ));
mbar->add( MITEM_VIEW_ARROWS, FL_CTRL+'a', (Fl_Callback*)view_toggle_cb,
(void*)canvas,
FL_MENU_TOGGLE| (canvas->showflags & STG_SHOW_ARROWS ?
FL_MENU_VALUE : 0 ));
- mbar->add( MITEM_VIEW_TRAILS, FL_CTRL+'t', (Fl_Callback*)view_toggle_cb,
(void*)canvas,
- FL_MENU_TOGGLE| (canvas->showflags & STG_SHOW_TRAILS ?
FL_MENU_VALUE : 0 ));
-
+ mbar->add( MITEM_VIEW_BLOCKSRISING, FL_CTRL+'t',
(Fl_Callback*)view_toggle_cb, (void*)canvas,
+ FL_MENU_TOGGLE| (canvas->showflags & STG_SHOW_TRAILRISE ?
FL_MENU_VALUE : 0 ));
+
mbar->add( "Help", 0, 0, 0, FL_SUBMENU );
- mbar->add( "Help/About Stage...", FL_CTRL + 'f', (Fl_Callback *)About_cb );
+ mbar->add( "Help/About Stage...", NULL, (Fl_Callback *)About_cb );
//mbar->add( "Help/HTML Documentation", FL_CTRL + 'g', (Fl_Callback
*)dummy_cb );
show();
}
@@ -262,11 +260,12 @@
uint32_t quadtree = wf->ReadInt(wf_section, "show_tree", flags &
STG_SHOW_QUADTREE ) ? STG_SHOW_QUADTREE : 0;
uint32_t clock = wf->ReadInt(wf_section, "show_clock", flags &
STG_SHOW_CLOCK ) ? STG_SHOW_CLOCK : 0;
uint32_t trails = wf->ReadInt(wf_section, "show_trails", flags &
STG_SHOW_TRAILS ) ? STG_SHOW_TRAILS : 0;
+ uint32_t trailsrising = wf->ReadInt(wf_section, "show_trails_rising", flags
& STG_SHOW_TRAILRISE ) ? STG_SHOW_TRAILRISE : 0;
uint32_t arrows = wf->ReadInt(wf_section, "show_arrows", flags &
STG_SHOW_ARROWS ) ? STG_SHOW_ARROWS : 0;
uint32_t footprints = wf->ReadInt(wf_section, "show_footprints", flags &
STG_SHOW_FOOTPRINT ) ? STG_SHOW_FOOTPRINT : 0;
canvas->SetShowFlags( grid | data | follow | blocks | quadtree | clock
- | trails | arrows | footprints );
+ | trails | arrows | footprints | trailsrising );
canvas->invalidate(); // we probably changed something
// fix the GUI menu checkboxes to match
@@ -295,6 +294,11 @@
// TODO - per model visualizations load
}
+ void StgWorldGui::SaveCallback( Fl_Widget* wid, StgWorldGui* world )
+ {
+ world->Save();
+ }
+
void StgWorldGui::Save( void )
{
PRINT_DEBUG1( "%s.Save()", token );
@@ -324,21 +328,34 @@
StgWorld::Save();
}
-bool StgWorldGui::RealTimeUpdate()
+void StgWorld::UpdateCb( StgWorld* world )
{
- if( interval_real )
- return StgWorld::RealTimeUpdateWithIdler( Fl::check);
- else
- return Update();
+ world->Update();
+
+ // need to reinstantiatethe timeout each time
+ Fl::repeat_timeout( world->interval_real/1e6,
+ (Fl_Timeout_Handler)UpdateCb, world );
}
-bool StgWorldGui::Update()
+static void idle_callback( StgWorld* world )
{
- bool updated = StgWorld::Update();
- Fl::check(); // may redraw the window
- return updated;
+ world->Update();
}
+void StgWorldGui::Run()
+{
+
+ // if a non-zero interval was requested, call Update() after that
+ // interval
+ if( interval_real > 0 )
+ Fl::add_timeout( interval_real/1e6, (Fl_Timeout_Handler)UpdateCb, this );
+ else // otherwise call Update() whenever there's no GUI work to do
+ Fl::add_idle( (Fl_Timeout_Handler)idle_callback, this );
+
+ Fl::run();
+}
+
+
void StgWorldGui::DrawTree( bool drawall )
{
g_hash_table_foreach( superregions, (GHFunc)SuperRegion::Draw_cb, NULL );
Modified: code/stage/trunk/todo
===================================================================
--- code/stage/trunk/todo 2008-06-01 02:05:23 UTC (rev 6461)
+++ code/stage/trunk/todo 2008-06-03 17:18:26 UTC (rev 6462)
@@ -1,12 +1,17 @@
-- TODO --
+ESSENTIAL
- 3d ray tracing
- GUI rotations
- docs
+ - finish CMake scripts
+ - clean up graphics implementation
+
+NICE
- gripper
+ - pucks
- power
- energy
- - pucks
-- DONE --
@@ -15,8 +20,8 @@
multiple interfaces. See note in stg_driver.cc
-- Large Scale Robotics paper
- - 0.01M robots
- - two or three benchmark controllers
+ - 0.1M robots
+ - two or three benchmark controllers (ended up as 1)
- experimental design
- sensible defaults - laser (all devices)
Modified: code/stage/trunk/worlds/fasr.world
===================================================================
--- code/stage/trunk/worlds/fasr.world 2008-06-01 02:05:23 UTC (rev 6461)
+++ code/stage/trunk/worlds/fasr.world 2008-06-03 17:18:26 UTC (rev 6462)
@@ -26,16 +26,17 @@
rotate [ 0.000 0.000 ]
scale 33.306
show_data 0
+ interval 50
)
# load an environment bitmap
-floorplan
-(
- name "cave"
- size3 [16 16 0.5]
- pose [0.000 0.000 0.000]
- bitmap "bitmaps/cave.png"
-)
+#floorplan
+#(
+# name "cave"
+# size3 [16 16 0.5]
+# pose [0.000 0.000 0.000]
+# bitmap "bitmaps/cave.png"
+#)
zone
(
@@ -56,29 +57,29 @@
define autorob pioneer2dx
(
color "red"
- sicklaser(pose [ 0.040 0.000 0.000 ] samples 32 range_max 5 laser_return 2 )
+ sicklaser( pose [ 0.040 0.000 0.000 ] samples 32 range_max 5 laser_return 2 )
ctrl "fasr"
)
-autorob( pose [4.461 6.406 1.930] )
+autorob( pose [4.461 6.406 1.930] say "Booga" )
autorob( pose [6.635 6.458 -52.629] )
autorob( pose [6.385 5.805 -87.082] )
autorob( pose [7.004 5.327 170.536] )
autorob( pose [5.770 6.492 -10.539] )
autorob( pose [7.493 4.852 -156.719] )
autorob( pose [5.078 6.853 -37.549] )
-autorob( pose [6.147 7.399 4.964] )
-autorob( pose [4.065 5.583 125.796] )
-autorob( pose [7.487 6.926 -40.634] )
+#autorob( pose [6.147 7.399 4.964] )
+#autorob( pose [4.065 5.583 125.796] )
+#autorob( pose [7.487 6.926 -40.634] )
-autorob( pose [4.530 7.367 -113.456] )
-autorob( pose [6.071 5.138 -1.177] )
-autorob( pose [6.591 4.622 -68.007] )
-autorob( pose [5.454 7.540 135.162] )
-autorob( pose [4.707 5.855 -3.588] )
-autorob( pose [6.714 7.447 -73.332] )
-autorob( pose [5.582 5.724 -48.161] )
-autorob( pose [3.958 6.851 -102.651] )
-autorob( pose [5.127 5.109 23.582] )
-autorob( pose [7.534 5.825 -70.230] )
+#autorob( pose [4.530 7.367 -113.456] )
+#autorob( pose [6.071 5.138 -1.177] )
+#autorob( pose [6.591 4.622 -68.007] )
+#autorob( pose [5.454 7.540 135.162] )
+#autorob( pose [4.707 5.855 -3.588] )
+#autorob( pose [6.714 7.447 -73.332] )
+#autorob( pose [5.582 5.724 -48.161] )
+#autorob( pose [3.958 6.851 -102.651] )
+#autorob( pose [5.127 5.109 23.582] )
+#autorob( pose [7.534 5.825 -70.230] )
Modified: code/stage/trunk/worlds/pioneer.inc
===================================================================
--- code/stage/trunk/worlds/pioneer.inc 2008-06-01 02:05:23 UTC (rev 6461)
+++ code/stage/trunk/worlds/pioneer.inc 2008-06-03 17:18:26 UTC (rev 6462)
@@ -36,7 +36,6 @@
ssize [0.01 0.05]
)
-
define pioneer2dx position
(
# actual size
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit