// // OpenSceneGraph Quick Start Guide // http://www.lulu.com/content/767629
// http://www.openscenegraph.com/osgwiki/pmwiki.php/Documentation/QuickStartGuide
//
// State Example, Modifying state attributes and modes
#include <osg/Group> // 组节点
#include <osg/MatrixTransform> // 矩阵变换
#include <osg/Geode> // 叶节点
#include <osg/Geometry> // 几何信息
#include <osg/StateSet> // 状态设置
#include <osg/StateAttribute> // 状态属性
#include <osg/ShadeModel> // 着色模型
#include <osg/CullFace> // 剔除多边形面
#include <osg/PolygonMode> // 多边形模型
#include <osg/LineWidth> // 线宽
#include <osg/ref_ptr>
#include <osgDB/Registry> // 注册表
#include <osgDB/WriteFile>
#include <osgDB/ReadFile>
#include <osg/Notify> // 通知
#include <osgViewer/Viewer>
#include <iostream>
int
main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
osg::Node *pan = osgDB::readNodeFile("panxing.obj");
// 创建旋转矩阵,并把导弹作为旋转矩阵的孩子
osg::MatrixTransform* rotateMT = new osg::MatrixTransform;
rotateMT->setMatrix(
osg::Matrix::rotate(osg::inDegrees(90.0f),0.f,0.f,1.f)); // 沿着x轴顺时针旋转90度
rotateMT->addChild(pan);
std::string out( "panxing.obj" ); //保存
if ( !(osgDB::writeNodeFile( *(rotateMT), out )) )
{
osg::notify(osg::FATAL) << "Failed in osgDB::writeNodeFile()." ;
return 1;
}
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild(osgDB::readNodeFile("panxing.obj"));
viewer->setSceneData(root);
return viewer->run();
}
#CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(osg27 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS REQUIRED Widgets Xml Test)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets osgDB osgViewer osg )