charger.cc
Go to the documentation of this file.
00001 
00009 #include "stage.hh"
00010 #include "worldfile.hh"
00011 using namespace Stg;
00012 
00013 Charger::Charger( World* world ) 
00014   : world( world ), watts( 1000.0 )
00015 {
00016   //printf( "Charger constructed" );
00017 }
00018 
00019 void Charger::ChargeIfContained( PowerPack* pp, Pose pose )
00020 {
00021   if( Contains( pose ) )
00022          Charge( pp );
00023 }
00024 
00025 bool Charger::Contains( Pose pose )
00026 {
00027   return( pose.x >= volume.x.min &&
00028                          pose.x  < volume.x.max &&
00029                          pose.y >= volume.y.min &&
00030                          pose.y  < volume.y.max &&
00031                          pose.z >= volume.z.min &&
00032                          pose.z  < volume.z.max );
00033 }
00034          
00035 void Charger::Charge( PowerPack* pp )
00036 {
00037   double given = watts * world->interval_sim * 1e-6;
00038   
00039   pp->stored += given;
00040   
00041   // do not exceed capacity
00042   pp->stored = MIN( pp->stored, pp->capacity );
00043   pp->charging = true;
00044   /*
00045          printf( "charger %p  at [%.2f %.2f] [%.2f %.2f] [%.2f %.2f] gave pack %p %.3f joules\n",
00046          this,
00047          volume.x.min,
00048          volume.x.max,
00049          volume.y.min,
00050          volume.y.max,
00051          volume.z.min,
00052          volume.z.max,
00053          pp, given );
00054   
00055   pp->Print( "just charged" );
00056   */
00057 }
00058 
00059 void Charger::Visualize()
00060 {
00061 
00062   glPushMatrix();
00063   glPolygonMode( GL_FRONT, GL_FILL );
00064   glColor4f( 1, 0.5,0,0.4 );
00065   glTranslatef( 0,0,volume.z.min);
00066   glRectf( volume.x.min, volume.y.min, volume.x.max, volume.y.max );
00067   
00068   glTranslatef( 0,0,volume.z.max );
00069   glRectf( volume.x.min, volume.y.min, volume.x.max, volume.y.max );
00070   glPopMatrix();
00071 
00072   glPushMatrix();
00073   glPolygonMode( GL_FRONT, GL_LINE );
00074   glColor4f( 1, 0.5,0,0.8 );
00075   glTranslatef( 0,0,volume.z.min);
00076   glRectf( volume.x.min, volume.y.min, volume.x.max, volume.y.max );
00077   
00078   glTranslatef( 0,0,volume.z.max );
00079   glRectf( volume.x.min, volume.y.min, volume.x.max, volume.y.max );
00080   glPopMatrix();
00081 
00082   // ?
00083   //glPolygonMode( GL_FRONT, GL_FILL );
00084 }
00085 
00086 void swap( double &a, double &b )
00087 {
00088   double keep = a;
00089   a = b;
00090   b = keep;
00091 }
00092 
00093 void Charger::Load( Worldfile* wf, int entity )
00094 {
00095   if( wf->PropertyExists( entity, "volume" ) )
00096          {
00097                 volume.x.min = wf->ReadTupleLength( entity, "volume", 0, volume.x.min );
00098                 volume.x.max = wf->ReadTupleLength( entity, "volume", 1, volume.x.max );
00099                 volume.y.min = wf->ReadTupleLength( entity, "volume", 2, volume.y.min );
00100                 volume.y.max = wf->ReadTupleLength( entity, "volume", 3, volume.y.max );
00101                 volume.z.min = wf->ReadTupleLength( entity, "volume", 4, volume.z.min );
00102                 volume.z.max = wf->ReadTupleLength( entity, "volume", 5, volume.z.max );
00103                 
00104                 // force the windings for GL's sake
00105                 if( volume.x.min > volume.x.max )
00106                   swap( volume.x.min, volume.x.max );
00107                 
00108                 if( volume.y.min > volume.y.max )
00109                   swap( volume.y.min, volume.y.max );
00110 
00111                 if( volume.z.min > volume.z.max )
00112                   swap( volume.z.min, volume.z.max );
00113                 
00114          }
00115   
00116   watts = wf->ReadFloat( entity, "watts", watts );
00117 }


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