gl.cc
Go to the documentation of this file.
00001 
00002 #include "stage.hh"
00003 using namespace Stg;
00004 
00005 // transform the current coordinate frame by the given pose
00006 void Stg::Gl::coord_shift( double x, double y, double z, double a  )
00007 {
00008         glTranslatef( x,y,z );
00009         glRotatef( rtod(a), 0,0,1 );
00010 }
00011 
00012 // transform the current coordinate frame by the given pose
00013 void Stg::Gl::pose_shift( const Pose &pose )
00014 {
00015         coord_shift( pose.x, pose.y, pose.z, pose.a );
00016 }
00017 
00018 void Stg::Gl::pose_inverse_shift( const Pose &pose )
00019 {
00020   coord_shift( 0,0,0, -pose.a );
00021   coord_shift( -pose.x, -pose.y, -pose.z, 0 );
00022 }
00023 
00024 void Stg::Gl::draw_array( float x, float y, float w, float h, 
00025                                                                   float* data, size_t len, size_t offset,
00026                                                                   float min, float max )
00027 {
00028   float sample_spacing = w / (float)len;
00029   float yscale = h / (max-min);
00030   
00031   //printf( "min %.2f max %.2f\n", min, max );
00032 
00033   glBegin( GL_LINE_STRIP );
00034 
00035   for( unsigned int i=0; i<len; i++ )
00036          glVertex3f( x + (float)i*sample_spacing, y+(data[(i+offset)%len]-min)*yscale, 0.01 );
00037   
00038   glEnd();
00039   
00040   glColor3f( 0,0,0 );
00041   char buf[64];
00042   snprintf( buf, 63, "%.2f", min );
00043   Gl::draw_string( x,y,0,buf );
00044   snprintf( buf, 63, "%.2f", max );
00045   Gl::draw_string( x,y+h-fl_height(),0,buf );
00046 
00047 }
00048 
00049 void Stg::Gl::draw_array( float x, float y, float w, float h, 
00050                           float* data, size_t len, size_t offset )
00051 {
00052   // wild initial bounds
00053   float smallest = 1e16;
00054   float largest = -1e16;
00055   
00056   for( size_t i=0; i<len; i++ )
00057     {
00058       smallest = std::min( smallest, data[i] );
00059       largest = std::max( largest, data[i] );
00060     }
00061 
00062   draw_array( x,y,w,h,data,len,offset,smallest,largest );
00063 }
00064 
00065 void Stg::Gl::draw_string( float x, float y, float z, const char *str ) 
00066 {  
00067   glRasterPos3f( x, y, z );
00068    
00069    GLboolean b;
00070    glGetBooleanv( GL_CURRENT_RASTER_POSITION_VALID, &b );  
00071 
00072    //printf( "[%.2f %.2f %.2f] %d string %u %s\n", x,y,z, (int)b, (unsigned int)strlen(str), str ); 
00073    
00074    if( b ) gl_draw( str ); // fltk function
00075 }
00076 
00077 void Stg::Gl::draw_string_multiline( float x, float y, float w, float h,  const char *str, Fl_Align align ) 
00078 {  
00079   //printf( "[%.2f %.2f %.2f] string %u %s\n", x,y,z,(unsigned int)strlen(str), str ); 
00080   gl_draw(str, x, y, w, h, align ); // fltk function
00081 }
00082 
00083 void Stg::Gl::draw_speech_bubble( float x, float y, float z, const char* str )
00084 {  
00085         draw_string( x, y, z, str );
00086 }
00087 
00088 // draw an octagon with center rectangle dimensions w/h
00089 //   and outside margin m
00090 void Stg::Gl::draw_octagon( float w, float h, float m )
00091 {
00092         glBegin(GL_POLYGON);
00093         glVertex2f( m+w, 0 );
00094         glVertex2f( w+2*m, m );
00095         glVertex2f( w+2*m, h+m );
00096         glVertex2f( m+w, h+2*m );
00097         glVertex2f( m, h+2*m );
00098         glVertex2f( 0, h+m );
00099         glVertex2f( 0, m );
00100         glVertex2f( m, 0 );
00101         glEnd();
00102 }
00103 
00104 // draw an octagon with center rectangle dimensions w/h
00105 //   and outside margin m
00106 void Stg::Gl::draw_octagon( float x, float y, float w, float h, float m )
00107 {
00108         glBegin(GL_POLYGON);
00109         glVertex2f( x + m+w, y );
00110         glVertex2f( x+w+2*m, y+m );
00111         glVertex2f( x+w+2*m, y+h+m );
00112         glVertex2f( x+m+w, y+h+2*m );
00113         glVertex2f( x+m, y+h+2*m );
00114         glVertex2f( x, y+h+m );
00115         glVertex2f( x, y+m );
00116         glVertex2f( x+m, y );
00117         glEnd();
00118 }
00119 
00120 
00121 void Stg::Gl::draw_centered_rect( float x, float y, float dx, float dy )
00122 {
00123   glRectf( x-0.5*dx, y-0.5*dy, x+0.5*dx, y+0.5*dy );
00124 }
00125 
00126 void Stg::Gl::draw_vector( double x, double y, double z )
00127 {
00128   glBegin( GL_LINES );
00129   glVertex3f( 0,0,0 );
00130   glVertex3f( x,y,z );
00131   glEnd();
00132 }
00133 
00134 void Stg::Gl::draw_origin( double len )
00135 {
00136   draw_vector( len,0,0 );
00137   draw_vector( 0,len,0 );
00138   draw_vector( 0,0,len );
00139 }
00140 
00141 void Stg::Gl::draw_grid( bounds3d_t vol )
00142 {
00143         glBegin(GL_LINES);
00144 
00145         for( double i = floor(vol.x.min); i < vol.x.max; i++)
00146         {
00147                 glVertex2f(  i, vol.y.min );
00148                 glVertex2f(  i, vol.y.max );
00149         }
00150 
00151         for( double i = floor(vol.y.min); i < vol.y.max; i++)
00152         {
00153                 glVertex2f(  vol.x.min, i );
00154                 glVertex2f(  vol.x.max, i );
00155         }
00156 
00157         glEnd();
00158 
00159         char str[16];
00160 
00161         for( double i = floor(vol.x.min); i < vol.x.max; i++)
00162         {
00163                 snprintf( str, 16, "%d", (int)i );
00164                 draw_string(  i, 0, 0.00, str );
00165         }
00166 
00167         for( double i = floor(vol.y.min); i < vol.y.max; i++)
00168         {
00169                 snprintf( str, 16, "%d", (int)i );
00170                 draw_string(  0, i, 0.00, str );
00171         }
00172 }
00173 
00174 


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Thu Aug 27 2015 15:20:57