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

LWSurfaceBlokImageMap.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: LWSurfaceBlokImageMap.cpp,v 1.6 2002/02/16 16:38:11 tksuoran Exp $
00022 */
00023 
00024 
00025 #include "Teddy/TeddyConfig.h"
00026 #if defined( TEDDY_INCLUDE_LW_SCENE )
00027 
00028 
00029 #if defined(_MSC_VER)
00030 #   pragma warning(disable:4786)
00031 #endif
00032 
00033 
00034 #include "Teddy/Imports/LWClip.h"
00035 #include "Teddy/Imports/LWFile.h"
00036 #include "Teddy/Imports/LWLayer.h"
00037 #include "Teddy/Imports/LWModel.h"
00038 #include "Teddy/Imports/LWSurface.h"
00039 #include "Teddy/Imports/LWSurfaceBlok.h"
00040 #include "Teddy/Models/Geometry.h"
00041 #include "Teddy/Graphics/Texture.h"
00042 #include "Teddy/Graphics/ImageFileTexture.h"
00043 #include "Teddy/SysSupport/Messages.h"
00044 #include "Teddy/SysSupport/FileScan.h"
00045 #include "Teddy/SysSupport/StdMaths.h"
00046 #include "Teddy/SysSupport/StdIO.h"
00047 using namespace Teddy::Graphics;
00048 using namespace Teddy::SysSupport;
00049 
00050 
00051 namespace Teddy   {
00052 namespace Imports {
00053 
00054 
00055 void LWSurfaceBlok::applyImageMap(){
00056     //  Disabled image maps are easy to handle
00057     if( enable == 0 ){
00058         return;
00059     }
00060 
00061     //  At the moment only color textures are supported
00062     if( texture_channel != ID_COLR ){
00063         dmsg( M_LWO,
00064             "Texture channel %s not supported; only COLR channel is supported.",
00065             did( texture_channel )
00066         );
00067     }
00068 
00069     //  We need to get the texture name; only still images are supported
00070     LWLayer *layer = dynamic_cast<LWLayer*>( surface->getLayer() );
00071     if( layer == NULL ){
00072         emsg( M_LWO, "Layer not found" );
00073         return;
00074     }
00075 
00076     Model *model = surface->getModel();
00077     if( model == NULL ){
00078         emsg( M_LWO, "Model not found" );
00079     }
00080 
00081     LWClip *clip = layer->getClip( texture_image_map );
00082     if( clip == NULL ){
00083         emsg( M_LWO,
00084             "Texture image map %d not found",
00085             texture_image_map
00086         );
00087         return;
00088     }
00089 
00090     std::string texture_file_name = clip->still_image;
00091     std::string final_file_name   = fix_file_name( "Data/textures/", texture_file_name.c_str() );
00092     dmsg( M_LWO, "Look for texture file '%s'", final_file_name.c_str() );
00093     Texture *t = new ImageFileTexture( final_file_name );
00094     surface->setTexture( t, true );
00095 
00096     //  Choose projection mode
00097     switch( texture_projection_mode ){
00098     case LW_PROJECTION_PLANAR:
00099         model->getGeometry()->makePlanarTextureCoordinates(
00100             texture_center,
00101             texture_size,
00102             texture_major_axis
00103         );
00104         dmsg( M_TMAP, "Planar Image Map done" );
00105         break;
00106 
00107     case LW_PROJECTION_CYLINDRICAL:
00108         model->getGeometry()->makeCylindricalTextureCoordinates(
00109             texture_center,
00110             texture_size,
00111             texture_major_axis
00112         );
00113         dmsg( M_TMAP, "Cylindrical Image Map done" );
00114         break;
00115 
00116     case LW_PROJECTION_SPHERICAL:
00117         model->getGeometry()->makeSphericalTextureCoordinates(
00118             texture_center,
00119             texture_size,
00120             texture_major_axis
00121         );
00122         dmsg( M_TMAP, "Spherical Image Map done" );
00123         break;
00124 
00125     case LW_PROJECTION_CUBIC:
00126         model->getGeometry()->makeCubicTextureCoordinates(
00127             texture_center,
00128             texture_size
00129         );
00130         dmsg( M_TMAP, "Cubic Image Map done" );
00131         break;
00132 
00133     case LW_PROJECTION_FRONT:
00134         dmsg( M_TMAP, "Front projection not yet implemented" );
00135         break;
00136 
00137     case LW_PROJECTION_UV:
00138         dmsg( M_TMAP, "UV projection not yet implemented" );
00139         break;
00140 
00141     default:
00142         dmsg( M_TMAP, "Unknown projection mode" );
00143         break;
00144     }
00145 
00146 }
00147 
00148 
00149 };  //  namespace Imports
00150 };  //  namespace Teddy
00151 
00152 
00153 #endif  //  TEDDY_INCLUDE_LW_SCENE
00154