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

ModelDraw.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:  $
00022 */
00023 
00024 
00025 #include "Teddy/Materials/Material.h"
00026 #include "Teddy/Models/Model.h"
00027 #include "Teddy/Models/Geometry.h"
00028 #include "Teddy/PhysicalComponents/Projection.h"
00029 #include "Teddy/Scenes/Camera.h"
00030 #include "Teddy/SysSupport/StdMaths.h"
00031 #include "Teddy/SysSupport/Messages.h"
00032 using namespace Teddy::Graphics;
00033 using namespace Teddy::Materials;
00034 using namespace Teddy::Scenes;
00035 using namespace Teddy::SysSupport;
00036 
00037 
00038 namespace Teddy  {
00039 namespace Models {
00040 
00041 
00043 void Model::doMaterial( Projection *p, Model *parent ){
00044     if( material == NULL ){
00045         if( parent != NULL ){
00046             parent->doMaterial( p );
00047         }else{
00048             p->doMaterial( &Material::RED );
00049         }
00050     }else{
00051         p->doMaterial( material );
00052     }
00053 }
00054 
00055 
00057 /*virtual*/ void Model::draw( Projection *p, Model *parent ){
00058     Camera *c = p->getCamera();
00059 
00060     if( isEnabled(OPT_VISIBLE) == true ){
00061         bool setup = false;
00062 
00063         //  Draw self
00064         c->doObjectMatrix( p, getLocalToWorldMatrix() );
00065         if( c->cull(*this) == false ){
00066             if( geometry != NULL ){
00067                 doMaterial( p, parent );
00068                 setup = true;
00069 
00070 //              dmsg( M_INIT, "Drawing %s", getName().c_str() );
00071                 while( p->materialPass() ){
00072                     geometry->draw( p );
00073                 }
00074             }else{
00075 //              dmsg( M_INIT, "Not drawing %s, has no geometry", getName().c_str() );
00076             }
00077         }else{
00078 //          dmsg( M_INIT, "Not drawing %s, culled", getName().c_str() );
00079         }
00080 
00081         //  Draw children
00082         if( children.size() > 0 ){
00083             if( setup == false ){
00084                 doMaterial( p, parent );
00085             }
00086             c->pushObjectMatrix();
00087             list<Model*>::iterator m_it = children.begin();
00088             while( m_it != children.end() ){
00089                 (*m_it)->draw( p, material != NULL ? this : parent );
00090                 m_it++;
00091             }
00092             c->popObjectMatrix();
00093         }
00094     }else{
00095 //      dmsg( M_INIT, "Not drawing %s, not visible", getName().c_str() );
00096     }
00097 }
00098 
00099 
00100 };  //  namespace Models
00101 };  //  namespace Teddy
00102