Hi Daniel,
If you want to combine a set of transforms/rotations, you have to create
separate matrices and multiply them together:
osg::Matrix tmp, osg::Matrix final;
final.setIdentity();
tmp.setTranslate(...);
final.mult(tmp);
tmp.setRotate(...);
final.mult(tmp);
...
etc.. Ether that, or combine the rotation in a quaternion and use one
of the setTransform (translate, quat, scale) functions.
That might be one reason why it dosn't work. I also don't know what your
exact problem is, other than 'it doesn't work the way you want'. :)
Cheers
/Marcus
P.S. That's a lot of code you posted. Try to get a small & simple part
of it working before you do anything more complex.
Daniel Zuidinga wrote:
> Hello,
>
> i want to move an vrml-node with all its childs if i click it.
> I implemented 3 methods:
>
>
> first one: adds and Transformation node and the vrml-nodes as a child(s)
> (the result is added to the graph):
>
> OSG::NodePtr createSceneObject(CSceneObject object)
> {
> OSG::NodePtr nVrml = OSG::SceneFileHandler::the().read(object.filename);
>
> if (nVrml != OSG::NullFC)
> {
> // Transformation und Rotation
> OSG::TransformPtr cTransform = OSG::Transform::create();
> beginEditCP(cTransform , OSG::Transform::MatrixFieldMask);
> object.m.setIdentity();
> object.m.setTranslate(object.posX, object.posY, object.posZ);
> object.m.setRotate(OSG::Quaternion(OSG::Vec3f(1,0,0), object.rotX));
> object.m.setRotate(OSG::Quaternion(OSG::Vec3f(0,1,0), object.rotY));
> object.m.setRotate(OSG::Quaternion(OSG::Vec3f(0,0,1), object.rotZ));
> object.m.setScale(object.scaleX, object.scaleY, object.scaleZ);
> cTransform->setMatrix(object.m);
> OSG::setName(cTransform, "OBJEKTTRANSFORM");
> endEditCP(cTransform, OSG::Transform::MatrixFieldMask);
>
> OSG::NodePtr nTransform = OSG::Node::create();
> beginEditCP(nTransform, OSG::Node::CoreFieldMask |
> OSG::Node::ChildrenFieldMask);
> nTransform->setCore(cTransform);
> nTransform->addChild(nVrml);
> OSG::setName(nTransform, "OBJEKTTRANSFORM");
> endEditCP(nTransform, OSG::Node::CoreFieldMask |
> OSG::Node::ChildrenFieldMask);
> return nTransform;
>
> }
> else
> {
> logger.logDebug("Datei konnte nicht geladen werden");
> return OSG::NullFC;
> }
> }
>
> second one: gives a node upwards to the parents:
>
> OSG::NodePtr getParentNodeWithName(OSG::NodePtr n, char* str)
> {
> //int parents = n->getParent();
> bool found = false;
>
> if(getName(n))
> if(getName(n) == std::string(str))
> {
> found = true;
> return n;
> }
> else
> {
> return getParentNodeWithName(n->getParent(), str);
> }
> }
>
>
> third one: here is the problem: the parent-core-type seems not to be
> derived from OSG::Transform.
>
> OSG::NodePtr C3DEngine::selectObject(int x, int y)
> {
> OSG::Line ray = mgr->calcViewRay(x, y);
> OSG::IntersectAction *iAct = OSG::IntersectAction::create();
>
> iAct->setLine(ray);
> iAct->apply(mgr->getRoot());
>
> if (iAct->didHit())
> {
> OSG::NodePtr n = iAct->getHitObject();
> currentObject = n;
> mgr->setHighlight(n);
> mgr->setHeadlight(true);
>
> OSG::NodePtr parent;
> parent = getParentNodeWithName(n,"OBJEKTTRANSFORM"); //gives a parent
> if(parent != OSG::NullFC)
> {
> if(parent->getCore()->getType().isDerivedFrom(
> OSG::Transform::getClassType())) //gives not the right type
> {
> OSG::TransformPtr cTransform = OSG::TransformPtr::dcast(parent->getCore());
> OSG::Matrix m = cTransform->getMatrix();
> m.setTranslate(10, 0, 0);
> cTransform->setMatrix(m);
> }
> }
> return n;
> }
> else
> {
> return OSG::NullFC;
> }
>
> }
>
> i can“t find my fault :-/
>
>
> thanks
> Daniel
>
>
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Opensg-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/opensg-users
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users