A complete simulation lifting process, the initial state -> arm from -> down sling -> vertical lifting -> horizontal rotation -> lowering an object -> contraction sling.
osg::ref_ptr<osg::Node> createSimple() { osg::ref_ptr<osg::Geode> geode = new osg::Geode; osg::ref_ptr<osg::Geometry> geo = new osg::Geometry; //申请一些顶点 osg::ref_ptr<osg::Vec3Array> vers = new osg::Vec3Array; geo->setVertexArray(vers.get()); #if 1 geo->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, 4));//创建一个线圈 #else geo->addPrimitiveSet(new:: DrawArrays OSG (OSG :: :: Quads primitives -, 0 , . 4 )); // Create a square #endif // provided vertex Vers> push_back (OSG :: Vec3 (- 15 , 3.0 , - 15 )); Vers -> push_back (OSG :: Vec3 ( 15 , 3.0 , - 15 )); Vers -> push_back (OSG :: Vec3 ( 15 , 3.0 , 15 )); Vers -> push_back (OSG :: Vec3 (- 15 , 3.0 , 15 )); // application color osg::ref_ptr<osg::Vec4Array> color = new osg::Vec4Array(); color->push_back(osg::Vec4(1.0, 0.0, 0.0, 0.5)); color->push_back(osg::Vec4(0.0, 1.0, 0.0, 0.5)); color->push_back(osg::Vec4(0.0, 0.0, 1.0, 0.5)); color->push_back(osg::Vec4(1.0, 1.0, 0.0, 0.5)); //Set the color Geo-> setColorArray (Color. GET ()); GEO -> setColorBinding (OSG the Geometry :: :: :: AttributeBinding BIND_PER_VERTEX); // set the color bind // set the normal, for the time being the brightest screen :: ref_ptr OSG <OSG :: Vec3Array is> NORM = new new OSG Vec3Array is ::; GEO -> setNormalArray (NORM); GEO -> setNormalBinding (OSG AttributeBinding :: :: :: BIND_OVERALL the Geometry); NORM -> push_back (OSG: : Vec3 ( 0.0 , - 1.0 , 0.0 )); // open transparency Geo> getOrCreateStateSet () -> the setMode (GL_BLEND, OSG :: :: StateAttribute the ON); //设置线宽 osg::ref_ptr<osg::LineWidth> w = new osg::LineWidth; w->setWidth(5.0); geo->getOrCreateStateSet()->setAttributeAndModes(w.get(), osg::StateAttribute::ON); geode->addDrawable(geo.get()); return geode; }
//代码参考:https://blog.csdn.net/wb175208/article/details/80513775