Revision: 8237
http://playerstage.svn.sourceforge.net/playerstage/?rev=8237&view=rev
Author: rtv
Date: 2009-08-27 19:46:25 +0000 (Thu, 27 Aug 2009)
Log Message:
-----------
GUI clean ups
Modified Paths:
--------------
code/stage/trunk/libstage/canvas.cc
code/stage/trunk/libstage/canvas.hh
code/stage/trunk/libstage/region.cc
code/stage/trunk/libstage/region.hh
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/worldgui.cc
Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2009-08-26 23:43:56 UTC (rev 8236)
+++ code/stage/trunk/libstage/canvas.cc 2009-08-27 19:46:25 UTC (rev 8237)
@@ -52,8 +52,8 @@
}
Canvas::Canvas( WorldGui* world,
- int x, int y,
- int width, int height) :
+ int x, int y,
+ int width, int height) :
Fl_Gl_Window( x, y, width, height ),
colorstack(),
models_sorted(),
@@ -69,7 +69,9 @@
interval( 20 ), // msec between redraws
// initialize Option objects
// showBlinken( "Blinkenlights", "show_blinkenlights", "", true, world ),
+ showBBoxes( "Debug/Bounding boxes", "show_boundingboxes", "^b", false, world
),
showBlocks( "Blocks", "show_blocks", "b", true, world ),
+ showBlur( "Trails/Blur", "show_trailblur", "^d", false, world ),
showClock( "Clock", "show_clock", "c", true, world ),
showData( "Data", "show_data", "d", false, world ),
showFlags( "Flags", "show_flags", "l", true, world ),
@@ -82,11 +84,9 @@
showTrailArrows( "Trails/Rising Arrows", "show_trailarrows", "^a", false,
world ),
showTrailRise( "Trails/Rising blocks", "show_trailrise", "^r", false, world
),
showTrails( "Trails/Fast", "show_trailfast", "^f", false, world ),
- showTree( "Debug/Tree", "show_tree", "^t", false, world ),
- showBBoxes( "Debug/Bounding boxes", "show_boundingboxes", "^b", false, world
),
- showBlur( "Trails/Blur", "show_trailblur", "^d", false, world ),
+ showVoxels( "Debug/Voxels", "show_voxels", "^v", false, world ),
pCamOn( "Perspective camera", "pcam_on", "r", false, world ),
- visualizeAll( "Selected only", "vis_all", "^v", false, world ),
+ visualizeAll( "Selected only", "vis_all", "v", false, world ),
// and the rest
graphics( true ),
world( world ),
@@ -151,27 +151,27 @@
GLuint mains_id = TextureManager::getInstance().loadTexture(
fullpath.c_str() );
TextureManager::getInstance()._mains_texture_id = mains_id;
-// // generate a small glow texture
-// GLubyte* pixels = new GLubyte[ 4 * 128 * 128 ];
+ // // generate a small glow texture
+ // GLubyte* pixels = new GLubyte[ 4 * 128 * 128 ];
-// for( int x=0; x<128; x++ )
-// for( int y=0; y<128; y++ )
-// {
-// GLubyte* p = &pixels[ 4 * (128*y + x)];
-// p[0] = (GLubyte)255; // red
-// p[1] = (GLubyte)0; // green
-// p[2] = (GLubyte)0; // blue
-// p[3] = (GLubyte)128; // alpha
-// }
+ // for( int x=0; x<128; x++ )
+ // for( int y=0; y<128; y++ )
+ // {
+ // GLubyte* p = &pixels[ 4 * (128*y + x)];
+ // p[0] = (GLubyte)255; // red
+ // p[1] = (GLubyte)0; // green
+ // p[2] = (GLubyte)0; // blue
+ // p[3] = (GLubyte)128; // alpha
+ // }
-// glGenTextures(1, &glowTex );
-// glBindTexture( GL_TEXTURE_2D, glowTex );
+ // glGenTextures(1, &glowTex );
+ // glBindTexture( GL_TEXTURE_2D, glowTex );
-// glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0,
-// GL_RGBA, GL_UNSIGNED_BYTE, pixels );
+ // glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0,
+ // GL_RGBA, GL_UNSIGNED_BYTE, pixels );
-// delete[] pixels;
+ // delete[] pixels;
// draw a check into a bitmap, then load that into a texture
int i, j;
@@ -229,19 +229,19 @@
Model* mod = (*it);
if( mod->gui.move )
- {
- uint8_t rByte, gByte, bByte, aByte;
- uint32_t modelId = mod->id;
- rByte = modelId;
- gByte = modelId >> 8;
- bByte = modelId >> 16;
- aByte = modelId >> 24;
+ {
+ uint8_t rByte, gByte, bByte, aByte;
+ uint32_t modelId = mod->id;
+ rByte = modelId;
+ gByte = modelId >> 8;
+ bByte = modelId >> 16;
+ aByte = modelId >> 24;
- //printf("mod->Id(): 0x%X, rByte: 0x%X, gByte: 0x%X, bByte: 0x%X,
aByte: 0x%X\n", modelId, rByte, gByte, bByte, aByte);
+ //printf("mod->Id(): 0x%X, rByte: 0x%X, gByte: 0x%X,
bByte: 0x%X, aByte: 0x%X\n", modelId, rByte, gByte, bByte, aByte);
- glColor4ub( rByte, gByte, bByte, aByte );
- mod->DrawPicker();
- }
+ glColor4ub( rByte, gByte, bByte, aByte );
+ mod->DrawPicker();
+ }
}
// read the color of the pixel in the back buffer under the mouse
@@ -253,13 +253,13 @@
uint32_t modelId;
glReadPixels( x,viewport[3]-y,1,1,
- GL_RED,GL_UNSIGNED_BYTE,(void*)&rByte );
+ GL_RED,GL_UNSIGNED_BYTE,(void*)&rByte
);
glReadPixels( x,viewport[3]-y,1,1,
- GL_GREEN,GL_UNSIGNED_BYTE,(void*)&gByte );
+
GL_GREEN,GL_UNSIGNED_BYTE,(void*)&gByte );
glReadPixels( x,viewport[3]-y,1,1,
- GL_BLUE,GL_UNSIGNED_BYTE,(void*)&bByte );
+ GL_BLUE,GL_UNSIGNED_BYTE,(void*)&bByte
);
glReadPixels( x,viewport[3]-y,1,1,
- GL_ALPHA,GL_UNSIGNED_BYTE,(void*)&aByte );
+
GL_ALPHA,GL_UNSIGNED_BYTE,(void*)&aByte );
modelId = rByte;
modelId |= gByte << 8;
@@ -316,7 +316,7 @@
// convert from 2d window pixel to 3d world coordinates
void Canvas::CanvasToWorld( int px, int py,
- double *wx, double *wy, double* wz )
+ double
*wx, double *wy, double* wz )
{
if( px <= 0 )
px = 1;
@@ -359,10 +359,10 @@
{
case FL_MOUSEWHEEL:
if( pCamOn == true ) {
- perspective_camera.scroll( Fl::event_dy() / 10.0 );
+ perspective_camera.scroll( Fl::event_dy() / 10.0 );
}
else {
- camera.scale( Fl::event_dy(), Fl::event_x(), w(), Fl::event_y(), h() );
+ camera.scale( Fl::event_dy(), Fl::event_x(), w(),
Fl::event_y(), h() );
}
invalidate();
redraw();
@@ -370,154 +370,156 @@
case FL_MOVE: // moused moved while no button was pressed
if( Fl::event_state( FL_META ) )
- {
- puts( "TODO: HANDLE HISTORY" );
- //world->paused = ! world->paused;
- return 1;
- }
+ {
+ puts( "TODO: HANDLE HISTORY" );
+ //world->paused = ! world->paused;
+ return 1;
+ }
if ( startx >=0 )
- {
- // mouse pointing to valid value
+ {
+ // mouse pointing to valid value
- if( Fl::event_state( FL_CTRL ) )
- {
- int dx = Fl::event_x() - startx;
- int dy = Fl::event_y() - starty;
+ if( Fl::event_state( FL_CTRL ) )
+ {
+ int dx = Fl::event_x() - startx;
+ int dy = Fl::event_y() - starty;
- if( pCamOn == true ) {
- perspective_camera.addYaw( -dx );
- perspective_camera.addPitch( -dy );
- }
- else {
- camera.addPitch( - 0.5 * static_cast<double>( dy ) );
- camera.addYaw( - 0.5 * static_cast<double>( dx ) );
- }
- invalidate();
- redraw();
- }
- else if( Fl::event_state( FL_ALT ) )
- {
- int dx = Fl::event_x() - startx;
- int dy = Fl::event_y() - starty;
+ if( pCamOn == true ) {
+ perspective_camera.addYaw( -dx );
+ perspective_camera.addPitch( -dy );
+ }
+ else {
+ camera.addPitch( - 0.5 *
static_cast<double>( dy ) );
+ camera.addYaw( - 0.5 *
static_cast<double>( dx ) );
+ }
+ invalidate();
+ redraw();
+ }
+ else if( Fl::event_state( FL_ALT ) )
+ {
+ int dx = Fl::event_x() - startx;
+ int dy = Fl::event_y() - starty;
- if( pCamOn == true ) {
- perspective_camera.move( -dx, dy, 0.0 );
- }
- else {
- camera.move( -dx, dy );
- }
- invalidate();
- }
- }
+ if( pCamOn == true ) {
+ perspective_camera.move( -dx, dy, 0.0
);
+ }
+ else {
+ camera.move( -dx, dy );
+ }
+ invalidate();
+ }
+ }
startx = Fl::event_x();
starty = Fl::event_y();
return 1;
case FL_PUSH: // button pressed
{
- //else
- {
- Model* mod = getModel( startx, starty );
- startx = Fl::event_x();
- starty = Fl::event_y();
- selectedModel = false;
- switch( Fl::event_button() )
- {
- case 1:
- clicked_empty_space = ( mod == NULL );
- empty_space_startx = startx;
- empty_space_starty = starty;
- if( mod ) {
- // clicked a model
- if ( Fl::event_state( FL_SHIFT ) ) {
- // holding shift, toggle selection
- if ( selected( mod ) )
- unSelect( mod );
- else {
- select( mod );
- selectedModel = true; // selected a model
+ //else
+ {
+ Model* mod = getModel( startx, starty );
+ startx = Fl::event_x();
+ starty = Fl::event_y();
+ selectedModel = false;
+ switch( Fl::event_button() )
+ {
+ case 1:
+ clicked_empty_space = ( mod == NULL );
+ empty_space_startx = startx;
+ empty_space_starty = starty;
+ if( mod ) {
+ // clicked a model
+ if ( Fl::event_state( FL_SHIFT ) ) {
+ // holding shift, toggle
selection
+ if ( selected( mod ) )
+ unSelect( mod );
+ else {
+ select( mod );
+ selectedModel = true; //
selected a model
+ }
+ }
+ else {
+ if ( !selected( mod ) ) {
+ // clicked on an unselected
model while
+ // not holding shift, this
is the new
+ // selection
+ unSelectAll();
+ select( mod );
+ }
+ selectedModel = true; //
selected a model
+ }
+ }
+
+ redraw(); // probably required
+ return 1;
+ case 3:
+ {
+ // leave selections alone
+ // rotating handled within FL_DRAG
+ return 1;
+ }
+ default:
+ return 0;
+ }
}
- }
- else {
- if ( !selected( mod ) ) {
- // clicked on an unselected model while
- // not holding shift, this is the new
- // selection
- unSelectAll();
- select( mod );
- }
- selectedModel = true; // selected a model
- }
- }
-
- return 1;
- case 3:
- {
- // leave selections alone
- // rotating handled within FL_DRAG
- 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;
+ int dx = Fl::event_x() - startx;
+ int dy = Fl::event_y() - starty;
- if ( Fl::event_state( FL_BUTTON1 ) && Fl::event_state( FL_CTRL ) ==
false ) {
- // Left mouse button drag
- if ( selectedModel ) {
- // started dragging on a selected model
+ if ( Fl::event_state( FL_BUTTON1 ) && Fl::event_state(
FL_CTRL ) == false ) {
+ // Left mouse button drag
+ if ( selectedModel ) {
+ // started dragging on a selected model
- 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_EACH( it, selected_models )
- {
- Model* mod = *it;
- mod->AddToPose( x-sx, y-sy, 0, 0 );
- }
- }
- else {
- // started dragging on empty space or an
- // unselected model, move the canvas
- if( pCamOn == true ) {
- perspective_camera.move( -dx, dy, 0.0 );
- }
- else {
- camera.move( -dx, dy );
- }
- invalidate(); // so the projection gets updated
- }
- }
- else if ( Fl::event_state( FL_BUTTON3 ) || ( Fl::event_state(
FL_BUTTON1 ) && Fl::event_state( FL_CTRL ) ) ) {
- // rotate all selected models
- FOR_EACH( it, selected_models )
- {
- Model* mod = *it;
- mod->AddToPose( 0,0,0, 0.05*(dx+dy) );
- }
- }
+ 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_EACH( it, selected_models )
+ {
+ Model* mod = *it;
+ mod->AddToPose( x-sx, y-sy, 0, 0 );
+ }
+ }
+ else {
+ // started dragging on empty space or an
+ // unselected model, move the canvas
+ if( pCamOn == true ) {
+ perspective_camera.move( -dx, dy, 0.0 );
+ }
+ else {
+ camera.move( -dx, dy );
+ }
+ invalidate(); // so the projection gets updated
+ }
+ }
+ else if ( Fl::event_state( FL_BUTTON3 ) || ( Fl::event_state(
FL_BUTTON1 ) && Fl::event_state( FL_CTRL ) ) ) {
+ // rotate all selected models
+ FOR_EACH( it, selected_models )
+ {
+ Model* mod = *it;
+ mod->AddToPose( 0,0,0, 0.05*(dx+dy) );
+ }
+ }
- startx = Fl::event_x();
- starty = Fl::event_y();
+ startx = Fl::event_x();
+ starty = Fl::event_y();
- redraw();
- return 1;
+ redraw();
+ return 1;
} // end case FL_DRAG
case FL_RELEASE: // mouse button released
if( empty_space_startx == Fl::event_x() && empty_space_starty ==
Fl::event_y() && clicked_empty_space == true ) {
- // clicked on empty space, unselect all
- unSelectAll();
+ // clicked on empty space, unselect all
+ unSelectAll();
+ redraw();
}
return 1;
@@ -528,23 +530,23 @@
case FL_KEYBOARD:
switch( Fl::event_key() )
- {
- case FL_Left:
- if( pCamOn == false ) { camera.move( -10, 0 ); }
- else { perspective_camera.strafe( -0.5 ); } break;
- case FL_Right:
- if( pCamOn == false ) {camera.move( 10, 0 ); }
- else { perspective_camera.strafe( 0.5 ); } break;
- case FL_Down:
- if( pCamOn == false ) {camera.move( 0, -10 ); }
- else { perspective_camera.forward( -0.5 ); } break;
- case FL_Up:
- if( pCamOn == false ) {camera.move( 0, 10 ); }
- else { perspective_camera.forward( 0.5 ); } break;
- default:
- redraw(); // we probably set a display config - so need this
- return 0; // keypress unhandled
- }
+ {
+ case FL_Left:
+ if( pCamOn == false ) { camera.move( -10, 0 ); }
+ else { perspective_camera.strafe( -0.5 ); } break;
+ case FL_Right:
+ if( pCamOn == false ) {camera.move( 10, 0 ); }
+ else { perspective_camera.strafe( 0.5 ); } break;
+ case FL_Down:
+ if( pCamOn == false ) {camera.move( 0, -10 ); }
+ else { perspective_camera.forward( -0.5 ); } break;
+ case FL_Up:
+ if( pCamOn == false ) {camera.move( 0, 10 ); }
+ else { perspective_camera.forward( 0.5 ); } break;
+ default:
+ redraw(); // we probably set a display config - so
need this
+ return 0; // keypress unhandled
+ }
invalidate(); // update projection
return 1;
@@ -681,14 +683,6 @@
{
FOR_EACH( it, models_sorted )
(*it)->DrawBlocksTree();
-
- // some models may be carried by others - this prevents them being drawn
twice
- // for( GList* it = models_sorted; it; it=it->next )
- // {
- // Model* mod = (Model*)it->data;
- // if( mod->parent == NULL )
- // mod->DrawBlocksTree();
- // }
}
void Canvas::DrawBoundingBoxes()
@@ -751,10 +745,10 @@
Pose b_pose = b->GetGlobalPose();
stg_meters_t a_dist = hypot( y - a_pose.y,
- x - a_pose.x );
+
x - a_pose.x );
stg_meters_t b_dist = hypot( y - b_pose.y,
- x - b_pose.x );
+
x - b_pose.x );
return ( a_dist < b_dist );
}
@@ -790,23 +784,13 @@
if( ! showTrails )
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- if( showTree || showOccupancy )
- {
- glPushMatrix();
-
- GLfloat scale = 1.0/world->Resolution();
- glScalef( scale, scale, 1.0 ); // XX TODO - this seems slightly
- // out for Z. look into it.
-
- if( showOccupancy )
- ((WorldGui*)world)->DrawTree( false );
-
- if( showTree )
- ((WorldGui*)world)->DrawTree( true );
-
- glPopMatrix();
- }
+ if( showOccupancy )
+ ((WorldGui*)world)->DrawOccupancy();
+ if( showVoxels )
+ ((WorldGui*)world)->DrawVoxels();
+
+
if( ! world->rt_cells.empty() )
{
glPushMatrix();
@@ -821,24 +805,24 @@
glBegin( GL_POINTS );
for( unsigned int i=0;
- i < world->rt_cells.size();
- i++ )
- {
- char str[128];
- snprintf( str, 128, "(%d,%d)",
- world->rt_cells[i].x,
- world->rt_cells[i].y );
+ i < world->rt_cells.size();
+ i++ )
+ {
+ char str[128];
+ snprintf( str, 128, "(%d,%d)",
+ world->rt_cells[i].x,
+ world->rt_cells[i].y );
- Gl::draw_string( world->rt_cells[i].x+1,
- world->rt_cells[i].y+1, 0.1, str );
+ Gl::draw_string( world->rt_cells[i].x+1,
+
world->rt_cells[i].y+1, 0.1, str );
- //printf( "x: %d y: %d\n", world->rt_regions[i].x,
world->rt_regions[i].y );
- //glRectf( world->rt_cells[i].x+0.3, world->rt_cells[i].y+0.3,
- // world->rt_cells[i].x+0.7, world->rt_cells[i].y+0.7 );
+ //printf( "x: %d y: %d\n", world->rt_regions[i].x,
world->rt_regions[i].y );
+ //glRectf( world->rt_cells[i].x+0.3,
world->rt_cells[i].y+0.3,
+ // world->rt_cells[i].x+0.7,
world->rt_cells[i].y+0.7 );
- glVertex2f( world->rt_cells[i].x, world->rt_cells[i].y );
+ glVertex2f( world->rt_cells[i].x, world->rt_cells[i].y
);
- }
+ }
glEnd();
@@ -846,11 +830,11 @@
world->PushColor( Color( 0,1,0,0.2) );
glBegin( GL_LINE_STRIP );
for( unsigned int i=0;
- i < world->rt_cells.size();
- i++ )
- {
- glVertex2f( world->rt_cells[i].x+0.5, world->rt_cells[i].y+0.5 );
- }
+ i < world->rt_cells.size();
+ i++ )
+ {
+ glVertex2f( world->rt_cells[i].x+0.5,
world->rt_cells[i].y+0.5 );
+ }
glEnd();
world->PopColor();
#endif
@@ -870,30 +854,30 @@
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
for( unsigned int i=0;
- i < world->rt_candidate_cells.size();
- i++ )
- {
- // char str[128];
- // snprintf( str, 128, "(%d,%d)",
- //
world->rt_candidate_cells[i].x,
- //
world->rt_candidate_cells[i].y );
+ i < world->rt_candidate_cells.size();
+ i++ )
+ {
+ // char str[128];
+ // snprintf( str, 128, "(%d,%d)",
+ //
world->rt_candidate_cells[i].x,
+ //
world->rt_candidate_cells[i].y );
- // Gl::draw_string(
world->rt_candidate_cells[i].x+1,
- //
world->rt_candidate_cells[i].y+1, 0.1, str );
+ // Gl::draw_string(
world->rt_candidate_cells[i].x+1,
+ //
world->rt_candidate_cells[i].y+1, 0.1, str );
- //printf( "x: %d y: %d\n", world->rt_regions[i].x,
world->rt_regions[i].y );
- glRectf( world->rt_candidate_cells[i].x,
world->rt_candidate_cells[i].y,
- world->rt_candidate_cells[i].x+1,
world->rt_candidate_cells[i].y+1 );
- }
+ //printf( "x: %d y: %d\n", world->rt_regions[i].x,
world->rt_regions[i].y );
+ glRectf( world->rt_candidate_cells[i].x,
world->rt_candidate_cells[i].y,
+
world->rt_candidate_cells[i].x+1, world->rt_candidate_cells[i].y+1 );
+ }
world->PushColor( Color( 0,1,0,0.2) );
glBegin( GL_LINE_STRIP );
for( unsigned int i=0;
- i < world->rt_candidate_cells.size();
- i++ )
- {
- glVertex2f( world->rt_candidate_cells[i].x+0.5,
world->rt_candidate_cells[i].y+0.5 );
- }
+ i < world->rt_candidate_cells.size();
+ i++ )
+ {
+ glVertex2f( world->rt_candidate_cells[i].x+0.5,
world->rt_candidate_cells[i].y+0.5 );
+ }
glEnd();
world->PopColor();
@@ -903,8 +887,6 @@
//world->rt_cells.clear();
}
-
-
if( showGrid )
DrawGlobalGrid();
else
@@ -915,7 +897,7 @@
glDisable( GL_DEPTH_TEST ); // using alpha blending
FOR_EACH( it, models_sorted )
- (*it)->DrawTrailFootprint();
+ (*it)->DrawTrailFootprint();
glEnable( GL_DEPTH_TEST );
}
@@ -952,11 +934,11 @@
if( showData ) {
if ( ! visualizeAll ) {
FOR_EACH( it, world->World::children )
- (*it)->DataVisualizeTree( current_camera );
+ (*it)->DataVisualizeTree( current_camera );
}
else if ( selected_models.size() > 0 ) {
FOR_EACH( it, world->World::children )
- (*it)->DataVisualizeTree( current_camera );
+ (*it)->DataVisualizeTree( current_camera );
}
else if ( last_selection ) {
last_selection->DataVisualizeTree( current_camera );
@@ -972,10 +954,10 @@
glPushMatrix();
//ensure two icons can't be in the exact same plane
if( camera.pitch() == 0 && !pCamOn )
- glTranslatef( 0, 0, 0.1 );
+ glTranslatef( 0, 0, 0.1 );
FOR_EACH( it, models_sorted )
- (*it)->DrawStatusTree( &camera );
+ (*it)->DrawStatusTree( &camera );
glPopMatrix();
}
@@ -985,13 +967,13 @@
glDisable( GL_DEPTH_TEST );
PushColor( 0,0,0,0.5 );
FOR_EACH( it, world->ray_list )
- {
- float* pts = *it;
- glBegin( GL_LINES );
- glVertex2f( pts[0], pts[1] );
- glVertex2f( pts[2], pts[3] );
- glEnd();
- }
+ {
+ float* pts = *it;
+ glBegin( GL_LINES );
+ glVertex2f( pts[0], pts[1] );
+ glVertex2f( pts[2], pts[3] );
+ glEnd();
+ }
PopColor();
glEnable( GL_DEPTH_TEST );
@@ -1015,7 +997,7 @@
std::string clockstr = world->ClockString();
if( showFollow == true && last_selection )
- clockstr.append( " [FOLLOW MODE]" );
+ clockstr.append( " [FOLLOW MODE]" );
float txtWidth = gl_width( clockstr.c_str());
if( txtWidth < 200 ) txtWidth = 200;
@@ -1036,16 +1018,16 @@
// ENERGY BOX
if( PowerPack::global_capacity > 0 )
- {
- colorstack.Push( 0.8,1.0,0.8,0.85 ); // pale green
- glRectf( 0, height, width, 90 );
- colorstack.Push( 0,0,0 ); // black
- Gl::draw_string_multiline( margin, height + margin, width, 50,
- world->EnergyString().c_str(),
- (Fl_Align)( FL_ALIGN_LEFT |
FL_ALIGN_BOTTOM) );
- colorstack.Pop();
- colorstack.Pop();
- }
+ {
+ colorstack.Push( 0.8,1.0,0.8,0.85 ); // pale green
+ glRectf( 0, height, width, 90 );
+ colorstack.Push( 0,0,0 ); // black
+ Gl::draw_string_multiline( margin, height + margin,
width, 50,
+
world->EnergyString().c_str(),
+
(Fl_Align)( FL_ALIGN_LEFT | FL_ALIGN_BOTTOM) );
+ colorstack.Pop();
+ colorstack.Pop();
+ }
glEnable( GL_DEPTH_TEST );
glPopMatrix();
@@ -1133,11 +1115,11 @@
png_set_rows( pp, info, rowpointers );
png_set_IHDR( pp, info,
- width, height, 8,
- PNG_COLOR_TYPE_RGBA,
- PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_DEFAULT,
- PNG_FILTER_TYPE_DEFAULT);
+ width, height, 8,
+ PNG_COLOR_TYPE_RGBA,
+ PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
png_write_png( pp, info, PNG_TRANSFORM_IDENTITY, NULL );
@@ -1183,7 +1165,7 @@
showTrails.createMenuItem( menu, path );
showTrailRise.createMenuItem( menu, path ); // broken
showBBoxes.createMenuItem( menu, path );
- showTree.createMenuItem( menu, path );
+ showVoxels.createMenuItem( menu, path );
showScreenshots.createMenuItem( menu, path );
}
@@ -1213,15 +1195,15 @@
showTrailArrows.Load( wf, sec );
showTrailRise.Load( wf, sec );
showTrails.Load( wf, sec );
- showTree.Load( wf, sec );
+ showVoxels.Load( wf, sec );
showScreenshots.Load( wf, sec );
pCamOn.Load( wf, sec );
if( ! world->paused )
// // start the timer that causes regular redraws
Fl::add_timeout( ((double)interval/1000),
- (Fl_Timeout_Handler)Canvas::TimerCallback,
- this);
+
(Fl_Timeout_Handler)Canvas::TimerCallback,
+ this);
invalidate(); // we probably changed something
}
@@ -1246,7 +1228,7 @@
showTrailArrows.Save( wf, sec );
showTrailRise.Save( wf, sec );
showTrails.Save( wf, sec );
- showTree.Save( wf, sec );
+ showVoxels.Save( wf, sec );
showScreenshots.Save( wf, sec );
pCamOn.Save( wf, sec );
}
@@ -1254,31 +1236,27 @@
void Canvas::draw()
{
- // static unsigned long calls=0;
- // printf( "Draw calls %lu\n", ++calls );
-
-
//Enable the following to debug camera model
// if( loaded_texture == true && pCamOn == true )
// return;
-
+
if (!valid() )
{
if( ! init_done )
- InitGl();
+ InitGl();
if( pCamOn == true )
- {
- perspective_camera.setAspect( static_cast< float >( w() ) /
static_cast< float >( h() ) );
- perspective_camera.SetProjection();
- current_camera = &perspective_camera;
- }
+ {
+ perspective_camera.setAspect( static_cast< float >(
w() ) / static_cast< float >( h() ) );
+ perspective_camera.SetProjection();
+ current_camera = &perspective_camera;
+ }
else
- {
- stg_bounds3d_t extent = world->GetExtent();
- camera.SetProjection( w(), h(), extent.y.min, extent.y.max );
- current_camera = &camera;
- }
+ {
+ stg_bounds3d_t extent = world->GetExtent();
+ camera.SetProjection( w(), h(), extent.y.min,
extent.y.max );
+ current_camera = &camera;
+ }
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}
@@ -1288,14 +1266,14 @@
{
Pose gpose = last_selection->GetGlobalPose();
if( pCamOn == true )
- {
- perspective_camera.setPose( gpose.x, gpose.y, 0.2 );
- perspective_camera.setYaw( rtod( gpose.a ) - 90.0 );
- }
+ {
+ perspective_camera.setPose( gpose.x, gpose.y, 0.2 );
+ perspective_camera.setYaw( rtod( gpose.a ) - 90.0 );
+ }
else
- {
- camera.setPose( gpose.x, gpose.y );
- }
+ {
+ camera.setPose( gpose.x, gpose.y );
+ }
}
current_camera->Draw();
Modified: code/stage/trunk/libstage/canvas.hh
===================================================================
--- code/stage/trunk/libstage/canvas.hh 2009-08-26 23:43:56 UTC (rev 8236)
+++ code/stage/trunk/libstage/canvas.hh 2009-08-27 19:46:25 UTC (rev 8237)
@@ -78,7 +78,9 @@
void RemoveModel( Model* mod );
Option //showBlinken,
+ showBBoxes,
showBlocks,
+ showBlur,
showClock,
showData,
showFlags,
@@ -91,9 +93,7 @@
showTrailArrows,
showTrailRise,
showTrails,
- showTree,
- showBBoxes,
- showBlur,
+ showVoxels,
pCamOn,
visualizeAll;
Modified: code/stage/trunk/libstage/region.cc
===================================================================
--- code/stage/trunk/libstage/region.cc 2009-08-26 23:43:56 UTC (rev 8236)
+++ code/stage/trunk/libstage/region.cc 2009-08-27 19:46:25 UTC (rev 8237)
@@ -7,10 +7,6 @@
#include "region.hh"
using namespace Stg;
-// static member for accumulating empty regions for occasional garbage
-// collection
-// std::set<Region*> Region::empty_regions;
-
Region::Region( SuperRegion* sr) :
cells(),
superregion(sr),
@@ -29,25 +25,21 @@
count(0)
{
// populate the regions
- regions.insert( regions.begin(), SUPERREGIONSIZE, Region( this ) );
-
- //static int srcount=0;
- //printf( "created SR number %d\n", ++srcount );
- // printf( "superregion at %d %d\n", origin.x, origin.y );
+ regions.insert( regions.begin(), SUPERREGIONSIZE, Region( this ) );
}
SuperRegion::~SuperRegion()
{
- //printf( "deleting SR %p at [%d,%d]\n", this, origin.x, origin.y );
}
-void SuperRegion::Draw( bool drawall )
+void SuperRegion::DrawOccupancy()
{
- glEnable( GL_DEPTH_TEST );
-
- glPushMatrix();
+ glPushMatrix();
+ GLfloat scale = 1.0/world->Resolution();
+ glScalef( scale, scale, 1.0 ); // XX TODO - this seems slightly
glTranslatef( origin.x<<SRBITS, origin.y<<SRBITS,0);
-
+
+ glEnable( GL_DEPTH_TEST );
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
// outline superregion
@@ -62,27 +54,27 @@
for( int y=0; y<SUPERREGIONWIDTH; y++ )
for( int x=0; x<SUPERREGIONWIDTH; x++ )
{
- if( r->count )
+ if( r->count ) // region contains some occupied cells
{
- // outline regions with contents
+ // outline the region
glRecti( x<<RBITS, y<<RBITS,
(x+1)<<RBITS,
(y+1)<<RBITS );
-
+
+ // show how many cells are occupied
snprintf( buf, 15, "%lu", r->count );
Gl::draw_string( x<<RBITS, y<<RBITS, 0, buf );
+ // draw a rectangle around each occupied cell
for( int p=0; p<REGIONWIDTH; p++ )
for( int q=0; q<REGIONWIDTH; q++ )
if(
r->cells[p+(q*REGIONWIDTH)].blocks.size() )
{
GLfloat xx = p+(x<<RBITS);
- GLfloat yy = q+(y<<RBITS);
-
- glRecti( xx, yy,
- xx+1,
yy+1);
+ GLfloat yy = q+(y<<RBITS);
+ glRecti( xx, yy, xx+1, yy+1);
}
}
- else if( ! r->cells.empty() )
+ else if( ! r->cells.empty() ) // empty but used previously
{
double left = x << RBITS;
double right = (x+1) << RBITS;
@@ -90,7 +82,7 @@
double top = (y+1) << RBITS;
double d = 3.0;
-
+
// draw little corner markers for regions with
memory
// allocated but no contents
glBegin( GL_LINES );
@@ -122,144 +114,92 @@
glPopMatrix();
}
-// TODO
-#if 0
-void SuperRegion::Draw( bool drawall )
+
+static void DrawBlock( GLfloat x, GLfloat y, GLfloat zmin, GLfloat zmax )
{
- glEnable( GL_DEPTH_TEST );
+ glBegin( GL_QUADS );
+
+ // TOP
+ glVertex3f( x, y, zmax );
+ glVertex3f( 1+x, y, zmax );
+ glVertex3f( 1+x, 1+y, zmax );
+ glVertex3f( x, 1+y, zmax );
+
+ // sides
+ glVertex3f( x, y, zmax );
+ glVertex3f( x, 1+y, zmax );
+ glVertex3f( x, 1+y, zmin );
+ glVertex3f( x, y, zmin );
+
+ glVertex3f( 1+x, y, zmax );
+ glVertex3f( x, y, zmax );
+ glVertex3f( x, y, zmin );
+ glVertex3f( 1+x, y, zmin );
+
+ glVertex3f( 1+x, 1+y, zmax );
+ glVertex3f( 1+x, y, zmax );
+ glVertex3f( 1+x, y, zmin );
+ glVertex3f( 1+x, 1+y, zmin );
+
+ glVertex3f( x, 1+y, zmax );
+ glVertex3f( 1+x, 1+y, zmax );
+ glVertex3f( 1+x, 1+y, zmin );
+ glVertex3f( x, 1+y, zmin );
- glPushMatrix();
+ glEnd();
+}
+
+void SuperRegion::DrawVoxels()
+{
+ glPushMatrix();
+ GLfloat scale = 1.0/world->Resolution();
+ glScalef( scale, scale, 1.0 ); // XX TODO - this seems slightly
glTranslatef( origin.x<<SRBITS, origin.y<<SRBITS,0);
+
+ glEnable( GL_DEPTH_TEST );
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
- r = GetRegion( 0, 0);
-
+ Region* r = GetRegion( 0, 0);
+
for( int y=0; y<SUPERREGIONWIDTH; y++ )
for( int x=0; x<SUPERREGIONWIDTH; x++ )
{
- if( r->count < 1 )
- {
- r++;
- continue;
- }
-
- snprintf( buf, 15, "%lu", r->count );
- Gl::draw_string( x<<RBITS, y<<RBITS, 0, buf );
-
- for( int p=0; p<REGIONWIDTH; p++ )
- for( int q=0; q<REGIONWIDTH; q++ )
- if( r->cells[p+(q*REGIONWIDTH)].blocks.size() )
- {
- GLfloat xx = p+(x<<RBITS);
- GLfloat yy = q+(y<<RBITS);
+ if( r->count )
+ for( int p=0; p<REGIONWIDTH; p++ )
+ for( int q=0; q<REGIONWIDTH; q++ )
+ {
+ Cell* c =
(Cell*)&r->cells[p+(q*REGIONWIDTH)];
- if( ! drawall ) // draw a rectangle on
the floor
- {
- glRecti( xx, yy,
- xx+1,
yy+1);
- }
- else // draw a rectangular solid
- {
- Cell* c =
(Cell*)&r->cells[p+(q*REGIONWIDTH)];
-
+ if( c->blocks.size() )
+ {
+ GLfloat xx = p+(x<<RBITS);
+ GLfloat yy = q+(y<<RBITS);
+
FOR_EACH( it, c->blocks )
{
Block* block =
*it;
-
- //printf( "zb
%.2f %.2f\n", ent->zbounds.min, ent->zbounds.max );
-
+ // first draw
filled polygons
Color c =
block->GetColor();
glColor4f( c.r,
c.g, c.b, 1.0 );
-
+
glPolygonMode(
GL_FRONT_AND_BACK, GL_FILL );
glEnable(GL_POLYGON_OFFSET_FILL);
// TODO - these
numbers need tweaking for
//
better-looking rendering
-
glPolygonOffset(0.01, 0.1);
-
- //
// TOP
- glBegin(
GL_POLYGON );
- glVertex3f( xx,
yy, block->global_z.max );
- glVertex3f(
1+xx, yy, block->global_z.max );
- glVertex3f(
1+xx, 1+yy, block->global_z.max );
- glVertex3f( xx,
1+yy, block->global_z.max );
- glEnd();
-
- // sides
- glBegin(
GL_QUADS );
- glVertex3f( xx,
yy, block->global_z.max );
- glVertex3f( xx,
1+yy, block->global_z.max );
- glVertex3f( xx,
1+yy, block->global_z.min );
- glVertex3f( xx,
yy, block->global_z.min );
-
- glVertex3f(
1+xx, yy, block->global_z.max );
- glVertex3f( xx,
yy, block->global_z.max );
- glVertex3f( xx,
yy, block->global_z.min );
- glVertex3f(
1+xx, yy, block->global_z.min );
-
- glVertex3f(
1+xx, 1+yy, block->global_z.max );
- glVertex3f(
1+xx, yy, block->global_z.max );
- glVertex3f(
1+xx, yy, block->global_z.min );
- glVertex3f(
1+xx, 1+yy, block->global_z.min );
-
- glVertex3f( xx,
1+yy, block->global_z.max );
- glVertex3f(
1+xx, 1+yy, block->global_z.max );
- glVertex3f(
1+xx, 1+yy, block->global_z.min );
- glVertex3f( xx,
1+yy, block->global_z.min );
- glEnd();
-
-
glDisable(GL_POLYGON_OFFSET_FILL);
-
+
glPolygonOffset(0.01, 0.1);
+ DrawBlock( xx,
yy, block->global_z.min, block->global_z.max );
+
+ // draw again
in outline
+
glDisable(GL_POLYGON_OFFSET_FILL);
glColor4f(
c.r/2.0, c.g/2.0, c.b/2.0, c.a );
- glPolygonMode(
GL_FRONT_AND_BACK, GL_LINE );
-
- // TOP
- glBegin(
GL_POLYGON );
- glVertex3f( xx,
yy, block->global_z.max );
- glVertex3f(
1+xx, yy, block->global_z.max );
- glVertex3f(
1+xx, 1+yy, block->global_z.max );
- glVertex3f( xx,
1+yy, block->global_z.max );
- glEnd();
-
- // sides
- glBegin(
GL_QUADS );
- glVertex3f( xx,
yy, block->global_z.max );
- glVertex3f( xx,
1+yy, block->global_z.max );
- glVertex3f( xx,
1+yy, block->global_z.min );
- glVertex3f( xx,
yy, block->global_z.min );
-
- glVertex3f(
1+xx, yy, block->global_z.max );
- glVertex3f( xx,
yy, block->global_z.max );
- glVertex3f( xx,
yy, block->global_z.min );
- glVertex3f(
1+xx, yy, block->global_z.min );
-
- glVertex3f(
1+xx, 1+yy, block->global_z.max );
- glVertex3f(
1+xx, yy, block->global_z.max );
- glVertex3f(
1+xx, yy, block->global_z.min );
- glVertex3f(
1+xx, 1+yy, block->global_z.min );
-
- glVertex3f( xx,
1+yy, block->global_z.max );
- glVertex3f(
1+xx, 1+yy, block->global_z.max );
- glVertex3f(
1+xx, 1+yy, block->global_z.min );
- glVertex3f( xx,
1+yy, block->global_z.min );
- glEnd();
- }
- }
- }
-
+ glPolygonMode(
GL_FRONT_AND_BACK, GL_LINE );
+ DrawBlock( xx,
yy, block->global_z.min, block->global_z.max );
+ }
+ }
+ }
+
++r;
}
- glPopMatrix();
-}
-#endif
-
-//inline
-void SuperRegion::Floor()
-{
- glPushMatrix();
- glTranslatef( origin.x<<SRBITS, origin.y<<SRBITS, 0 );
- glRecti( 0,0, 1<<SRBITS, 1<<SRBITS );
glPopMatrix();
}
-
Modified: code/stage/trunk/libstage/region.hh
===================================================================
--- code/stage/trunk/libstage/region.hh 2009-08-26 23:43:56 UTC (rev 8236)
+++ code/stage/trunk/libstage/region.hh 2009-08-27 19:46:25 UTC (rev 8237)
@@ -94,8 +94,8 @@
Region* GetRegion( int32_t x, int32_t y )
{ return( ®ions[ x + y * SUPERREGIONWIDTH ] ); }
- void Draw( bool drawall );
- void Floor();
+ void DrawOccupancy();
+ void DrawVoxels();
unsigned long count; // number of blocks rendered into this superregion
}; // class SuperRegion;
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2009-08-26 23:43:56 UTC (rev 8236)
+++ code/stage/trunk/libstage/stage.hh 2009-08-27 19:46:25 UTC (rev 8237)
@@ -1462,9 +1462,9 @@
virtual void PushColor( double r, double g, double b, double a );
virtual void PopColor();
- void DrawTree( bool leaves );
- void DrawFloor();
-
+ void DrawOccupancy();
+ void DrawVoxels();
+
public:
WorldGui(int W,int H,const char*L=0);
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2009-08-26 23:43:56 UTC (rev
8236)
+++ code/stage/trunk/libstage/worldgui.cc 2009-08-27 19:46:25 UTC (rev
8237)
@@ -417,20 +417,16 @@
return std::string( str );
}
-void WorldGui::DrawTree( bool drawall )
+void WorldGui::DrawOccupancy()
{
FOR_EACH( it, superregions )
- (*it).second->Draw( drawall );
+ (*it).second->DrawOccupancy();
}
-void WorldGui::DrawFloor()
-{
- PushColor( 1,1,1,1 );
-
+void WorldGui::DrawVoxels()
+{
FOR_EACH( it, superregions )
- (*it).second->Floor();
-
- PopColor();
+ (*it).second->DrawVoxels();
}
void WorldGui::windowCb( Fl_Widget* w, WorldGui* wg )
@@ -523,7 +519,13 @@
void WorldGui::slowerCb( Fl_Widget* w, WorldGui* wg )
{
- wg->speedup *= 0.8;
+ if( wg->speedup <= 0 )
+ {
+ wg->speedup = 100.0;
+ wg->SetTimeouts();
+ }
+ else
+ wg->speedup *= 0.8;
}
void WorldGui::fasterCb( Fl_Widget* w, WorldGui* wg )
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit