|
本帖最后由 starmessage 于 2012-9-26 21:55 编辑
仿3DMax旋转球做的,扇形什么的实现后,发现问题,透明旋转球从某个角度看时,遮挡住了扇形与文字,该怎么弄,我设置了这个,也不行,请高人指点下。
如图:
扇形被球体挡住了,并且文字XYZ也被挡住了
换个角度,扇形显示
换个角度,文字XYZ才显示
明显是球的问题,但是我透明度设置了,底下的这个也设置了,可还是被挡住了,怎么解决呢?
代码对于旋转球和文字扇形都设置了这个属性,透明度,光照属性就不概述了。
getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
现在贴上代码,希望各位帮帮忙。到底怎么回事
粘贴上简单的代码,看看有没有人能够帮帮我。
osg::Geode* createSphere()
{
osg::Geode* sphereGeode = new osg::Geode;
osg::ShapeDrawable* sphereShapeDrawable=new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),0.9f));
sphereShapeDrawable->setColor(osg::Vec4(1.0f,1.0f,0.0f,0.1f));
sphereGeode->addDrawable(sphereShapeDrawable);
sphereGeode->getOrCreateStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON);
sphereGeode->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
return sphereGeode;
}
osg::Geode* createLoop()
{
osg::Geode* loopGeode=new osg::Geode;
int angleNum=(int)(235/1.0);
const float angleDelta = 1*2.0f*osg:I/(float)360;
const float r =0.98f;
osg::Vec3 _vFirPoint(1.0f,1.0f,0.0f);
osg::Vec3 _vCenter(0.0f,0.0f,0.0f);
if (abs(_vFirPoint.x())>0.99) _vFirPoint[0]=_vFirPoint.x()/abs(_vFirPoint.x())*0.90;
if (abs(_vFirPoint.y())>0.99) _vFirPoint[1]=_vFirPoint.y()/abs(_vFirPoint.y())*0.90;
float angle = 2*asin(abs(sqrt((_vFirPoint.x()-r)*(_vFirPoint.x()-r)+_vFirPoint.y()*_vFirPoint.y()))/r/2.0f);
if(_vFirPoint.y()<0) angle=2*osg::PI-angle;
osg::Vec3Array* vertexArray = new osg::Vec3Array(angleNum+2);
osg::Vec3Array* normalArray = new osg::Vec3Array(angleNum+2);
osg::Vec4Array* colorArray=new osg::Vec4Array(1);
(*colorArray)[0].set(1.0f,1.0f,0.0f,0.2f);
(*vertexArray)[0].set(_vCenter);
(*vertexArray)[0].set(0.0f,0.0f,0.0f);
for(unsigned int i = 1; i < angleNum+2; ++i,angle+=angleDelta)
{
float c = cosf(angle);
float s = sinf(angle);
(*vertexArray).set(c*r,s*r,0.0f);
(*normalArray).set(c,s,1.0f);
}
osg::Geometry* geometry = new osg::Geometry();
geometry->setVertexArray(vertexArray);
geometry->setNormalArray(normalArray);
geometry->setColorArray(colorArray);
geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
geometry->addPrimitiveSet(new osg:rawArrays(osg::PrimitiveSet::TRIANGLE_FAN,0,vertexArray->size()));
loopGeode->addDrawable(geometry);
loopGeode->getOrCreateStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON);
loopGeode->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
return loopGeode;
}
int _tmain(int argc, _TCHAR* argv[])
{
osg::ref_ptr<osg::Group> root = new osg::Group;
osgViewer::Viewer viewer;
root->addChild(createLoop());
root->addChild(createSphere());
viewer.setSceneData(root.get());
return viewer.run();
}
调整加入的结点的顺序一样使不能解决。但是加入box等对象,可以透过去了,是不是loop法线等的问题,希望可以解决。
|
|