Hi Brian,
ShapeDrawable by defaults uses display lists so you'll need to call
dirtyDisplayList() on it to force it to update.
Robert.
On 5/2/07, Brian Sparks <[EMAIL PROTECTED]> wrote:
Hi All,
I know this is a total newby question, sorry. I want
to change the length/width of a cylinder. I noticed
there are setHeight / setRadius functions, but they do
not work as I thought. The following code is very
simple: it sets up a scene with one cylinder. It sets
a global pointer to the osg::Cylinder object, and then
during an update callback, calls setHeight(). But the
cylinder does not change on the screen. If I do the
appropriate rotation on the appropriate
MatrixTransform object, it rotates.
What am I doing wrong?
Thanks in advance!
-- Brian
I hope this code comes out OK to the list:
-----------------------------------------------
float r = 0.01;
float h = 1.0;
MatrixTransform * g_pMtxXfrm = NULL;
Cylinder * g_pCyl = NULL;
class myMtxXfrmNodeCallback : public osg::NodeCallback
{
public:
virtual void operator()(osg::Node* node,
osg::NodeVisitor* nv)
{
g_pCyl->setHeight(h);
g_pCyl->setRadius(h);
h += 0.1;
g_pMtxXfrm->postMult(osg::Matrixf::rotate(r,
Y_AXIS));
traverse(node, nv);
}
};
class myCylNodeCallback : public osg::NodeCallback
{
public:
virtual void operator()(osg::Node* node,
osg::NodeVisitor* nv)
{
g_pCyl->setHeight(h);
g_pCyl->setRadius(h);
h += 0.1;
traverse(node, nv);
}
};
int main( int argc, char **argv )
{
osg::Group* root = new osg::Group();
osgProducer::Viewer viewer;
ref_ptr<TessellationHints> hints = new
TessellationHints;
hints->setDetailRatio(2.0f);
ref_ptr<ShapeDrawable> shape;
ref_ptr<Geode> geode = new Geode;
ref_ptr<MatrixTransform> transform = g_pMtxXfrm = new
MatrixTransform;
transform->setUpdateCallback( new
myMtxXfrmNodeCallback );
transform->addChild(geode.get());
root->addChild(transform.get());
shape = new ShapeDrawable(g_pCyl = new
Cylinder(Vec3(0.0f, 0.0f, 3.0f), 5., 2.),
hints.get());
// g_pCyl->setUpdateCallback( new myCylNodeCallback );
g_pCyl->setDataVariance(Object::DYNAMIC);
shape->setColor(Vec4(1.0f, 0.3f, 0.3f, 1.0f));
geode->addDrawable(shape.get());
// add a viewport to the viewer and attach the
scene graph.
viewer.setSceneData( root );
viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
viewer.setSceneData( root );
viewer.realize();
while( !viewer.done() )
{
// wait for all cull and draw threads to
complete.
viewer.sync();
// update the scene by traversing it with the
the update visitor which will
// call all node update callbacks and
animations.
viewer.update();
// fire off the cull and draw traversals of the
scene.
viewer.frame();
}
// wait for all cull and draw threads to complete
before exit.
viewer.sync();
return 0;
}
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/