|
楼主 |
发表于 2013-3-26 15:44:09
|
显示全部楼层
本帖最后由 1162810317 于 2013-3-26 16:28 编辑
liuzhiyu123 发表于 2013-3-26 09:34
这个createBillboardTree(image.get()) 是可以共享的,遮挡的那个 不知道您设置的对不对,应该是从远到近的 ...
谢谢,我试试!
呃,,大神我不清楚您说的从远到近是渲染方式具体是设置哪个?我知道有先后渲染,,但没看到您说的远近,,,您能不能说详细点?谢谢!
osg::ref_ptr<osg::Node>createBillboardTree(osg::ref_ptr<osg::Image> image,osg::Vec3 position)
{ //创建四边形
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
//设置顶点
osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
v->push_back(osg::Vec3(-50.0f, 0.0f, -50.0f)); //0.5
v->push_back(osg::Vec3(50.0f, 0.0f, -50.0f));
v->push_back(osg::Vec3(50.0f, 0.0f, 50.0f));
v->push_back(osg::Vec3(-50.0f, 0.0f, 50.0f));
geometry->setVertexArray(v.get());
//设置法线
osg::ref_ptr<osg::Vec3Array> normal = new osg::Vec3Array;
normal->push_back(osg::Vec3(1.0f, 0.0f, 0.0f)
^ osg::Vec3(0.0f, 0.0f, 1.0f));
geometry->setNormalArray(normal.get());
geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
//设置纹理坐标
osg::ref_ptr<osg::Vec2Array> vt = new osg::Vec2Array;
vt->push_back(osg::Vec2(0.0f, 0.0f));
vt->push_back(osg::Vec2(1.0f, 0.0f));
vt->push_back(osg::Vec2(1.0f, 1.0f));
vt->push_back(osg::Vec2(0.0f, 1.0f));
geometry->setTexCoordArray(0, vt.get());
//绘制四边形
geometry->addPrimitiveSet(new osg:rawArrays(osg:rimitiveSet:UADS, 0, 4));
if (image.get())
{
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
//关联image
texture->setImage(image.get());
//关联Texture2D纹理对象,第三个参数默认为ON
stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
//启用混合
stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
//关闭光照
stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
geometry->setStateSet(stateset.get());
}
//创建Billboard对象
osg::ref_ptr<osg::Billboard> billboard1 = new osg::Billboard;
//设置旋转模式
billboard1->setMode(osg::Billboard::AXIAL_ROT );
billboard1->setAxis (osg::Vec3(0,0,1));
//添加Drawable,并设置其位置,默认位置为osg::Vec3(5.0f, 0.0f, 0.0f)
billboard1->addDrawable(geometry.get(), position);
return billboard1.get();
} |
|