osg create shape

osg::ref_ptr<osg::Node> OSG_Qt_::createSimple()
{
    osg::ref_ptr<osg::Geode> geode = new osg::Geode;
    osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;

    // Application vertex 
    osg :: ref_ptr <osg :: Vec3Array is> = the coords new new osg :: Vec3Array is;
     // apply color 
    osg :: ref_ptr <osg :: Vec4Array> Colors = new new osg :: Vec4Array;
     // Application normal vector 
    osg ref_ptr :: <OSG :: Vec3Array is> = Norms new new OSG Vec3Array is ::;

    // Set the vertex associated manner 
    geometry-> addPrimitiveSet ( new new OSG :: DrawArrays (OSG primitives - :: :: :: Quads Mode, 0 , . 4 ));

    coords->push_back(osg::Vec3(-10.0,0.0,-10.0));
    coords->push_back(osg::Vec3(10.0, 0.0, -10.0));
    coords->push_back(osg::Vec3(10.0, 0.0, 10.0));
    coords->push_back(osg::Vec3(-10.0, 0.0, 10.0));

    // color assignment 
    colors-> push_back (OSG :: Vec4f ( 1.0 , 0.0 , 0.0 , 1.0 ));
    colors->push_back(osg::Vec4f(0.0, 1.0, 0.0, 1.0));
    colors->push_back(osg::Vec4f(0.0, 0.0, 1.0, 1.0));
    colors->push_back(osg::Vec4f(1.0, 1.0, 0.0, 1.0));

    // normal vector assignment 
    norms-> push_back (OSG :: Vec3 ( 0.0 , - 1.0 , 0.0 ));


    // Set the vertex 
    geometry-> setVertexArray (the coords. GET ());
     // set the color 
    geometry-> setColorArray (Colors. GET ());
     // color bindings embodiment 
    geometry-> setColorBinding (OSG :: :: AttributeBinding the Geometry BIND_PER_VERTEX ::);
     // set the normal vector 
    geometry-> setNormalArray (Norms. GET ());
     // normals binding 
    geometry-> setNormalBinding (OSG the Geometry :: :: :: AttributeBinding BIND_OVERALL);

    geode->addDrawable(geometry.get());
    return geode;
}

 

Guess you like

Origin www.cnblogs.com/herd/p/11073983.html