00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
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 };
00159 };
00160