Revision: 7561
http://playerstage.svn.sourceforge.net/playerstage/?rev=7561&view=rev
Author: rtv
Date: 2009-03-30 21:43:22 +0000 (Mon, 30 Mar 2009)
Log Message:
-----------
vis stuff
Modified Paths:
--------------
code/stage/trunk/libstage/canvas.cc
code/stage/trunk/libstage/gl.cc
code/stage/trunk/libstage/model_draw.cc
code/stage/trunk/libstage/powerpack.cc
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-03-30 18:27:45 UTC (rev 7560)
+++ code/stage/trunk/libstage/canvas.cc 2009-03-30 21:43:22 UTC (rev 7561)
@@ -147,7 +147,6 @@
GLuint mains_id = TextureManager::getInstance().loadTexture(
fullpath.c_str() );
TextureManager::getInstance()._mains_texture_id = mains_id;
-
//TODO merge this code into the textureManager?
int i, j;
@@ -177,6 +176,8 @@
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ fl_font( FL_HELVETICA, 12 );
+
init_done = true;
}
@@ -940,7 +941,9 @@
}
if( showClock )
- {
+ {
+ glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+
//use orthogonal projeciton without any zoom
glMatrixMode (GL_PROJECTION);
glPushMatrix(); //save old projection
@@ -958,22 +961,31 @@
if( showFollow == true && last_selection )
clockstr.append( " [ FOLLOW MODE ]" );
- fl_font( FL_HELVETICA, 12 );
- float txtWidth = gl_width( clockstr.c_str() );
+ float txtWidth = gl_width( clockstr.c_str());
+ if( txtWidth < 200 ) txtWidth = 200;
int txtHeight = gl_height();
- int width, height;
- width = int( txtWidth / 10 ) * 10;
- height = ( txtHeight / 5 + 1 ) * 5;
- float margin = ( height - txtHeight ) * 0.75;
+ const int margin = 5;
+ int width, height;
+ width = txtWidth + 2 * margin;
+ height = txtHeight + 2 * margin;
+ // TIME BOX
colorstack.Push( 0.8,0.8,1.0 ); // pale blue
glRectf( 0, 0, width, height );
- colorstack.Pop();
-
+ colorstack.Push( 0,0,0 ); // black
+ Gl::draw_string( margin, margin, 0, clockstr.c_str() );
+
+ // ENERGY BOX
+ 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( margin, margin, 0, clockstr.c_str() );
+ Gl::draw_string_multiline( margin, height + margin, txtWidth,
50, world->EnergyString().c_str(), (Fl_Align)( FL_ALIGN_LEFT | FL_ALIGN_BOTTOM)
);
+
colorstack.Pop();
+ colorstack.Pop();
+ colorstack.Pop();
+ colorstack.Pop();
glEnable( GL_DEPTH_TEST );
glPopMatrix();
Modified: code/stage/trunk/libstage/gl.cc
===================================================================
--- code/stage/trunk/libstage/gl.cc 2009-03-30 18:27:45 UTC (rev 7560)
+++ code/stage/trunk/libstage/gl.cc 2009-03-30 21:43:22 UTC (rev 7561)
@@ -24,9 +24,16 @@
void Stg::Gl::draw_string( float x, float y, float z, const char *str )
{
- glRasterPos3f( x, y, z );
+ glRasterPos3f( x, y, z );
+ //printf( "[%.2f %.2f %.2f] string %u %s\n", x,y,z,(unsigned
int)strlen(str), str );
+ gl_draw( str );
+}
+
+void Stg::Gl::draw_string_multiline( float x, float y, float w, float h,
const char *str, Fl_Align align )
+{
+ //glRasterPos3f( x, y, z );
//printf( "[%.2f %.2f %.2f] string %u %s\n", x,y,z,(unsigned
int)strlen(str), str );
- gl_draw(str);
+ gl_draw(str, x, y, w, h, align ); // fltk function
}
void Stg::Gl::draw_speech_bubble( float x, float y, float z, const char* str )
@@ -50,6 +57,23 @@
glEnd();
}
+// draw an octagon with center rectangle dimensions w/h
+// and outside margin m
+void Stg::Gl::draw_octagon( float x, float y, float w, float h, float m )
+{
+ glBegin(GL_POLYGON);
+ glVertex2f( x + m+w, y );
+ glVertex2f( x+w+2*m, y+m );
+ glVertex2f( x+w+2*m, y+h+m );
+ glVertex2f( x+m+w, y+h+2*m );
+ glVertex2f( x+m, y+h+2*m );
+ glVertex2f( x, y+h+m );
+ glVertex2f( x, y+m );
+ glVertex2f( x+m, y );
+ glEnd();
+}
+
+
void Stg::Gl::draw_centered_rect( float x, float y, float dx, float dy )
{
glRectf( x-0.5*dx, y-0.5*dy, x+0.5*dx, y+0.5*dy );
Modified: code/stage/trunk/libstage/model_draw.cc
===================================================================
--- code/stage/trunk/libstage/model_draw.cc 2009-03-30 18:27:45 UTC (rev
7560)
+++ code/stage/trunk/libstage/model_draw.cc 2009-03-30 21:43:22 UTC (rev
7561)
@@ -325,6 +325,8 @@
if( say_string )
{
+ glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+
//get raster positition, add gl_width, then project
back to world coords
glRasterPos3f( 0, 0, 0 );
GLfloat pos[ 4 ];
@@ -335,7 +337,7 @@
if( valid )
{
- fl_font( FL_HELVETICA, 12 );
+ //fl_font( FL_HELVETICA, 12 );
float w = gl_width( this->say_string ); //
scaled text width
float h = gl_height(); // scaled text height
@@ -379,7 +381,7 @@
PushColor( BUBBLE_TEXT );
// draw text inside the bubble
- Gl::draw_string( 2.5*m, 2.5*m, 0,
this->say_string );
+ Gl::draw_string( m, 2.5*m, 0,
this->say_string );
PopColor();
}
}
Modified: code/stage/trunk/libstage/powerpack.cc
===================================================================
--- code/stage/trunk/libstage/powerpack.cc 2009-03-30 18:27:45 UTC (rev
7560)
+++ code/stage/trunk/libstage/powerpack.cc 2009-03-30 21:43:22 UTC (rev
7561)
@@ -124,10 +124,7 @@
// draw the percentage
- //gl_draw_string( -0.2, 0, 0, buf );
-
- // ?
- // glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+ //gl_draw_string( -0.2, 0, 0, buf );
}
@@ -237,6 +234,7 @@
//------------------------------------------------------------------------------
// Dissipation Visualizer class
+stg_joules_t PowerPack::DissipationVis::global_peak_value = 0.0;
PowerPack::DissipationVis::DissipationVis( stg_meters_t width,
stg_meters_t height,
@@ -274,7 +272,7 @@
stg_joules_t j = cells[ y*columns + x ];
if( j > 0 )
{
- glColor4f( 1.0, 0, 0, j/peak_value );
+ glColor4f( 1.0, 0, 0, j/global_peak_value );
glRectf( x,y,x+1,y+1 );
}
}
@@ -300,5 +298,10 @@
(*j) += amount;
if( (*j) > peak_value )
- peak_value = (*j);
+ {
+ peak_value = (*j);
+
+ if( peak_value > global_peak_value )
+ global_peak_value = peak_value;
+ }
}
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2009-03-30 18:27:45 UTC (rev 7560)
+++ code/stage/trunk/libstage/stage.hh 2009-03-30 21:43:22 UTC (rev 7561)
@@ -468,8 +468,11 @@
void draw_grid( stg_bounds3d_t vol );
/** Render a string at [x,y,z] in the current color */
void draw_string( float x, float y, float z, const char *string);
+ void draw_string_multiline( float x, float y, float w, float h,
+
const char *string, Fl_Align align );
void draw_speech_bubble( float x, float y, float z, const char* str );
void draw_octagon( float w, float h, float m );
+ void draw_octagon( float x, float y, float w, float h, float m );
void draw_vector( double x, double y, double z );
void draw_origin( double len );
/** Draws a rectangle with center at x,y, with sides of length dx,dy */
@@ -1414,6 +1417,9 @@
/** Get human readable string that describes the current simulation
time. */
std::string ClockString( void );
+
+ /** Get human readable string that describes the current global energy
state. */
+ std::string EnergyString( void );
/** Set the minimum real time interval between world updates, in
microeconds. */
@@ -1437,8 +1443,10 @@
unsigned int columns, rows;
stg_meters_t width, height;
stg_joules_t* cells;
- double peak_value;
+ stg_joules_t peak_value;
double cellsize;
+
+ static stg_joules_t global_peak_value;
public:
DissipationVis( stg_meters_t width,
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2009-03-30 18:27:45 UTC (rev
7560)
+++ code/stage/trunk/libstage/worldgui.cc 2009-03-30 21:43:22 UTC (rev
7561)
@@ -406,36 +406,41 @@
average_real_interval /= INTERVAL_LOG_LEN;
double localratio = (double)interval_sim / (double)average_real_interval;
+
+ std::string str;
+ char buf[256];
- std::ostringstream status_stream;
- status_stream.fill( '0' );
- if( hours > 0 )
- status_stream << hours << "h";
-
- status_stream << std::setw( 2 ) << minutes << "m"
- << std::setw( 2 ) << seconds << "." << std::setprecision( 3 ) <<
std::setw( 3 ) << msec << "s ";
-
- char str[ 256 ];
- snprintf( str, 255, "[%.2f]", localratio );
- status_stream << str;
-
-
- snprintf( str, 255, "<stored: %.0f/%.0fKJ input: %.0fKJ dissipated:
%.0fKJ power: %.2fKW>",
- PowerPack::global_stored / 1e3,
- PowerPack::global_capacity /1e3,
- PowerPack::global_input / 1e3,
- PowerPack::global_dissipated / 1e3,
- (PowerPack::global_dissipated / (sim_time /
1e6)) / 1e3 );
-
- status_stream << str;
+ if( hours > 0 )
+ {
+ snprintf( buf, 255, "%uh", hours );
+ str += buf;
+ }
- if( paused == true )
- status_stream << " [ PAUSED ]";
-
-
- return status_stream.str();
+ snprintf( buf, 255, "%um%02us%03umsec [%.2f]", minutes, seconds, msec,
localratio );
+ str += buf;
+
+ if( paused == true )
+ str += " [ PAUSED ]";
+
+ return str;
}
+std::string WorldGui::EnergyString()
+{
+ char str[512];
+
+ snprintf( str, 255, "Energy\n stored: %.0f / %.0f KJ\n input: %.0f
KJ\n output: %.0f KJ at %.2f KW\n",
+ PowerPack::global_stored / 1e3,
+ PowerPack::global_capacity /1e3,
+ PowerPack::global_input / 1e3,
+ PowerPack::global_dissipated / 1e3,
+ (PowerPack::global_dissipated / (sim_time /
1e6)) / 1e3 );
+
+ std::string s( str );
+ return s;
+}
+
+
// callback wrapper for SuperRegion::Draw()
static void Draw_cb( gpointer dummykey,
SuperRegion* sr,
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit