|
楼主 |
发表于 2011-9-5 20:17:42
|
显示全部楼层
回复 2# array
#include <osg/Camera>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator>
#include <osgUtil/SmoothingVisitor>
osg::ref_ptr<osg::Geode> CreateCuboid()
{
osg::ref_ptr<osg::Geode> geode=new osg::Geode;
osg::ref_ptr<osg::Geometry> geom=new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> vector=new osg::Vec3Array;
vector->push_back(osg::Vec3(0,0,1));
vector->push_back(osg::Vec3(0,0,0));
vector->push_back(osg::Vec3(1,0,1));
vector->push_back(osg::Vec3(1,0,0));
vector->push_back(osg::Vec3(1,1,1));
vector->push_back(osg::Vec3(1,1,0));
vector->push_back(osg::Vec3(0,1,1));
vector->push_back(osg::Vec3(0,1,0));
vector->push_back(osg::Vec3(0,0,1));
vector->push_back(osg::Vec3(0,0,0));
geom->setVertexArray(vector);
geom->addPrimitiveSet(new osg:rawArrays(osg::DrawArrays:UAD_STRIP,0,vector->size()));
osg::ref_ptr<osg::DrawElementsUInt> dui=new osg::DrawElementsUInt(osg::DrawArrays::QUADS,8);
dui->push_back(0);dui->push_back(2);dui->push_back(4);dui->push_back(6);
dui->push_back(1);dui->push_back(3);dui->push_back(5);dui->push_back(7);
geom->addPrimitiveSet(dui);
geode->addDrawable(geom);
osgUtil::SmoothingVisitor smv;
smv.apply(*geode);
return geode;
}
int main( int argc, char** argv )
{
osg::ref_ptr<osgViewer::Viewer> viewer =new osgViewer::Viewer;
osg::ref_ptr<osg::Group> root =new osg::Group;
root->addChild(CreateCuboid());
viewer->setSceneData(root);
return viewer->run();
}
正面
反面
为什么直接使用shapedrawable就不会有这问题?材质和灯光如何设置呢? |
|