#include<osgViewer\Viewer>
#include<osg\Node>
#include<osg\Geode>
#include<osg\Group>
#include<osg\MatrixTransform>
#include<osgDB\ReadFile>
#include<osgDB\WriteFile>
#include<osgUtil\Optimizer>
int main()
{
//创建Viewer对象,场景浏览器
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
//创建场景组节点
osg::ref_ptr<osg::Group> root = new osg::Group();
//创建一个节点,读取牛的模型
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("cow.osg");
//创建矩阵变换节点mt1
osg::ref_ptr<osg::MatrixTransform> mt1 = new osg::MatrixTransform();
//创建一个矩阵
osg::Matrix m;
//在X方向平移10个单位
m.makeTranslate(osg::Vec3(10.0f, 0.0f, 0.0f));
//绕X轴旋转45度
m.makeRotate(45.0f, 1.0f, 0.0f, 0.0f);
//设置矩阵
mt1->setMatrix(m);
//添加子节点
mt1->addChild(node.get());
//创建矩阵变换节点mt2
osg::ref_ptr<osg::MatrixTransform> mt2 = new osg::MatrixTransform();
//创建一个矩阵
osg::Matr
OSG学习:矩阵变换节点示例
最新推荐文章于 2023-06-16 08:04:46 发布
本文档通过一个示例展示了如何在OSG中利用MatrixTransform节点进行矩阵变换,包括平移和旋转操作。代码创建了两个MatrixTransform节点,分别对同一个牛模型应用不同的变换矩阵,实现了模型在场景中的不同位置和角度显示。
摘要由CSDN通过智能技术生成