osgViewer::Viewer缩放、平移对单个模型不起作用
生活随笔
收集整理的這篇文章主要介紹了
osgViewer::Viewer缩放、平移对单个模型不起作用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?當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::Viewer缩放、平移对单个模型不起作用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: osgText中的setAxisAlig
- 下一篇: 苹果xr充电时间