|
各位,我在OSGEarth里面用Billboard显示图片,可是图片并不能始终朝向屏幕,有遇到相同问题的吗?
场景节点结构 根节点下包含MapNode和 Billboard节点,也就是Billboard并不在MapNode节点下;
部分代码如下:
osg::Billboard * pBillboard = new osg::Billboard();
pBillboard->setNormal(osg::Vec3f(0,0,1));
osg::Geometry * pRect = new osg::Geometry;
osg::Vec3Array * pVertArr = new osg::Vec3Array();
pVertArr->push_back(osg::Vec3(-0.5f,-0.5f,0.0f));
pVertArr->push_back(osg::Vec3(0.5f,-0.5f,0.0f));
pVertArr->push_back(osg::Vec3(0.5f,0.5f,0.0f));
pVertArr->push_back(osg::Vec3(-0.5f,0.5f,0.0f));
pRect->setVertexArray(pVertArr);
osg::Vec3Array * pNormArr = new osg::Vec3Array();
pNormArr->push_back(osg::Vec3f(0,0,1));
pRect->setNormalArray(pNormArr);
pRect->setNormalBinding(osg::Geometry::BIND_OVERALL);
osg::Vec2Array * pCoordArr = new osg::Vec2Array();
pCoordArr->push_back(osg::Vec2(0.0f,0.0f));
pCoordArr->push_back(osg::Vec2(1.0f,0.0f));
pCoordArr->push_back(osg::Vec2(1.0f,1.0f));
pCoordArr->push_back(osg::Vec2(0.0f,1.0f));
pRect->setTexCoordArray(0,pCoordArr);
pRect->addPrimitiveSet(new osg:rawArrays(GL_QUADS,0,4));
pBillboard->addDrawable(pRect);
osg::Texture2D * pTex2d = new osg::Texture2D;
pTex2d->setFilter(osg::Texture::MIN_FILTER,osg::Texture::NEAREST);
pTex2d->setFilter(osg::Texture::MAG_FILTER,osg::Texture::NEAREST);
pTex2d->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_BORDER);
pTex2d->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_BORDER);
//pTex2d->setBorderColor(osg::Vec4f(0.6f,0.6f,0.6f,1));
//pTex2d->setBorderWidth(2);
pTex2d->setResizeNonPowerOfTwoHint(false);
pTex2d->setImage(m_pTexImage);
pBillboard->getOrCreateStateSet()->setTextureAttributeAndModes(0,pTex2d);
pBillboard->getOrCreateStateSet()->setTextureAttribute(0,new osg::TexEnv(osg::TexEnv::REPLACE));
pBillboard->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
m_pTexMatrix = new osg::TexMat();
m_pTexMatrix->setMatrix(osg::Matrixd::identity());
pBillboard->getOrCreateStateSet()->setTextureAttributeAndModes(0,m_pTexMatrix);
pBillboard->setMode(osg::Billboard:OINT_ROT_EYE);
return pBillboard; |
|