Beispiel #1
0
LineDrawable* makeStar(double x, double y, double r)
{
    LineDrawable* star = new LineDrawable(GL_LINES);
    for(float i=0.0f; i<osg::PI*2.0; i += osg::PI/16.0)
    {
        float c = cos(i), s = sin(i);
        star->pushVertex(osg::Vec3(x, 0, y));
        star->pushVertex(osg::Vec3(x+(r*c-r*s), 0, y+(r*c+r*s)));
    }
    star->finish();
    return star;
}
    void operator()(osg::Node* node, osg::NodeVisitor* nv)
    {
        if (nv->getFrameStamp()->getFrameNumber() % 20 == 0)
        {
            LineDrawable* line = (LineDrawable*)node;

            unsigned total = line->getNumVerts();
            unsigned first = line->getFirst();
        
            line->setFirst( (first+1) % total );
            line->setCount( 3 );
        }
    }
Beispiel #3
0
void
Clamping::setHeights(osg::Geometry* geom, osg::FloatArray* hats)
{
    if ( geom )
    {
        hats->setBinding(osg::Array::BIND_PER_VERTEX);
        hats->setNormalize(false);

        LineDrawable* line = dynamic_cast<LineDrawable*>(geom);
        if (line)
        {
            line->importVertexAttribArray(HeightsAttrLocation, hats);
        }
        else
        {
            geom->setVertexAttribArray(HeightsAttrLocation, hats);
        }
    }
}
    void addBuoyancyTest(osg::Node* model)
    {
        //labels = new AnnotationLayer();
        //map->addLayer(labels);

        normals = new AnnotationLayer();
        map->addLayer(normals);

        // geometry for a unit normal vector
        normalDrawable = new LineDrawable(GL_LINES);
        normalDrawable->setColor(osg::Vec4(1,1,0,1));
        normalDrawable->pushVertex(osg::Vec3(0,0,0));
        normalDrawable->pushVertex(osg::Vec3(0,0,10));
        normalDrawable->pushVertex(osg::Vec3(-2,0,0.5));
        normalDrawable->pushVertex(osg::Vec3(2,0,0.5));
        normalDrawable->pushVertex(osg::Vec3(0,-2,0.5));
        normalDrawable->pushVertex(osg::Vec3(0,2,0.5));
        normalDrawable->finish();

        // a single shared anchor point for the intersection set:
        isect->setAnchor(anchor);

        // generate a bunch of local points around the anchor:
        for(int x=-50; x<=50; x+=25)
        {
            for(int y=-50; y<=50; y+=25)
            {
                isect->addLocalPoint(osg::Vec3d(x, y, 0));

                // a label communicating the wave height:
                //PlaceNode* label = new PlaceNode();
                //label->setDynamic(true);
                //label->setPosition(anchor);
                //label->setIconImage(image);
                //label->setText("-");
                //labels->getGroup()->addChild(label);

                // a normal vector and optional model:
                GeoPositionNode* normal = new GeoPositionNode();
                normal->setDynamic(true);
                normal->getPositionAttitudeTransform()->addChild(normalDrawable);
                if (model)
                    normal->getPositionAttitudeTransform()->addChild(model);
                normal->setPosition(anchor);
                normals->getGroup()->addChild(normal);
            }
        }

        //ScreenSpaceLayout::setDeclutteringEnabled(false);
    }
