Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Scanner.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TSGL - Teddy Space Game Library
00004     Copyright (C) 2002 Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id: Scanner.cpp,v 1.1 2002/01/08 20:47:05 tksuoran Exp $
00022 */
00023 
00024 
00025 #include "config.h"
00026 #include "Teddy/SpaceGame/Root.h"
00027 #include "Teddy/SpaceGame/Scanner.h"
00028 #include "Teddy/Graphics/ImageFileTexture.h"
00029 #include "Teddy/Graphics/View.h"
00030 #include "Teddy/Materials/Material.h"
00031 #include "Teddy/Maths/Vector.h"
00032 #include "Teddy/Models/ModelInstance.h"
00033 #include "Teddy/PhysicalComponents/GradientFill.h"
00034 #include "Teddy/PhysicalComponents/TextureFill.h"
00035 #include "Teddy/PhysicalComponents/LayoutConstraint.h"
00036 #include "Teddy/PhysicalComponents/Style.h"
00037 #include "Teddy/PhysicalComponents/WindowFrame.h"
00038 #include "Teddy/Scenes/Camera.h"
00039 #include "Teddy/Scenes/Scene.h"
00040 #include <cstdio>
00041 using namespace Teddy::Graphics;
00042 using namespace Teddy::Models;
00043 using namespace Teddy::PhysicalComponents;
00044 
00045 
00046 namespace Teddy     {
00047 namespace SpaceGame {
00048 
00049 
00051 Scanner::Scanner( Root *root )
00052 :
00053 Area( "Scanner" )
00054 {
00055     txt = new ImageFileTexture( "gui/scanner.png" );
00056 
00057     this->root       = root;
00058     this->camera     = root->getObjectManager()->getCamera();
00059     this->constraint = new LayoutConstraint();
00060     constraint->local_x_offset_relative  =  -0.5f;
00061     constraint->local_y_offset_relative  =  -1;
00062     constraint->local_x_offset_pixels    =   0;
00063     constraint->local_y_offset_pixels    = -10;
00064     constraint->parent_x_offset_relative =   0.5f;
00065     constraint->parent_y_offset_relative =   1;
00066     constraint->local_x_fill_pixels      = 256;
00067     constraint->local_y_fill_pixels      =  70;
00068 
00069     /*
00070     this->insert(
00071         new Teddy::PhysicalComponents::GradientFill(
00072             Color( 0.7f, 0.0f, 0.1f, 0.83f ),
00073             Color( 0.7f, 0.0f, 0.1f, 0.83f ),
00074             Color( 0.7f, 0.0f, 0.1f, 0.53f ),
00075             Color( 0.7f, 0.0f, 0.1f, 0.53f )
00076         )
00077     );
00078 
00079     this->insert(
00080         new WindowFrame( "Scanner" )
00081     );*/
00082 
00083     range    = 8;
00084     ordering = post_self;
00085 }
00086 
00087 
00088 void Scanner::cycle(){
00089     range = (range<32)? range*=2 : 1;
00090 }
00091 
00092 
00094 void Scanner::drawSelf(){
00095     color( C_WHITE );
00096     if( txt != NULL ){
00097         view->blit( txt, this->viewport[0], this->viewport[1] );
00098     }
00099 
00100     return;
00101     view->disable( TEXTURE_2D );
00102 
00103     list<ModelInstance*> instances = camera->getScene()->getInstances();
00104     Vector loc;
00105     int    x;
00106     int    y;
00107     int    z;
00108     int    x1;
00109     int    y1;
00110     int    y2;
00111     Matrix w2l = camera->worldToLocal();
00112 
00113     list<ModelInstance*>::iterator i_it = instances.begin();
00114     while( i_it != instances.end() ){
00115         Vector pos = (*i_it)->getPosition();
00116         Vector loc = w2l.transformVector( pos );
00117         loc = loc * (float)(range);
00118 
00119         Color c;
00120         Material *mat = (*i_it)->getMaterial();
00121         if( mat != NULL ){
00122             c = mat->getDiffuse();
00123         }else{
00124             c = Color::GRAY_50;
00125         }
00126         color( c );
00127 
00128         x = (int)( loc.v[0] * 0.01 );
00129         y = (int)( loc.v[1] * 0.01 );
00130         z = (int)( loc.v[2] *-0.01 );
00131 
00132         x1 = x;
00133         y1 = -z / 4;
00134         y2 = y1 - y / 2;
00135 
00136         if( (y2 > - 50) && (y2 < 50) &&
00137             (x1 > -100) && (x1 <100)    )
00138         {
00139 
00140             x1 += 127;
00141             y1 += 31;
00142             y2 += 31;
00143 
00144             beginLines();
00145             vertex2i( x1  , y2   ); vertex2i( x1+3, y2   );
00146             vertex2i( x1  , y2+1 ); vertex2i( x1+4, y2+1 );
00147             vertex2i( x1  , y2+2 ); vertex2i( x1+4, y2+2 );
00148             vertex2i( x1  , y2+3 ); vertex2i( x1+3, y2+3 );
00149             vertex2i( x1  , y1   ); vertex2i( x1  , y2   );
00150             vertex2i( x1+1, y1   ); vertex2i( x1+1, y2   );
00151             end();
00152         }
00153         i_it++;
00154     }
00155 }
00156 
00157 
00158 };  //  namespace SpaceGame
00159 };  //  namespace Teddy
00160