1.OSG屏幕坐标系:
x轴:默认屏幕水平向右方向。
y轴:垂直屏幕向里。
z轴:垂直向上。
2.隐藏模型
模型仍在渲染当中,损耗并未减少,适用于小模型。
osg::ref_ptr<osg::Node> osgcool = osgDB::readNodeFile("glider.osg");
oc->setNodeMask(0);
3.节点开关
在内存中消失,需要时显示出来,适用于使用频率较低的模型。
#include <osg/Switch>
osg::ref_ptr<osg::Group> group = new osg::Group;
osg::Switch *sw = new osg::Switch();
sw->addChild(osgDB::readNodeFile("glider.osg"),false);
group->addChild(sw);
4.模型变换
平移旋转缩放,通过矩阵相乘来实现。
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgDB/ReadFile>
#include <osg/Switch>
#include <osg/MatrixTransform>//矩阵变换
int main()
{
osg::ref_ptr<osg::Group> group = new osg::Group;
osg::ref_ptr<osg::Node> osgcool = osgDB::readNodeFile("glider.osg");
osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform;
trans->setMatrix(osg::Matrix::translate(0, 0, 2));
trans->addChild(osgcool.get());
osg::ref_ptr<osg::MatrixTransform> scale = new osg::MatrixTransform;
scale->setMatrix(osg::Matrix::scale(0.5, 0.5, 0.5)*osg::Matrix::translate(0, 0, -2));
scale->addChild(osgcool.get());
osg::ref_ptr<osg::MatrixTransform> rot = new osg::MatrixTransform;
rot->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(45.0), 1, 0, 0)*osg::Matrix::scale(0.5, 0.5, 0.5)*osg::Matrix::translate(4, 0, -2));
rot->addChild(osgcool.get());
group->addChild(osgcool.get());
group->addChild(trans.get());
group->addChild(scale.get());
group->addChild(rot.get());
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
viewer->setSceneData(group.get());
viewer->addEventHandler(new osgViewer::WindowSizeHandler);
viewer->run();
return 0;
}