[osg-users] osgmanipulator example questions

sicong he hesicong2005 at gmail.com
Mon Sep 10 03:49:11 PDT 2007


I tried by best and I found a way to solve thi problem.
The idea is:
First see the scene structure:

SceneRoot
Teapot01 Box01

Teapot01 and Box01 are the children of SceneRoot.
When I select "Teapot01", the osgManipulator::selection (I call it in my
program Selection) set Teapot01 as one if its children.
Then I find all the parents of Teapot01, in this example, is SceneRoot and
Selection.
Then I replace the Teapot01 child of SceneRoot with Selection. Now the scene
structure is:

SceneRoot
Selection      Box01
Teapot01

And then I connect the dragger with Selection. All things go right.
When Box01 is selected, I replace the Selection child of SceneRoot with
Teapot01 and calculate the matrix of Teapot01.
The matrix of Selection is also reset. Then repeat the above steps to make
Box01 dragable.

My demo program and test scene is attached. If you have better ideas, please
tell me! Thanks in advanced!

2007/9/10, David Callu <ledocc at gmail.com>:
>
> Hi,
>
>
> Can you send the osgmanipulator.cpp modified and your scene to test?
>
> David Callu
>
> 2007/9/10, hesicong2006 <hesicong2006 at 163.com >:
> >
> > I know why. root should add an Child include the scene.
> >
> > But another question. I can drag the Teapot01, but the whole scene now
> > has two "Teapot". Then how can I fix it?
> >
> > hesicong2006 wrote:
> > > Hi, Robert
> > > Someday before I asked a question about drag object in OSG and you
> > told
> > > me to see osgmanipulator example. It's great.
> > > I tried to modify it as I want to move one object in the scene but the
> > > whole scene. I tried to do this in addDraggerToScene function:
> > >
> > > osg::Node* addDraggerToScene(osg::Node* scene,
> > > osgManipulator::CommandManager* cmdMgr, const std::string& name)
> > > {
> > >    scene->getOrCreateStateSet()->setMode(GL_NORMALIZE,
> > > osg::StateAttribute::ON);
> > >
> > >    osg::Node* selectedObject=FindByName("Teapot01");
> > >
> > >    osgManipulator::Selection* selection = new
> > osgManipulator::Selection;
> > >    selection->addChild(selectedObject);
> > >
> > >    osgManipulator::Dragger* dragger = createDragger(name);
> > >
> > >    osg::Group* root = new osg::Group;
> > >    root->addChild(dragger);
> > >    root->addChild(selection);
> > >    root->addChild(createHUD());
> > >
> > >    float scale = selectedObject->getBound().radius() * 1.6;
> > >    dragger->setMatrix(osg::Matrix::scale(scale, scale, scale) *
> > >
> > > osg::Matrix::translate(selectedObject->getBound().center()));
> > >    cmdMgr->connect(*dragger, *selection);
> > >
> > >    return root;
> > > }
> > >
> > >
> > > And here my scene has two objects, one teapot, one box. But when I run
> >
> > > the program, I see only the "Teapot01" which really can drag and move,
> > > but the box is lost!
> > > I don't know how to only move one object in the scene. Please give me
> > > some ideas. Thanks.
> > >
> > >
> >
> > _______________________________________________
> > osg-users mailing list
> > osg-users at lists.openscenegraph.org
> >
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20070910/905e8f58/attachment-0003.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NativePick.rar
Type: application/octet-stream
Size: 27003 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20070910/905e8f58/attachment-0003.obj>


More information about the osg-users mailing list