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

PostElement.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-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: PostElement.cpp,v 1.5 2002/01/14 09:14:15 tksuoran Exp $
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 /*virtual*/ PostElement::~PostElement(){
00052 }
00053 
00054 
00055 void PostElement::insert( Ellipsoid *e ){
00056     ellipsoids.push_back( e );
00057 }
00058 
00059 
00060 /*virtual*/ 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     //view->enable( DEPTH_TEST );
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     //glDepthMask     ( GL_FALSE );
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         //  This test is not right.. The whole z might not be right?
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                 //delta.set( 0, 1 );
00104                 delta[0] = 0;
00105                 delta[1] = 0; //.set( 0, 1 );
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     //glDepthMask( GL_TRUE );
00123 #endif
00124 }
00125 
00126 
00127 };  //  namespace Scenes
00128 };  //  namespace Teddy  
00129