OSG:从节点获取变换矩阵

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来做这件事.

use*_*323 5

我认为您只想将矩阵打印到控制台。在这种情况下,请使用中提供的流运算符<osg/io_utils>

#include <osg/io_utils>

std:: cout << mat;
Run Code Online (Sandbox Code Playgroud)


小智 0

好吧,你在 osg::Matrix mat 中有矩阵。我不清楚你所说的“我只想拥有矩阵”是什么意思。如果你澄清的话,我也许可以帮助你。