|
楼主 |
发表于 2009-7-25 19:23:31
|
显示全部楼层
osg::Geometry* polyGeom = new osg::Geometry();
//mirror = new osg::Geometry();
//设置该几何体不使用显示列表
polyGeom->setDataVariance( osg::Object:YNAMIC );
polyGeom->setSupportsDisplayList(true);
//创建顶点数组,并添加数据
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices->push_back( osg::Vec3(0.0f,0.0f,0.0f)+mirrorcenter );
vertices->push_back( osg::Vec3(0.0f,mirror_width,0.0f)+mirrorcenter );
vertices->push_back( osg::Vec3(0.0f,mirror_width,mirror_height)+mirrorcenter );
vertices->push_back( osg::Vec3(0.0f,0.0f,mirror_height)+mirrorcenter );
//创建纹理数组,并添加数据
osg::Vec2Array* texcoords = new osg::Vec2Array();
texcoords->push_back( osg::Vec2(0.0f,0.0f) );
texcoords->push_back( osg::Vec2(1.0f,0.0f) );
texcoords->push_back( osg::Vec2(1.0f,1.0f) );
texcoords->push_back( osg::Vec2(0.0f,1.0f) );
polyGeom->setVertexArray(vertices);
//使用vbo扩展
{
osg::VertexBufferObject* vbObject = new osg::VertexBufferObject;
//vertices->setVertexBufferObject(vbObject);
//polyGeom->setUseVertexBufferObjects(true);
}
polyGeom->setTexCoordArray(0,texcoords);
//创建颜色数组,并设置绑定方式及添加数据
// osg::Vec4Array* colors = new osg::Vec4Array;
// colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
// polyGeom->setColorArray(colors);
// polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
polyGeom->addPrimitiveSet(new osg::DrawArrays(osg:rimitiveSet:UADS,0,vertices->size()));
//现在我们需要将纹理附加到该几何体上,我们创建一个包含该纹理的StateSet
osg::StateSet* stateset = new osg::StateSet;
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);
polyGeom->setStateSet(stateset);
//polyGeom->setUpdateCallback(new MirrorCallback((*vertices)[0],(*vertices)[1],(*vertices)[2],(*vertices)[3]));
Mycallback* mycb = new osg::Mycallback(osg::Vec3(0.f,0.f,0.f),osg::Vec3(2.f,0.f,0.f),osg::Vec3(2.f,2.f,0.f),osg::Vec3(0.f,2.f,0.f));
polyGeom->setUpdateCallback(mycb);
在回调函数里我是这样做的:
class MyCallback :
public osg::Drawable::UpdateCallback
{
public:
MyCallback(osg::Vec3& lu,osg::Vec3& lb,osg::Vec3& ru,osg::Vec3& rb):
leftup(lu),
leftbottom(lb),
rightup(ru),
rightbottom(rb)
{
//extracted_verts=new osg::Vec3Array;
}
~MyCallback()
{
}
virtual void update(osg::NodeVisitor* nv,osg::Drawable* drawable)
{
//drawable->dirtyBound();
osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(drawable);
osg::Vec3Array* vertices= dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray());
(*vertices)[0]=leftup;
(*vertices)[1]=leftbottom;
(*vertices)[2]=rightup;
(*vertices)[3]=rightbottom;
geometry->setVertexArray(vertices);
geometry->dirtyDisplayList();
}
public:
osg::Vec3 leftup,leftbottom,rightup,rightbottom;
};
通过改变leftup,leftbottom,rightup,rightbottom来改变长方形的大小,但是没反应,什么地方不对呢? |
|