Exemple #1
0
    void updateColor()
    {
        osg::Vec4 osgColor(
            color.redF(),
            color.greenF(),
            color.blueF(),
            color.alphaF());

        text->setColor(osgColor);
    }
Exemple #2
0
void OSGTextNode::setColor(const QColor &color)
{
    osg::Vec4 osgColor(
                color.redF(),
                color.greenF(),
                color.blueF(),
                color.alphaF());
    if (h->text->getColor() != osgColor) {
        h->text->setColor(osgColor);
        emit colorChanged(color);
    }
}
osg::Drawable *ReverseTileNode::createReverseTile(void) const {
    // Get the tile
    ReverseTile* tile = static_cast<ReverseTile*>(_lego);

    // Get tile color
    QColor color = tile->getColor();

    // Get integer sizes
    int width = tile->getWidth();
    int length = tile->getLength();
    int height = 3;

    // Get real position, according to tile size
    double mw = (-width)*Lego::length_unit/2;
    double pw = (width)*Lego::length_unit/2;
    double mwp = (-width+2)*Lego::length_unit/2;
    double ml = (-length)*Lego::length_unit/2;
    double pl = (length)*Lego::length_unit/2;
    double mh = (-height)*Lego::height_unit/2;
    double ph = (height)*Lego::height_unit/2;
    double phm = (height-1)*Lego::height_unit/2;

    // Create 14 vertices
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::Vec3 v0(mw, ml, mh);
    osg::Vec3 v1(mw, pl, mh);
    osg::Vec3 v2(mwp, pl, mh);
    osg::Vec3 v3(mwp, ml, mh);
    osg::Vec3 v4(pw, ml, phm);
    osg::Vec3 v5(pw, pl, phm);
    osg::Vec3 v6(pw, pl, ph);
    osg::Vec3 v7(pw, ml, ph);
    osg::Vec3 v8(mw, ml, ph);
    osg::Vec3 v9(mw, pl, ph);
    osg::Vec3 v10(mwp, ml, phm);
    osg::Vec3 v11(mwp, ml, ph);
    osg::Vec3 v12(mwp, pl, ph);
    osg::Vec3 v13(mwp, pl, phm);

    // Create 10 faces, 8 faces are quads splitted into two triangles
    // NB: Down face is transparent, we don't even create it

    // Front face t1
    vertices->push_back(v4);
    vertices->push_back(v5);
    vertices->push_back(v6);
    // Front face t2
    vertices->push_back(v4);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Back face t1
    vertices->push_back(v0);
    vertices->push_back(v1);
    vertices->push_back(v8);
    // Back face t2
    vertices->push_back(v1);
    vertices->push_back(v8);
    vertices->push_back(v9);

    // Top face t1
    vertices->push_back(v6);
    vertices->push_back(v7);
    vertices->push_back(v9);
    // Top face t2
    vertices->push_back(v7);
    vertices->push_back(v8);
    vertices->push_back(v9);

    // Slop face t1
    vertices->push_back(v2);
    vertices->push_back(v3);
    vertices->push_back(v5);
    // Slop face t2
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v5);

    // Right triangle face
    vertices->push_back(v2);
    vertices->push_back(v13);
    vertices->push_back(v5);

    // Right quad face t1
    vertices->push_back(v13);
    vertices->push_back(v12);
    vertices->push_back(v6);
    // Right quad face t2
    vertices->push_back(v13);
    vertices->push_back(v6);
    vertices->push_back(v5);

    // Right quad face down t1
    vertices->push_back(v1);
    vertices->push_back(v9);
    vertices->push_back(v12);
    // Right quad face down t2
    vertices->push_back(v1);
    vertices->push_back(v2);
    vertices->push_back(v12);

    // Left triangle face
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v10);

    // Left quad face t1
    vertices->push_back(v4);
    vertices->push_back(v10);
    vertices->push_back(v11);
    // Left quad face t2
    vertices->push_back(v4);
    vertices->push_back(v7);
    vertices->push_back(v11);

    // Left quad face down t1
    vertices->push_back(v0);
    vertices->push_back(v3);
    vertices->push_back(v8);
    // Left quad face down t2
    vertices->push_back(v3);
    vertices->push_back(v8);
    vertices->push_back(v11);

    // Create tile geometry
    osg::ref_ptr<osg::Geometry> tileGeometry = new osg::Geometry;

    // Match vertices
    tileGeometry->setVertexArray(vertices);

    // Add color (each rectangle has the same color except for the down one which is transparent)
    osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    // Every face has the same color, so there is only one color
    colors->push_back(osgColor);

    // Match color
    tileGeometry->setColorArray(colors);
    tileGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);

    // Create normals
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, 0, 1));
    normals->push_back(osg::Vec3(0, 0, 1));
    double w = pw - mwp;
    double h = phm - mh;
    double norm = std::sqrt(w*w + h*h);
    normals->push_back(osg::Vec3(h/norm, 0, -w/norm));
    normals->push_back(osg::Vec3(h/norm, 0, -w/norm));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));

    // Match normals
    tileGeometry->setNormalArray(normals);
    tileGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    // Define tile 18 GL_TRIANGLES with 20*3 vertices
    tileGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 18*3));

    // Return the tile whithout plot
    return tileGeometry.release();
}
Exemple #4
0
osg::Drawable *ClampNode::createBrick(void) const {
    // Get the brick
    Clamp* clamp = static_cast<Clamp*>(_lego);
    
    // Get brick color
    QColor color = clamp->getColor();

    // Get clamp bounding box
    clamp->calculateBoundingBox();
    BoundingBox bb = clamp->getBoundingBox();
    // Get integer sizes
    int width = bb.getWidth();
    int length = bb.getLength();
    int height = bb.getHeight();

    // Get real position, according to tile size
    double mw = (-width)*Lego::length_unit/2;
    double mwpm = (-width)*Lego::length_unit/2+Lego::height_unit/2;
    double mwp = (-width)*Lego::length_unit/2+0.93*Lego::height_unit;
    double pw = (width)*Lego::length_unit/2;
    double pwm = (width)*Lego::length_unit/2-Lego::height_unit/2;
    double ml = (-length)*Lego::length_unit/2;
    double mlp = (-length+0.5)*Lego::length_unit/2;
    double pl = (length)*Lego::length_unit/2;
    double plm = (length-0.5)*Lego::length_unit/2;
    double mh = (-height)*Lego::height_unit/2;
    double mhp = (-height)*Lego::height_unit/2+2*Lego::plot_top_height;
    double mhpm = (-height)*Lego::height_unit/2+Lego::plot_top_height;
    double phm = (height)*Lego::height_unit/2-Lego::height_unit/2;
    double phmp = (height)*Lego::height_unit/2-0.5*Lego::height_unit/2;
    
    // Create 3 vertices
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::Vec3 v0(ml, mw, mh);
    osg::Vec3 v1(pl, mw, mh);
    osg::Vec3 v2(pl, pw, mh);
    osg::Vec3 v3(ml, pw, mh);
    osg::Vec3 v4(ml, pw, mhp);
    osg::Vec3 v5(pl, pw, mhp);
    osg::Vec3 v6(pl, mw, mhp);
    osg::Vec3 v7(ml, mw, mhp);
    osg::Vec3 v8(mlp, mw, mhp);
    osg::Vec3 v9(mlp, mw, phm);
    osg::Vec3 v10(ml, mw, phm);
    osg::Vec3 v11(ml, mwp, phmp);
    osg::Vec3 v12(mlp, mwp, phmp);
    osg::Vec3 v13(mlp, pw, mhp);
    osg::Vec3 v14(plm, mw, mhp);
    osg::Vec3 v15(plm, mw, phm);
    osg::Vec3 v16(pl, mw, phm);
    osg::Vec3 v17(pl, mwp, phmp);
    osg::Vec3 v18(plm, mwp, phmp);
    osg::Vec3 v19(plm, pw, mhp);
    osg::Vec3 v20(mlp, mwpm, mh);
    osg::Vec3 v21(plm, mwpm, mh);
    osg::Vec3 v22(plm, pwm, mh);
    osg::Vec3 v23(mlp, pwm, mh);
    osg::Vec3 v24(mlp, mwpm, mhpm);
    osg::Vec3 v25(plm, mwpm, mhpm);
    osg::Vec3 v26(plm, pwm, mhpm);
    osg::Vec3 v27(mlp, pwm, mhpm);
    
    // Create 1 faces, 0 faces are quads splitted into two triangles
    // NB: Down face is transparent, we don't even create it

    // Bottom
    vertices->push_back(v3);
    vertices->push_back(v2);
    vertices->push_back(v1);
    vertices->push_back(v0);
    // Bottom hole
    vertices->push_back(v20);
    vertices->push_back(v21);
    vertices->push_back(v22);
    vertices->push_back(v23);
    // Bottom far
    vertices->push_back(v24);
    vertices->push_back(v25);
    vertices->push_back(v26);
    vertices->push_back(v27);

    // Front face
    vertices->push_back(v2);
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v5);

    // Back face
    vertices->push_back(v0);
    vertices->push_back(v1);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Left bottom face
    vertices->push_back(v0);
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v7);

    // Right bottom face
    vertices->push_back(v1);
    vertices->push_back(v2);
    vertices->push_back(v5);
    vertices->push_back(v6);

    // Top face
    vertices->push_back(v4);
    vertices->push_back(v5);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Left part back
    vertices->push_back(v7);
    vertices->push_back(v8);
    vertices->push_back(v9);
    vertices->push_back(v10);

    // Left part left ext
    vertices->push_back(v4);
    vertices->push_back(v7);
    vertices->push_back(v10);
    vertices->push_back(v11);

    // Left part front
    vertices->push_back(v4);
    vertices->push_back(v11);
    vertices->push_back(v12);
    vertices->push_back(v13);

    // Left part left int
    vertices->push_back(v8);
    vertices->push_back(v9);
    vertices->push_back(v12);
    vertices->push_back(v13);

    // Right part back
    vertices->push_back(v6);
    vertices->push_back(v14);
    vertices->push_back(v15);
    vertices->push_back(v16);

    // Left part left ext
    vertices->push_back(v5);
    vertices->push_back(v6);
    vertices->push_back(v16);
    vertices->push_back(v17);

    // Left part front
    vertices->push_back(v5);
    vertices->push_back(v17);
    vertices->push_back(v18);
    vertices->push_back(v19);

    // Left part left int
    vertices->push_back(v14);
    vertices->push_back(v15);
    vertices->push_back(v18);
    vertices->push_back(v19);

    // Bottom front
    vertices->push_back(v20);
    vertices->push_back(v21);
    vertices->push_back(v25);
    vertices->push_back(v24);

    // Bottom right
    vertices->push_back(v21);
    vertices->push_back(v22);
    vertices->push_back(v26);
    vertices->push_back(v25);

    // Bottom back
    vertices->push_back(v22);
    vertices->push_back(v23);
    vertices->push_back(v27);
    vertices->push_back(v26);

    // Bottom left
    vertices->push_back(v23);
    vertices->push_back(v20);
    vertices->push_back(v24);
    vertices->push_back(v27);

    // Create tile geometry
    osg::ref_ptr<osg::Geometry> clampGeometry = new osg::Geometry;
    
    // Match vertices
    clampGeometry->setVertexArray(vertices);
    
    // Create colors
    osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    // Every face has the same color, so there is only one color
    colors->push_back(osgColor);
    
    // Match color
    clampGeometry->setColorArray(colors);
    clampGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
    
    // Create normals
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(0, 0, -1));
    normals->push_back(osg::Vec3(0, 0, -1));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, 0, 1));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    double w = pw - mwp;
    double h = phmp - mhp;
    double norm = std::sqrt(w*w + h*h);
    normals->push_back(osg::Vec3(0, h/norm, w/norm));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, h/norm, w/norm));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    
    // Match normals
    clampGeometry->setNormalArray(normals);
    clampGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    // Define 1 GL_QUADS with 1*4 vertices, corresponding to bottom part
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0*4, 4));

    // Define 1 GL_QUADS with 1*4 vertices, corresponding to 1 hole in bottom part
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 1*4, 4));

    // Retesslate to create hole
    osgUtil::Tessellator tesslator;
    tesslator.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
    tesslator.setWindingType(osgUtil::Tessellator::TESS_WINDING_ODD);
    tesslator.retessellatePolygons(*clampGeometry);

    // Create 17 GL_QUADS, i.e. 18*4 vertices
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 2*4, 18*4));

    // Return the tile whithout plot
    return clampGeometry.release();
}