osg::Node* createLineDrawables()
{
    LineGroup* group = new LineGroup();

    group->addCullCallback(new InstallViewportSizeUniform());

    float x = 10;
    LineDrawable* strip = new LineDrawable(GL_LINE_STRIP);
    strip->setLineWidth(8);
    strip->setColor(osg::Vec4(1,1,1,1));
    addVerts(strip, x, 10);
    group->addChild(strip);

    x += 20;
    LineDrawable* loop = new LineDrawable(GL_LINE_LOOP);
    loop->setLineWidth(8);
    loop->setColor(osg::Vec4(1,1,0,1));
    addVerts(loop, x, 10);
    group->addChild(loop);

    x += 20;
    LineDrawable* stippled = new LineDrawable(GL_LINE_STRIP);
    stippled->setLineWidth(4);
    stippled->setStipplePattern(0xff00);
    stippled->setColor(osg::Vec4(0,1,0,1));
    addVerts(stippled, x, 10);
    group->addChild(stippled);
    
    x += 20;
    LineDrawable* segments = new LineDrawable(GL_LINES);
    segments->setLineWidth(3);
    segments->setColor(osg::Vec4(0,1,1,1));
    addVerts(segments, x, 10);
    group->addChild(segments);

    x += 20;
    LineDrawable* firstCount = new LineDrawable(GL_LINE_STRIP);
    firstCount->setLineWidth(5);
    firstCount->setColor(osg::Vec4(1,0,1,1));
    addVerts(firstCount, x, 10);
    firstCount->addUpdateCallback(new TestFirstCount());
    group->addChild(firstCount);
    
    x += 20;
    osg::ref_ptr<osg::Node> node = makeGeometryForImport(x, 10);
    group->import(node.get());

    return group;
}
Beispiel #6
0
osg::Node* createDrawables()
{
    // You need a viewport uniform for the lines to work.
    // MapNode installs one automatically, but we're not using MapNode
    // in this example.
    osg::Group* group = new osg::Group();
    group->addCullCallback(new InstallViewportSizeUniform());

    float x = 10;
    float y = 10;

    LineDrawable* strip = new LineDrawable(GL_LINE_STRIP);
    strip->setLineWidth(8);
    strip->setColor(osg::Vec4(1,1,1,1));
    addVerts(strip, x, y);
    group->addChild(strip);

    x += 20;
    LineDrawable* loop = new LineDrawable(GL_LINE_LOOP);
    loop->setLineWidth(1);
    loop->setColor(osg::Vec4(1,1,0,1));
    addVerts(loop, x, y);
    group->addChild(loop);

    x += 20;
    LineDrawable* stippled = new LineDrawable(GL_LINE_STRIP);
    stippled->setLineWidth(4);
    stippled->setStipplePattern(0xff00);
    stippled->setColor(osg::Vec4(0,1,0,1));
    addVerts(stippled, x, y);
    group->addChild(stippled);
    
    x += 20;
    LineDrawable* segments = new LineDrawable(GL_LINES);
    segments->setLineWidth(3);
    segments->setColor(osg::Vec4(0,1,1,1));
    addVerts(segments, x, y);
    group->addChild(segments);

    x += 20;
    LineDrawable* firstCount = new LineDrawable(GL_LINE_STRIP);
    firstCount->setLineWidth(5);
    firstCount->setColor(osg::Vec4(1,0,1,1));
    addVerts(firstCount, x, y);
    firstCount->addUpdateCallback(new TestFirstCount());
    group->addChild(firstCount);
    
    x += 20;
    osg::ref_ptr<osg::Node> node = makeGeometryForImport(x, y);
    LineGroup* lines = new LineGroup();
    lines->import(node.get());
    group->addChild(lines);

    x += 20;
    LineDrawable* points = new LineDrawable(GL_POINTS);
    addVerts(points, x, y);
    group->addChild(points);

    x = 20;
    y -= 20;
    for(unsigned i=0; i<10; ++i)
    {
        LineDrawable* across = new LineDrawable(GL_LINES);
        across->pushVertex(osg::Vec3(x, 0, y));
        across->pushVertex(osg::Vec3(x+100, 0, y));
        across->setLineWidth((float)(i+1));
        across->finish();
        group->addChild(across);
        y -= (i+2);
    }

    x = 20;
    y -= 20;
    LineDrawable* star = makeStar(x, y, 10);
    star->setColor(osg::Vec4(1,1,1,1));
    star->setLineWidth(1.0f);
    group->addChild(star);

    x += 40;
    LineDrawable* star2 = makeStar(x, y, 10);
    star2->setColor(osg::Vec4(1,.5,0,1));
    star2->setLineWidth(2.0f);
    group->addChild(star2);

    x += 40;
    LineDrawable* star3 = makeStar(x, y, 10);
    star3->setColor(osg::Vec4(1,1,0,1));
    star3->setLineWidth(3.0f);
    group->addChild(star3);

    y -= 40;
    x = 20;
    PointDrawable* grid = makeGridOfPoints(x, y);
    grid->setPointSize(3.0f);
    grid->setColor(osg::Vec4(0,1,1,1));
    group->addChild(grid);

    x += 50;
    PointDrawable* grid2 = makeGridOfPoints(x, y);
    grid2->setPointSize(20.0f);
    GLUtils::setPointSmooth(grid2->getOrCreateStateSet(), 1);
    group->addChild(grid2);

    return group;
}