以线框的方式画一个节点的最小BoundingBox

以线框的方式画一个节点的最小BoundingBox

void BoxLine::Set(osg::BoundingBox &box)

{

     float lengthX=box.xMax()-box.xMin();

     float lengthY=box.yMax()-box.yMin();

     float lengthZ=box.zMax()-box.zMin();

     osg::Vec3 center((box.xMax()+box.xMin())/2,(box.yMax()+box.yMin())/2,(box.zMax()+box.zMin())/2);

 

     osg::ShapeDrawable *sd=new osg::ShapeDrawable(new osg::Box(center,lengthX,lengthY,lengthZ));

 

     osg::Vec3Array *colors=new osg::Vec3Array;

    

     sd->setColor(osg::Vec4(1,0,0,1));

 

     osg::StateSet *state=sd->getOrCreateStateSet();

     osg::PolygonMode* pm = new osg::PolygonMode(

         osg::PolygonMode::FRONT_AND_BACK,

         osg::PolygonMode::LINE );

     state->setAttributeAndModes( pm );

     // 同时还设置线宽为。

     osg::LineWidth* lw = new osg::LineWidth( 3.f );

     state->setAttribute( lw );

     osg::Geode *geode=new osg::Geode;

     geode->addDrawable(sd);

     this->addChild(geode);

}

 

你可能感兴趣的:(float,colors)