1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
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.
10 //
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.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
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>
27 
PlacementShadowDefinition()28 PlacementShadowDefinition::PlacementShadowDefinition() :
29 	drawShadow_(true), flattenArea_(0)
30 {
31 }
32 
~PlacementShadowDefinition()33 PlacementShadowDefinition::~PlacementShadowDefinition()
34 {
35 }
36 
readXML(XMLNode * node)37 bool PlacementShadowDefinition::readXML(XMLNode *node)
38 {
39 	node->getNamedChild("drawshadow", drawShadow_, false);
40 	node->getNamedChild("flattenarea", flattenArea_, false);
41 
42 	XMLNode *groundMap = 0;
43 	if (node->getNamedChild("groundmap", groundMap, false))
44 	{
45 		if (!groundMap_.initFromNode(groundMap)) return false;
46 	}
47 
48 	return true;
49 }
50 
updateLandscapeHeight(ScorchedContext & context,FixedVector & position,FixedVector & size)51 void PlacementShadowDefinition::updateLandscapeHeight(
52 	ScorchedContext &context,
53 	FixedVector &position, FixedVector &size)
54 {
55 	if (flattenArea_ != 0)
56 	{
57 		fixed areaSize = flattenArea_;
58 		if (areaSize < 0)
59 		{
60 			areaSize = MAX(size[0], size[1])/2 + 1;
61 		}
62 
63 		DeformLandscape::flattenArea(context, position, false, areaSize);
64 	}
65 }
66 
67 #ifndef S3D_SERVER
68 
69 #include <GLEXT/GLImageModifier.h>
updateLandscapeTexture(bool useShadows,ScorchedContext & context,FixedVector & position,FixedVector & size)70 void PlacementShadowDefinition::updateLandscapeTexture(
71 	bool useShadows,
72 	ScorchedContext &context,
73 	FixedVector &position, FixedVector &size)
74 {
75 	if (!groundMap_.getImageName().empty())
76 	{
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);
84 	}
85 
86 	if (drawShadow_ && useShadows)
87 	{
88 		ImageModifier::addCircleToLandscape(
89 			context,
90 			position[0].asFloat(),
91 			position[1].asFloat(),
92 			MAX(size[0], size[1]).asFloat(), 1.0f);
93 	}
94 }
95 
96 #endif //S3D_SERVER
97