PlacementShadowDefinition.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <placement/PlacementShadowDefinition.h>
00022 #include <landscapemap/LandscapeMaps.h>
00023 #include <landscapemap/DeformLandscape.h>
00024 #include <common/Defines.h>
00025 #include <engine/ScorchedContext.h>
00026 #include <image/ImageStore.h>
00027 
00028 PlacementShadowDefinition::PlacementShadowDefinition() :
00029         drawShadow_(true), flattenArea_(0)
00030 {
00031 }
00032 
00033 PlacementShadowDefinition::~PlacementShadowDefinition()
00034 {
00035 }
00036 
00037 bool PlacementShadowDefinition::readXML(XMLNode *node, const char *base)
00038 {
00039         node->getNamedChild("drawshadow", drawShadow_, false);
00040         node->getNamedChild("flattenarea", flattenArea_, false);
00041 
00042         XMLNode *groundMap = 0;
00043         if (node->getNamedChild("groundmap", groundMap, false))
00044         {
00045                 if (!groundMap_.initFromNode(base, groundMap)) return false;
00046         }
00047 
00048         return true;
00049 }
00050 
00051 void PlacementShadowDefinition::updateLandscapeHeight(
00052         ScorchedContext &context,
00053         FixedVector &position, FixedVector &size)
00054 {
00055         if (flattenArea_ != 0)
00056         {
00057                 fixed areaSize = flattenArea_;
00058                 if (areaSize < 0)
00059                 {
00060                         areaSize = MAX(size[0], size[1])/2 + 1;
00061                 }
00062 
00063                 DeformLandscape::flattenArea(context, position, false, areaSize);
00064         }
00065 }
00066 
00067 #ifndef S3D_SERVER
00068 
00069 #include <GLEXT/GLImageModifier.h>
00070 void PlacementShadowDefinition::updateLandscapeTexture(
00071         bool useShadows,
00072         ScorchedContext &context,
00073         FixedVector &position, FixedVector &size)
00074 {
00075         if (groundMap_.imageValid())
00076         {
00077                 Image *image = ImageStore::instance()->loadImage(groundMap_);
00078                 ImageModifier::addBitmapToLandscape(
00079                         context,
00080                         *image,
00081                         position[0].asFloat(), 
00082                         position[1].asFloat(),
00083                         0.25f, 0.25f);
00084         }
00085 
00086         if (drawShadow_ && useShadows)
00087         {
00088                 ImageModifier::addCircleToLandscape(
00089                         context,
00090                         position[0].asFloat(), 
00091                         position[1].asFloat(), 
00092                         MAX(size[0], size[1]).asFloat(), 1.0f);
00093         }
00094 }
00095 
00096 #endif //S3D_SERVER

Generated on Mon Feb 16 15:14:51 2009 for Scorched3D by  doxygen 1.5.3