Hello Austin,
Austin Baker wrote:
> In this application, I must be able to 'flatten' the scene graph
> and break all dependencies, yet retain each objects position. I do
> this with a depth-first tree-traversal and successively add all
> objects to a new root (hence flattening the tree). It works great,
> except for one issue...
>
> It seems the sphere and cone are stored relative to the box and
> when I break that link between the box and its children, the sphere
> and cone both get moved back to the position where they were
> originally created.
yes, at least on the OpenSG side children are positioned relative to
their parent.
> I have attempted to store the matrix of the sphere
> and cone before breaking the link, and then set their matrix to it
> after the operation is complete, but they still remain at their
> creation location, instead of where they should be (located near the
> box).
Hm, from your description and code I can not see any obvious problem;
just some comments/questions:
> Here is how I store and overwrite the matrix:
>
> [code]
> if (numChildren <= 0) // Do we have a leaf node?
> {
> // We only care about leaf nodes with Geometry Cores for now
> if(nodeCore != osg::NullFC &&
> nodeCore->getType().isDerivedFrom(osg::Geometry::getClassType()))
> {
> // save current world matrix of the object (the transform
> node is located 2 levels up from the actual geometry faces)
I guess you checked this, but are you sure this is where the transform
is located ?
> osg::NodePtr parentPtr = node->getParent()->getParent();
> osg::Node* parentNode = parentPtr.getCPtr();
why do you use/need the Node * here ?
> osg::Matrix worldMatrix = parentNode->getToWorld();
you can ask any Node for the toWorld matrix, so just using
node->getToWorld() should give you the transformation matrix that
applies to the geometry. You would store the wrong matrix if there is
another transform below this one.
> // move parent node with transform core to new root and
> overwrite its matrix
> osg::beginEditCP(newRoot);
> newRoot->addChild(parentPtr);
> osg::TransformPtr parent_xform =
> osg::TransformPtr::dcast(parentNode->getCore());
> osg::beginEditCP(parent_xform);
> parent_xform->setMatrix(worldMatrix); osg::endEditCP(parent_xform);
> osg::endEditCP(newRoot);
> }
> }
> [/code]
Hm, basically I would expect this to work. As stated above I'm just a
bit curious if the assumptions you make on where the transforms are
located are valid.
Sorry for not being more helpful,
Carsten
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users