Skip to content

Commit

Permalink
fixed color bug in flags, and more STLing
Browse files Browse the repository at this point in the history
  • Loading branch information
rtv committed Jul 16, 2009
1 parent 6e109cd commit 2c36066
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 69 deletions.
2 changes: 1 addition & 1 deletion examples/ctrl/source.cc
Expand Up @@ -18,7 +18,7 @@ extern "C" int Init( Model* mod )
int Update( Model* mod, void* dummy )
{
if( mod->GetWorld()->GetUpdateCount() % INTERVAL == 0 )
mod->PushFlag( new Flag( Color( 1,1,0,0), FLAGSZ ) );
mod->PushFlag( new Flag( Color( 1,1,0 ), FLAGSZ ) );

return 0; // run again
}
Expand Down
17 changes: 9 additions & 8 deletions libstage/model.cc
Expand Up @@ -201,8 +201,8 @@ Model::Model( World* world,
color( 1,0,0 ), // red
data_fresh(false),
disabled(false),
custom_visual_list( NULL ),
flag_list(NULL),
custom_visual_list( NULL ),
flag_list(),
geom(),
has_default_block( true ),
id( Model::count++ ),
Expand Down Expand Up @@ -335,7 +335,7 @@ void Model::AddFlag( Flag* flag )
{
if( flag )
{
flag_list = g_list_append( this->flag_list, flag );
flag_list.push_back( flag );
CallCallbacks( &hooks.flag_incr );
}
}
Expand All @@ -344,7 +344,8 @@ void Model::RemoveFlag( Flag* flag )
{
if( flag )
{
flag_list = g_list_remove( this->flag_list, flag );
flag_list.erase( remove( flag_list.begin(), flag_list.end(), flag ));

CallCallbacks( &hooks.flag_decr );
}
}
Expand All @@ -353,18 +354,18 @@ void Model::PushFlag( Flag* flag )
{
if( flag )
{
flag_list = g_list_prepend( flag_list, flag);
flag_list.push_front( flag);
CallCallbacks( &hooks.flag_incr );
}
}

Flag* Model::PopFlag()
{
if( flag_list == NULL )
if( flag_list.size() == 0 )
return NULL;

Flag* flag = (Flag*)flag_list->data;
flag_list = g_list_remove( flag_list, flag );
Flag* flag = flag_list.front();
flag_list.pop_front();

CallCallbacks( &hooks.flag_decr );

Expand Down
47 changes: 12 additions & 35 deletions libstage/model_draw.cc
Expand Up @@ -438,7 +438,7 @@ void Model::DrawImage( uint32_t texture_id, Camera* cam, float alpha, double wid

void Model::DrawFlagList( void )
{
if( flag_list == NULL )
if( flag_list.size() < 1 )
return;

PushLocalCoords();
Expand All @@ -450,43 +450,20 @@ void Model::DrawFlagList( void )
Pose gpose = GetGlobalPose();
glRotatef( 180 + rtod(-gpose.a),0,0,1 );


GList* list = g_list_copy( flag_list );
list = g_list_reverse(list);

for( GList* item = list; item; item = item->next )
{

Flag* flag = (Flag*)item->data;

glTranslatef( 0, 0, flag->size/2.0 );

PushColor( flag->color );

for( std::list<Flag*>::reverse_iterator it( flag_list.rbegin());
it != flag_list.rend();
it++ )
{
Flag* flag = *it;

glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0, 1.0);
gluQuadricDrawStyle( quadric, GLU_FILL );
gluSphere( quadric, flag->size/2.0, 4,2 );
glDisable(GL_POLYGON_OFFSET_FILL);

// draw the edges darker version of the same color
Color c = flag->color;
c.r /= 2.0;
c.g /= 2.0;
c.b /= 2.0;
PushColor( c );

gluQuadricDrawStyle( quadric, GLU_LINE );
gluSphere( quadric, flag->size/2.0, 4,2 );

PopColor();
PopColor();
glTranslatef( 0, 0, flag->size/2.0 );

flag->Draw( quadric );

glTranslatef( 0, 0, flag->size/2.0 );
}

g_list_free( list );

gluDeleteQuadric( quadric );

Expand Down Expand Up @@ -514,10 +491,10 @@ void Model::DrawBlinkenlights()
PushColor( b->color );

if( b->enabled )
gluQuadricDrawStyle( quadric, GLU_FILL );
gluQuadricDrawStyle( quadric, GLU_FILL );
else
gluQuadricDrawStyle( quadric, GLU_LINE );

gluQuadricDrawStyle( quadric, GLU_LINE );
gluSphere( quadric, b->size/2.0, 8,8 );

PopColor();
Expand Down
18 changes: 18 additions & 0 deletions libstage/resource.cc
Expand Up @@ -20,3 +20,21 @@ Flag* Flag::Nibble( double chunk )

return piece;
}


void Flag::Draw( GLUquadric* quadric )
{
glColor4f( color.r, color.g, color.b, color.a );

glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.0, 1.0);
gluQuadricDrawStyle( quadric, GLU_FILL );
gluSphere( quadric, size/2.0, 4,2 );
glDisable(GL_POLYGON_OFFSET_FILL);

// draw the edges darker version of the same color
glColor4f( color.r/2.0, color.g/2.0, color.b/2.0, color.a/2.0 );

gluQuadricDrawStyle( quadric, GLU_LINE );
gluSphere( quadric, size/2.0, 4,2 );
}
20 changes: 14 additions & 6 deletions libstage/stage.hh
Expand Up @@ -559,6 +559,10 @@ namespace Stg

Flag( Color color, double size );
Flag* Nibble( double portion );

/** Draw the flag in OpenGl. Takes a quadric parameter to save
creating the quadric for each flag */
void Draw( GLUquadric* quadric );
};

/** Abstract class for adding visualizations to models. DataVisualize must be overloaded, and is then called in the models local coord system */
Expand Down Expand Up @@ -896,10 +900,11 @@ namespace Stg
unsigned int steps; ///< When paused, stage updates while steps >
///0, decrementing steps with each update.

void Start(){ paused = false; };
void Stop(){ paused = true; };
void TogglePause(){ paused = !paused; };
bool Paused(){ return( paused ); };
virtual void Start(){ paused = false; };
virtual void Stop(){ paused = true; };
virtual void TogglePause(){ paused ? Start() : Stop(); };

bool Paused(){ return( paused ); };

PointIntVec rt_cells;
PointIntVec rt_candidate_cells;
Expand Down Expand Up @@ -1471,6 +1476,9 @@ namespace Stg
virtual bool IsGUI() { return true; }
virtual Model* RecentlySelectedModel();

virtual void Start();
virtual void Stop();

void DrawBoundingBoxTree();

Canvas* GetCanvas( void ) { return canvas; }
Expand Down Expand Up @@ -1713,7 +1721,7 @@ namespace Stg
bool data_fresh;
stg_bool_t disabled; ///< if non-zero, the model is disabled
GList* custom_visual_list;
GList* flag_list;
std::list<Flag*> flag_list;
Geom geom;
Pose global_pose;
bool gpose_dirty; ///< set this to indicate that global pose may have changed
Expand Down Expand Up @@ -2040,7 +2048,7 @@ namespace Stg
void PushFlag( Flag* flag );
Flag* PopFlag();

int GetFlagCount() const { return g_list_length( flag_list ); }
int GetFlagCount() const { return flag_list.size(); }

/** Add a pointer to a blinkenlight to the model. */
void AddBlinkenlight( stg_blinkenlight_t* b )
Expand Down
46 changes: 27 additions & 19 deletions libstage/worldgui.cc
Expand Up @@ -334,14 +334,16 @@ bool WorldGui::Update()
TogglePause();
pause_time = true;
}

