osgViewer::Viewer缩放、平移对单个模型不起作用

在osgViewer中,当场景只有一个模型时,osg::PositionAttitudeTransform和osg::MatrixTransform的缩放和平移操作不起作用,只有在有多个模型时才生效。代码示例显示了尝试对模型进行缩放和平移但未成功的场景。

 当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;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值