Ejemplo n.º 1
0
void
Model::normalize(const Vector3f& centerOffset)
{
    AlignedBox<float, 3> bbox;

    for (vector<Mesh*>::const_iterator iter = meshes.begin(); iter != meshes.end(); iter++)
        bbox.extend((*iter)->getBoundingBox());

    Vector3f center = (bbox.min() + bbox.max()) * 0.5f + centerOffset;
    Vector3f extents = bbox.max() - bbox.min();
    float maxExtent = extents.maxCoeff();

    transform(-center, 2.0f / maxExtent);

    normalized = true;
}
Ejemplo n.º 2
0
void
VectorMapLayer::renderTile(RenderContext& rc, const WorldGeometry* /* world */, const QuadtreeTile* tile) const
{
#ifndef VESTA_OGLES2
    rc.setVertexInfo(VertexSpec::PositionColor);

    Material simpleMaterial;
    simpleMaterial.setDiffuse(Spectrum(1.0f, 1.0f, 1.0f));
    simpleMaterial.setOpacity(1.0f);
    rc.bindMaterial(&simpleMaterial);

    float tileArc = float(PI) * tile->extent();
    Vector2f southwest = tile->southwest();

    SpherePatch box;
    box.west = float(PI) * southwest.x();
    box.east = box.west + tileArc;
    box.south = float(PI) * southwest.y();
    box.north = box.south + tileArc;

    AlignedBox<float, 2> bounds(Vector2f(box.west, box.south), Vector2f(box.east, box.north));

    for (vector<counted_ptr<MapElement> >::const_iterator iter = m_elements.begin(); iter != m_elements.end(); ++iter)
    {
        const MapElement* element = iter->ptr();
        bool tileContainsElement = false;

        if (element)
        {
            AlignedBox<float, 2> elementBox = element->bounds();
            if (!elementBox.isNull())
            {
                if (elementBox.min().x() < bounds.max().x() &&
                    elementBox.max().x() > bounds.min().x() &&
                    elementBox.min().y() < bounds.max().y() &&
                    elementBox.max().y() > bounds.min().y())
                {
                    tileContainsElement = true;
                }
            }
        }

        if (tileContainsElement)
        {
            Spectrum color = element->color();
            glColor4f(color.red(), color.green(), color.blue(), element->opacity());

            if (element->opacity() < 1.0f)
            {
                glEnable(GL_BLEND);
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            }
            else
            {
                glDisable(GL_BLEND);
            }

            element->render(box.west, box.south, box.east, box.north);
        }
    }

    glDisable(GL_BLEND);
#endif
}