当osgViewer中只有一个模型时,osg::PositionAttitudeTransform 、osg::MatrixTransform对模型缩放、平移不起作用,只有大于1个模型时才起作用,原因不知道为啥,如下代码不会平移、缩放模型
#include <osgViewer/Viewer>
#include <osgViewer/CompositeViewer>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Group>
#include <osg/Geometry>
#include <osg/Camera>
#include <osg/MatrixTransform>
#include <osg/PositionAttitudeTransform>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>
#include <iostream>
int main()
{
osg::ref_ptr<osgViewer::Viewer> spViewer = new osgViewer::Viewer;
osg::ref_ptr<osg::Group> spGroup = new osg::Group;
osg::ref_ptr<osg::PositionAttitudeTransform> spTranform = new osg::PositionAttitudeTransform;
osg::ref_ptr<osg::Node> spNode = osgDB::readNodeFile("glider.osg");
spTranform->setScale(osg::Vec3(3, 2, 4)); // 此句不起作用
spTranform->addChild(spNode);
spGroup->addChild(spTranform);
spViewer->setSceneData(spGroup);
spViewer->realize();
spViewer->run();
return 0;
}
下面的代码也不起作用
#include <osgViewer/Viewer>
#include <osgViewer/CompositeViewer>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Group>
#include <osg/Geometry>
#include <osg/Camera>
#include <osg/MatrixTransform>
#include <osg/PositionAttitudeTransform>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgUtil/Optimizer>
#include <iostream>
int main()
{
osg::ref_ptr<osgViewer::Viewer> spViewer = new osgViewer::Viewer;
osg::ref_ptr<osg::MatrixTransform> spTranform = new osg::MatrixTransform;
osg::ref_ptr<osg::Node> spNode = osgDB::readNodeFile("E:/osg/OpenSceneGraph-Data-3.0.0/cow.osg");
osg::Matrix m1 = spTranform->getMatrix();
// 下面这句不会平移模型
m1 *= osg::Matrix::translate(osg::Vec3(-10.0f, 0.0f, 0.0f));
spTranform->setMatrix(m1);
spTranform->addChild(spNode);
spViewer->setSceneData(spTranform);
spViewer->realize();
spViewer->run();
return 0;
}
在osgViewer中,当场景只有一个模型时,osg::PositionAttitudeTransform和osg::MatrixTransform的缩放和平移操作不起作用,只有在有多个模型时才生效。代码示例显示了尝试对模型进行缩放和平移但未成功的场景。

2005

被折叠的 条评论
为什么被折叠?



