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 "Teddy/TeddyConfig.h"
00026 #include "Teddy/Scenes/PostElement.h"
00027 #include "Teddy/Graphics/View.h"
00028 #include "Teddy/Graphics/ImageFileTexture.h"
00029 #include "Teddy/Maths/Vector2.h"
00030 #include "Teddy/Maths/Vector4.h"
00031 #include "Teddy/PhysicalComponents/Projection.h"
00032 #include "Teddy/Scenes/Camera.h"
00033 #include "Teddy/SysSupport/StdList.h"
00034 #include "Teddy/SysSupport/StdIO.h"
00035 using namespace Teddy::Graphics;
00036 using namespace Teddy::Materials;
00037 using namespace Teddy::Maths;
00038 using namespace Teddy::PhysicalComponents;
00039 using namespace Teddy::Scenes;
00040
00041
00042 namespace Teddy {
00043 namespace Scenes {
00044
00045
00046 PostElement::PostElement( char *filename ){
00047 txt = new ImageFileTexture( filename );
00048 }
00049
00050
00051 PostElement::~PostElement(){
00052 }
00053
00054
00055 void PostElement::insert( Ellipsoid *e ){
00056 ellipsoids.push_back( e );
00057 }
00058
00059
00060 void PostElement::draw( Projection *p ){
00061 #if 0
00062 Camera *camera = p->getCamera();
00063 View *view = p->getView();
00064 double n = camera->getNear();
00065
00066
00067 if( txt != NULL ){
00068 txt->apply();
00069 view->enable( TEXTURE_2D );
00070 }else{
00071 view->disable( TEXTURE_2D );
00072 }
00073 view->disable ( DEPTH_TEST );
00074 view->enable ( BLEND );
00075
00076 view->setBlendFunc( GL_ONE, GL_ONE );
00077 view->setModelViewMatrix();
00078 p->color( C_WHITE );
00079
00080 list<Ellipsoid*>::iterator e_it = ellipsoids.begin();
00081 while( e_it != ellipsoids.end() ){
00082 Ellipsoid *e = *e_it;
00083 Matrix cam = camera->getWorldToLocalMatrix();
00084
00085 Vector viewLocation( cam * Vector4(e->location,1.0) );
00086 Vector viewForward ( cam * Vector4(e->forward, 0.0) );
00087 Vector center ( viewLocation );
00088 Vector top ( center + viewForward * e->front );
00089 Vector bottom ( center - viewForward * e->rear );
00090
00091 float z = min( top[2], bottom[2] ) - e->radius;
00092
00093 if( z < n ){
00094 top *= (z / top [2]);
00095 center *= (z / center[2]);
00096 bottom *= (z / bottom[2]);
00097
00098 Vector2 delta( top[0] - bottom[0], top[1] - bottom[1] );
00099 float offset = delta.magnitude();
00100 if( offset > 0 ){
00101 delta /= offset;
00102 }else{
00103
00104 delta[0] = 0;
00105 delta[1] = 0;
00106 }
00107
00108 Vector2 right( delta[1] * e->radius, -delta[0] * e->radius );
00109 Vector2 up ( delta[0] * e->radius, delta[1] * e->radius );
00110
00111 p->beginQuadStrip();
00112 p->texture( 0.0f, 0.0f ); p->vertex( top [0] - right[0] + up[0], top [1] - right[1] + up[1], top [2] );
00113 p->texture( 1.0f, 0.0f ); p->vertex( top [0] + right[0] + up[0], top [1] + right[1] + up[1], top [2] );
00114 p->texture( 0.0f, 0.5f ); p->vertex( center[0] - right[0] , center[1] - right[1] , center[2] );
00115 p->texture( 1.0f, 0.5f ); p->vertex( center[0] + right[0] , center[1] + right[1] , center[2] );
00116 p->texture( 0.0f, 1.0f ); p->vertex( bottom[0] - right[0] - up[0], bottom[1] - right[1] - up[1], bottom[2] );
00117 p->texture( 1.0f, 1.0f ); p->vertex( bottom[0] + right[0] - up[0], bottom[1] + right[1] - up[1], bottom[2] );
00118 p->end();
00119 }
00120 e_it++;
00121 }
00122
00123 #endif
00124 }
00125
00126
00127 };
00128 };
00129