bool val = World::Update();

// if we're paused and counting down, we need to redraw the window
// because it's not drawn on a timer when paused.
if( steps )
canvas->redraw(); // in case something happened that will never be

bool need_redraw = paused && (steps > 0);

bool val = World::Update();

if( need_redraw )
canvas->redraw();

stg_usec_t interval;
stg_usec_t timenow;

Expand Down Expand Up @@ -599,24 +601,30 @@ void WorldGui::fasttimeCb( Fl_Widget* w, WorldGui* wg )
wg->interval_real = 0;
}

void WorldGui::pauseCb( Fl_Widget* w, WorldGui* worldGui )
void WorldGui::Start()
{
worldGui->TogglePause();
World::Start();

// start the timer that causes regular redraws
Fl::add_timeout( ((double)canvas->interval/1000),
(Fl_Timeout_Handler)Canvas::TimerCallback,
canvas );
}

if( ! worldGui->paused )
{
// // start the timer that causes regular redraws
Fl::add_timeout( ((double)worldGui->canvas->interval/1000),
(Fl_Timeout_Handler)Canvas::TimerCallback,
worldGui->canvas );
}
else
{ // remove the timeout
Fl::remove_timeout( (Fl_Timeout_Handler)Canvas::TimerCallback );
}
void WorldGui::Stop()
{
World::Stop();

worldGui->canvas->redraw(); // in case something happened that will never be
// remove the redraw timeout
Fl::remove_timeout( (Fl_Timeout_Handler)Canvas::TimerCallback );

// drawn 'cos we cancelled the timeout
canvas->redraw(); // in case something happened that will never be
}

void WorldGui::pauseCb( Fl_Widget* w, WorldGui* worldGui )
{
worldGui->TogglePause();
}

void WorldGui::onceCb( Fl_Widget* w, WorldGui* worldGui )
Expand Down

0 comments on commit 2c36066

Please sign in to comment.