Lor*_*man 6 c++ openscenegraph
首先,我必须为我的英语道歉.
我正在开发一个应用程序,我们必须在每个时刻知道每个节点的属性(位置,旋转......),所以我想从场景图中获取每个节点的变换矩阵.
我遇到的问题是我不知道该怎么做.例如,如果我有类似的东西:
osg::ref_ptr<osg::Node> root = osgDB::readNodeFile("cessna.osg.15,20,25.trans.180,90,360.rot.2,3,4.scale");
Run Code Online (Sandbox Code Playgroud)
我想从名为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;
Run Code Online (Sandbox Code Playgroud)
但我想只有矩阵,是否可能?
谢谢.
PD:我正在使用nodeVisitor来做这件事.
我认为您只想将矩阵打印到控制台。在这种情况下,请使用中提供的流运算符<osg/io_utils>:
#include <osg/io_utils>
std:: cout << mat;
Run Code Online (Sandbox Code Playgroud)