Hi 
     When i run my  project exe int vs2005,that's ok, But when i run  outer 
it's not 
  correct! I function is render a scale a graphics  boudary_width and   
graphics  ..
   
   
   osg::Group * createGraph(osg::Vec3Array* points,osg::Vec4Array* 
graph_color,osg::Vec4Array* boudary_color,int boudary_width,std::string _name)
 {
  osg::Group* trans = new osg::Group;
  osg::MatrixTransform* trans_scale = new osg::MatrixTransform;
    osg::Geode * graph = new osg::Geode; 
    graph->setName(_name + "inter");
  osg::Geode * graph_scale = new osg::Geode; 
  graph_scale->setName(_name + "outer");
    //得到所有点的x,y轴的包围盒
  float x_min=0,x_max=0,y_min=0,y_max=0; 
  x_min = x_max = points->operator [](0).x(); 
  y_min = y_max = points->operator [](0).y(); 
  for (int i=1;i<points->size();++i)
  {
   if ((points->operator [](i).x())<x_min)
    x_min = points->operator [](i).x();
   if ((points->operator [](i).x())>x_max)
    x_max = points->operator [](i).x();
   if ((points->operator [](i).y())<y_min)
    y_min = points->operator [](i).y();
   if ((points->operator [](i).y())>y_max)
    y_max = points->operator [](i).y();
  }
  //中心点
  double x_mid = (x_min+x_max)/2; 
  double y_mid = (y_min+y_max)/2;
    //得到要伸缩的比例
  double x_scale = 1+2*boudary_width/(x_max-x_min);
  double y_scale = 1+2*boudary_width/(y_max-y_min);
  
  //设置变换矩阵
  osg::Matrix matrix_scale;
  osg::Matrix matrix_trans; 
  osg::Matrix matrix_trans1; 
    matrix_scale.makeScale(osg::Vec3(x_scale,y_scale,1));
  matrix_trans.makeTranslate(-x_mid,-y_mid,0);
    matrix_trans1.makeTranslate(x_mid,y_mid,0);
    //生成几何节点 osg::Geode* graph = new osg::Geode();   
    {
   //生成新的几何节点
   osg::Geometry* geometry = new osg::Geometry(); 
   //geometry->setName("geometry" );
   osg::Geometry* geometry_scale = new osg::Geometry(); 
   //geometry_scale->setName("geometry_scale");
     //设置节点的顶点 
   geometry->setVertexArray(points); 
   geometry_scale->setVertexArray(points);
     // 设置几何面的颜色
   geometry->setColorArray(graph_color);
   geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
   geometry_scale->setColorArray(boudary_color);
   geometry_scale->setColorBinding(osg::Geometry::BIND_OVERALL);
  
   // 添加绘制的几何
   geometry->addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,points->size()));
   geometry_scale->addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,points->size()));
     
   
   // Setup  blending
   geometry->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
     osg::BlendFunc *fn = new osg::BlendFunc();
   fn->setFunction(osg::BlendFunc::SRC_ALPHA, 
osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
   
   geometry->getOrCreateStateSet()->setAttributeAndModes(fn, 
osg::StateAttribute::ON);
     geometry_scale->getOrCreateStateSet()->setAttributeAndModes(fn, 
osg::StateAttribute::ON);
  
   //设置透明属性 --透明开关打开
   
   
geometry->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
     
geometry_scale->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
     
   //添加到节点
     graph_scale->addDrawable(geometry_scale);
     trans_scale->addChild(graph_scale); 
     osg::Matrix t = matrix_trans*matrix_scale*matrix_trans1;
   trans_scale->setMatrix(t);
  
   graph->addDrawable(geometry);
     trans->addChild(graph); 
     trans->addChild(trans_scale); 
  
  }
    return trans; 
 }
   
  Best regards. YangXiao.

       
---------------------------------
 雅虎邮箱,您的终生邮箱!
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to