void AreaShader::shadeArea(Surface& s, const Area* ar) const { WFMath::Polygon<2> clipped = ar->clipToSegment(s.m_segment); assert(clipped.isValid()); if (clipped.numCorners() == 0) return; Point2 segOrigin = s.m_segment.getRect().lowCorner(); clipped.shift(Point2(0,0) - segOrigin); scanConvert(clipped, s); }
bool TerrainArea::parseArea() { if (!mEntity.hasAttr("area")) { S_LOG_FAILURE("TerrainArea created for entity with no area attribute"); return false; } const Atlas::Message::Element areaElem(mEntity.valueOfAttr("area")); if (!areaElem.isMap()) { S_LOG_FAILURE("TerrainArea element ('area') must be of map type."); return false; } const Atlas::Message::MapType& areaData(areaElem.asMap()); int layer = 0; WFMath::Polygon<2> poly; TerrainAreaParser parser; if (parser.parseArea(areaData, poly, layer)) { if (!mArea) { mArea = new Mercator::Area(layer, false); } else { //A bit of an ugly hack here since the Mercator system doesn't support changing the layer. We need to swap the old area for a new one if the layer has changed. if (mArea->getLayer() != layer) { mOldArea = mArea; mArea = new Mercator::Area(layer, false); } } // transform polygon into terrain coords WFMath::Vector<3> xVec = WFMath::Vector<3>(1.0, 0.0, 0.0).rotate(mEntity.getOrientation()); double theta = atan2(xVec.y(), xVec.x()); // rotation about Z WFMath::RotMatrix<2> rm; poly.rotatePoint(rm.rotation(theta), WFMath::Point<2>(0, 0)); poly.shift(WFMath::Vector<2>(mEntity.getPosition().x(), mEntity.getPosition().y())); mArea->setShape(poly); return true; } else { return false; } }
bool TerrainArea::placeArea(WFMath::Polygon<2>& poly) { //If the position if invalid we can't do anything with the area yet. if (!mEntity.getPosition().isValid()) { return false; } // transform polygon into terrain coords if (mEntity.getOrientation().isValid()) { WFMath::Vector<3> xVec = WFMath::Vector<3>(1.0, 0.0, 0.0).rotate(mEntity.getOrientation()); double theta = atan2(xVec.y(), xVec.x()); // rotation about Z WFMath::RotMatrix<2> rm; poly.rotatePoint(rm.rotation(theta), WFMath::Point<2>(0, 0)); } poly.shift(WFMath::Vector<2>(mEntity.getPosition().x(), mEntity.getPosition().y())); return true; }