Hello ng,
i have problems with the getting and setting of the translation of
nodecores. The first thing which doesn't work well is the rotation, the
second thing is, that i doesn´t get the right information by calling
matrix.getTransform respectively i doesn't get the values which i set in
setObjectTranslation.
here are my methods setting and getting the translation:
void C3DEngine::setObjectTranslation(float posX, float posY, float posZ,
float rotX, float rotY, float rotZ,
float scaleX, float scaleY, float scaleZ)
{
OSG::Matrix m = currentTransform->getMatrix();
OSG::Matrix tmp;
m.setIdentity();
tmp.setIdentity();
tmp.setTranslate(posX, posY, posZ);
m.mult(tmp);
OSG::Quaternion qX(OSG::Vec3f(1,0,0), rotX/180.0f*PI);
OSG::Quaternion qY(OSG::Vec3f(0,1,0), rotY/180.0f*PI);
OSG::Quaternion qZ(OSG::Vec3f(0,0,1), rotZ/180.0f*PI);
qX.mult(qY); // this isn´t the right way, but i didn´t found a better one
qX.mult(qZ);
tmp.setRotate(qX);
m.mult(tmp);
tmp.setScale(scaleX, scaleY, scaleZ);
m.mult(tmp);
currentTransform->setMatrix(m);
}
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);
// aktuellen Transformationsknoten setzen
OSG::NodePtr parent;
parent = getParentNodeWithName(n, "OBJEKTTRANSFORM"); // get the root
Node of an vrml-object, this works!
if(parent != OSG::NullFC)
{
std::string str = OSG::getName(parent);
if(str=="OBJEKTTRANSFORM")
{
currentTransform = OSG::TransformPtr::dcast(parent->getCore());//kommt
hier der richtige Core?
OSG::Matrix m = currentTransform->getMatrix();
OSG::Quaternion rotation;
OSG::Vec3f translation;
OSG::Quaternion scaleOrientation;
OSG::Vec3f scalation;
m.getTransform(translation, rotation, scalation, scaleOrientation); ///
here is the fault, have i to normalize something or to do something
other first with the matrix/vectors?
currentSceneObject.posX = translation.x();
currentSceneObject.posY = translation.y();
currentSceneObject.posZ = translation.z();
currentSceneObject.rotX = rotation.x();
currentSceneObject.rotY = rotation.y();
currentSceneObject.rotY = rotation.z();
currentSceneObject.scaleX = scalation.x();
currentSceneObject.scaleY = scalation.y();
currentSceneObject.scaleZ = scalation.z();
}
}
}
else
{
mgr->setHighlight(OSG::NullFC);
return OSG::NullFC;
}
}
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