首先,我必须为我的英语道歉。
我正在开发一个应用程序,我们必须在每个时刻知道每个节点的属性(位置、旋转...),所以我考虑从场景图中获取每个节点的变换矩阵。
我遇到的问题是我不知道该怎么做。例如,如果我有这样的东西:
osg::ref_ptr<osg::Node> root = osgDB::readNodeFile("cessna.osg.15,20,25.trans.180,90,360.rot.2,3,4.scale");
我想从名为 root 的 Node 对象中获取变换矩阵。我发现了类似的东西:
osg::Matrix mat = osg::computeWorldToLocal(this->getNodePath());
std::cout << "X: " << mat.getTrans().x() << std::endl;
std::cout << "Rot X: " << mat.getRotate().x() << std::endl;
std::cout << "Scale X: " << mat.getScale().x() << std::endl;
但我只想拥有矩阵,这可能吗?
谢谢。
PD:我正在使用 nodeVisitor 来执行此操作。
最佳答案
我认为您只想将矩阵打印到控制台。在这种情况下,请使用 <osg/io_utils>
中提供的流运算符:
#include <osg/io_utils>
std:: cout << mat;
关于c++ - OSG : Get transform matrix from a node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14622323/