// bobject.cpp -- the base class for objects in a flightgear scenery tile // // Written by Frederic Bouvier, started February 2002. // // Copyright (C) 2002 Frederic Bouvier - fredb@users.sourceforge.net // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // // $Id: bobject.cpp,v 1.15 2005/05/09 07:01:49 fredb Exp $ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "rgbimage.hpp" #include "bobject.hpp" #include #include #include "preferences.hpp" extern FGSD_Preferences generalPreferences; class FGSD_Tile; SGPropertyNode FGSD_BaseObject::_materials; bool FGSD_BaseObject::_materialInit = false; FGSD_BaseObject::MaterialColorMap FGSD_BaseObject::_materialColorMap; double FGSD_BaseObject::_factor = 1.0; FGSD_BaseObject::FGSD_BaseObject( FGSD_Tile *__tile, ObjectType __type ) : _type( __type ) , _modified( false ) , _tile( __tile ) { if ( !_materialInit ) { SGPath fgRoot = generalPreferences.fgRootPath(); SGPath materialPath = fgRoot; materialPath.append( "materials.xml" ); readProperties( materialPath.str(), &_materials ); std::vector mats = _materials.getChildren( "material" ); for ( std::vector::iterator im = mats.begin(); im != mats.end(); ++im ) { SGPropertyNode *mat = *im; SGPropertyNode *texture = mat->getChild( "texture" ); if ( texture ) { float red = 0.0, green = 0.0, blue = 0.0; FGSD_RGBImage rgb; loadRGBTexture( rgb, fgRoot, texture->getStringValue() ); rgb.getAverageColor( red, green, blue ); Color texcolor( red, green, blue ); std::vector names = mat->getChildren( "name" ); size_t n = names.size(); for ( size_t i = 0; i < n; i++ ) { SGPropertyNode *name = names[ i ]; _materialColorMap[ name->getStringValue() ] = texcolor; } } } _materialInit = true; } } FGSD_BaseObject::~FGSD_BaseObject() { } void FGSD_BaseObject::loadRGBTexture( FGSD_Image &rgb, const SGPath &fgRoot, const char *name ) { SGPath texpath = fgRoot; texpath.append( "Textures" ); texpath.append( name ); rgb.load( texpath.c_str() ); }