Visual Studio 2012 Update 3, Windows 7.
#include "pch.h"
#include "area_outline_node.hpp"
#include <lgs/foreach.hpp>
#include "hex.hpp"
#include <lgs/renderer.hpp>
#include "faction.hpp"
#include "alliance.hpp"
#include "neighbor_graph.hpp"
#include <lgs/graph/bfs_search.hpp>
#include <lgs/opengl/geometry.hpp>
#include "hex_functions.hpp"
#include <lgs/opengl/opengl.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/adapted/c_array.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/register/point.hpp>
using namespace boost::geometry;
BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET(Vec2i, int, cs::cartesian, x, y, setX, setY);
namespace
{
int points[][2] = {{16, 0}, {60,0}, {76,32}, {60, 64}, {16, 64}, {0, 32}};
typedef Vec2i Point;
typedef model::polygon<Point, false> Poly;
typedef strategy::transform::translate_transformer<Point, Point> Translate; <<<< error here
Poly hexPoly;
struct FactionBorderHex
{
FactionBorderHex(Faction& faction) : faction_(&faction) {}
bool operator()(const Hex* hex) const
{
return hex->faction() == faction_ && IsFactionBorderHex()(hex);
}
Faction* faction_;
};
}
AreaOutlineNode::AreaOutlineNode()
{
if (hexPoly.outer().empty())
{
append(hexPoly, points);
correct(hexPoly);
}
}
void AreaOutlineNode::setFaction(Faction* faction)
{
if (faction_ != faction)
{
faction_ = faction;
meshes_.clear();
if (faction_)
{
setArea(faction_->hexes());
}
}
}
void AreaOutlineNode::setArea(const Lgs::Vector<Hex*>& area)
{
boost::unordered_set<Hex*> factionBorder = faction_->getBorder();
std::vector<Vec2f> verts;
while (!factionBorder.empty())
{
Lgs::Vector<Hex*> border = floodFill(*factionBorder.begin(), HexNeighborGraph(), FactionBorderHex(*faction_));
Poly polySum;
foreach (Hex* hex, border)
{
factionBorder.erase(hex);
Vec2i pos = pixelPosition(*hex);
Poly poly;
transform(hexPoly, poly, Translate(pos.x(), pos.y()));
std::vector<Poly> multiSum;
union_(polySum, poly, multiSum);
polySum = multiSum.front();
}
verts.assign(polySum.outer().begin(), polySum.outer().end());
meshes_.emplace_back(new Lgs::Geometry(Lgs::GeometryType::LineStrip));
meshes_.back()->setVertices(&verts.front(), verts.size());
meshes_.back()->setColors(&faction_->alliance()->borderColor(), 1);
}
}
void AreaOutlineNode::doRender(Renderer& r, const Recti& cullRect) const
{
if (faction_)
{
foreach (const boost::shared_ptr<Lgs::Geometry>& mesh, meshes_)
{
//r.drawMesh(mesh);
mesh->draw();
}
}
}
Sizei AreaOutlineNode::size() const
{
//FIXME: proper size based on envelope()
return Sizei(10000, 10000);
}