git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / common / placement / PlacementShadowDefinition.cpp
blob394f080e1224d75f6ba6cc0643f3bbf576dcb9b7
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <placement/PlacementShadowDefinition.h>
22 #include <landscapemap/LandscapeMaps.h>
23 #include <landscapemap/DeformLandscape.h>
24 #include <common/Defines.h>
25 #include <engine/ScorchedContext.h>
26 #include <image/ImageStore.h>
28 PlacementShadowDefinition::PlacementShadowDefinition() :
29 drawShadow_(true), flattenArea_(0)
33 PlacementShadowDefinition::~PlacementShadowDefinition()
37 bool PlacementShadowDefinition::readXML(XMLNode *node, const char *base)
39 node->getNamedChild("drawshadow", drawShadow_, false);
40 node->getNamedChild("flattenarea", flattenArea_, false);
42 XMLNode *groundMap = 0;
43 if (node->getNamedChild("groundmap", groundMap, false))
45 if (!groundMap_.initFromNode(base, groundMap)) return false;
48 return true;
51 void PlacementShadowDefinition::updateLandscapeHeight(
52 ScorchedContext &context,
53 FixedVector &position, FixedVector &size)
55 if (flattenArea_ != 0)
57 fixed areaSize = flattenArea_;
58 if (areaSize < 0)
60 areaSize = MAX(size[0], size[1])/2 + 1;
63 DeformLandscape::flattenArea(context, position, false, areaSize);
67 #ifndef S3D_SERVER
69 #include <GLEXT/GLImageModifier.h>
70 void PlacementShadowDefinition::updateLandscapeTexture(
71 bool useShadows,
72 ScorchedContext &context,
73 FixedVector &position, FixedVector &size)
75 if (groundMap_.imageValid())
77 Image *image = ImageStore::instance()->loadImage(groundMap_);
78 ImageModifier::addBitmapToLandscape(
79 context,
80 *image,
81 position[0].asFloat(),
82 position[1].asFloat(),
83 0.25f, 0.25f);
86 if (drawShadow_ && useShadows)
88 ImageModifier::addCircleToLandscape(
89 context,
90 position[0].asFloat(),
91 position[1].asFloat(),
92 MAX(size[0], size[1]).asFloat(), 1.0f);
96 #endif //S3D_SERVER