#ifdef _WIN32
#include <Windows.h>
#endif // _WIN32
#include<iostream> #include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/CompositeViewer> #include <osgDB/ReadFile> #include <osg/Geode>
#include <osg/Node>
#include <osg/Geometry>
#include <osg/GraphicsContext>
#include <osg/ShapeDrawable>
#include <osg/Material>
#include <osg/Image>
#include <osg/Texture2D>
#include <osg/TexEnv>
#include <osg/TexGen>
#include <osg/NodeVisitor>
#include <osg/MatrixTransform>
#include <osg/PositionAttitudeTransform>
#include <osg/AnimationPath>
#include <osg/Matrixd>
#include <osg/PagedLOD>
#include <osg/Camera>
#include <osgText/Text> #include <osgGA/TrackballManipulator>
#include <osgGA/GUIEventHandler>
#include <osgGA/CameraManipulator>
#include <osgGA/StandardManipulator>
#include <osgGA/OrbitManipulator>
#include <osgGA/TrackballManipulator> #include <osgUtil/IntersectionVisitor>
#include <osgUtil/LineSegmentIntersector> osg::Node* createCircle()
{
//osg::ref_ptr<osg::Geode> geode1 = new osg::Geode;
//osg::ref_ptr<osg::StateSet> stateSet1 = geode1->getOrCreateStateSet();
osg::Geode *geode1 = new osg::Geode;
osg::StateSet *stateSet1 = geode1->getOrCreateStateSet(); osg::ref_ptr<osg::Image> image1 = osgDB::readImageFile("D:\\参考手册\\OSG\\mzj.jpg"); if (!image1.valid())
{
return geode1;
} osg::ref_ptr<osg::Texture2D> texture2d1 = new osg::Texture2D;
texture2d1->setImage(, image1);
stateSet1->setTextureAttributeAndModes(, texture2d1, osg::StateAttribute::ON);
stateSet1->setMode(GL_LIGHTING, osg::StateAttribute::OFF); osg::TessellationHints *hits = new osg::TessellationHints;
hits->setDetailRatio(0.8f); geode1->addDrawable(new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(400.0, 300.0, 0.0), , 0.1), hits)); return geode1;
} osg::Node* createCircle1(osg::Texture2D *texture2dParam)
{
//osg::ref_ptr<osg::Geode> geode1 = new osg::Geode;
//osg::ref_ptr<osg::StateSet> stateSet1 = geode1->getOrCreateStateSet();
osg::Geode *geode1 = new osg::Geode;
osg::StateSet *stateSet1 = geode1->getOrCreateStateSet(); stateSet1->setTextureAttributeAndModes(, texture2dParam, osg::StateAttribute::ON);
stateSet1->setMode(GL_LIGHTING, osg::StateAttribute::OFF); osg::TessellationHints *hits = new osg::TessellationHints;
hits->setDetailRatio(0.8f); geode1->addDrawable(new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(400.0, 300.0, 0.0), , 0.1), hits)); return geode1;
} osg::Camera* createBackground(std::string strImg)
{
osg::ref_ptr<osg::Geode> geode1 = new osg::Geode;
osg::ref_ptr<osg::Geometry> geometry1 = new osg::Geometry;
osg::ref_ptr<osg::Camera> camera1 = new osg::Camera; camera1->setAllowEventFocus(false);
camera1->setProjectionMatrixAsOrtho2D(, , , );
camera1->setViewport(, , , ); camera1->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera1->setRenderOrder(osg::Camera::PRE_RENDER);
camera1->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
//camera1->setClearColor(osg::Vec4());
camera1->setViewMatrix(osg::Matrix::identity()); //压入顶点
osg::ref_ptr<osg::Vec3Array> vertex = new osg::Vec3Array;
vertex->push_back(osg::Vec3(0.0, 0.0, 0.0));
vertex->push_back(osg::Vec3(960.0, 0.0, 0.0));
vertex->push_back(osg::Vec3(960.0, 600.0, 0.0));
vertex->push_back(osg::Vec3(0.0, 600.0, 0.0));
geometry1->setVertexArray(vertex); //压入法线
osg::ref_ptr<osg::Vec3Array> norml = new osg::Vec3Array;
norml->push_back(osg::Vec3(0.0, 0.0, 1.0));
geometry1->setNormalArray(norml);
geometry1->setNormalBinding(osg::Geometry::BIND_OVERALL); //纹理坐标
osg::ref_ptr<osg::Vec2Array> coord = new osg::Vec2Array;
coord->push_back(osg::Vec2(0.0, 0.0));
coord->push_back(osg::Vec2(1.0, 0.0));
coord->push_back(osg::Vec2(1.0, 1.0));
coord->push_back(osg::Vec2(0.0, 1.0));
geometry1->setTexCoordArray(, coord);
geometry1->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, , )); osg::ref_ptr<osg::Image> img1 = osgDB::readImageFile(strImg);
if (!img1.valid())
{
std::cout << "" << std::endl;
} osg::ref_ptr<osg::Texture2D> texture2d = new osg::Texture2D;
texture2d->setImage(, img1);
geometry1->getOrCreateStateSet()->setTextureAttributeAndModes(, texture2d, osg::StateAttribute::ON); camera1->addChild(geode1);
geode1->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
geode1->addDrawable(geometry1); return camera1.release();
} //创建hud
osg::Camera* createCamera()
{
osg::ref_ptr<osg::Camera> camera1 = new osg::Camera;
camera1->setViewMatrix(osg::Matrix::identity());
camera1->setAllowEventFocus(false);
camera1->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera1->setViewport(, , , );
camera1->setProjectionMatrixAsOrtho2D(, , , );
camera1->setClearMask(GL_DEPTH_BUFFER_BIT);
camera1->setRenderOrder(osg::Camera::POST_RENDER); camera1->addChild(createCircle());
return camera1.release();
} osg::Camera* createHUD(osg::Texture2D *texture2d)
{
osg::ref_ptr<osg::Camera> camera1 = new osg::Camera;
camera1->setViewMatrix(osg::Matrix::identity());
camera1->setAllowEventFocus(false);
camera1->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera1->setViewport(, , , );
camera1->setProjectionMatrixAsOrtho2D(, , , );
camera1->setClearMask(GL_DEPTH_BUFFER_BIT);
camera1->setRenderOrder(osg::Camera::POST_RENDER); camera1->addChild(createCircle1(texture2d));
return camera1.release();
} //烘焙纹理
void createRTT(osgViewer::Viewer *viewerParam)
{
osg::ref_ptr<osg::Group> group1 = new osg::Group;
osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\\参考手册\\BIM\\osg\\build20190628.osgb"); group1->addChild(node1.get());
if (!viewerParam)
{
return;
} unsigned int width, height;
//获取系统分辨率
osg::GraphicsContext::WindowingSystemInterface *wsInterface = osg::GraphicsContext::getWindowingSystemInterface();
if (!wsInterface)
{
return;
} wsInterface->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(), width, height);
osg::ref_ptr<osg::GraphicsContext::Traits> traits1 = new osg::GraphicsContext::Traits; //width = 800;
//height = 600; traits1->x = ;
traits1->y = ;
traits1->width = width;
traits1->height = height;
traits1->windowDecoration = false;
traits1->doubleBuffer = true;
traits1->sharedContext = ; osg::ref_ptr<osg::GraphicsContext> graphicsContext1 = osg::GraphicsContext::createGraphicsContext(traits1);
if (!graphicsContext1.valid())
{
return;
} //创建主相机
osg::ref_ptr<osg::Camera> masterCamera = new osg::Camera;
masterCamera->setGraphicsContext(graphicsContext1);
masterCamera->setViewport(, , width, height); //osg::Camera *masterCamera = createBackground("D:\\参考手册\\images\\104.jpg");
//masterCamera->setViewport(0, 0, width, height);
viewerParam->addSlave(masterCamera); //烘焙RTT相机
osg::ref_ptr<osg::Camera> rttCamera = new osg::Camera;
rttCamera->setRenderOrder(osg::Camera::PRE_RENDER);
rttCamera->setGraphicsContext(graphicsContext1); rttCamera->setViewport(, , width, height);
rttCamera->addChild(node1); viewerParam->addSlave(rttCamera, osg::Matrix::scale(,,),osg::Matrix::identity(),false); //替换
osg::Texture2D *texture2d1 = new osg::Texture2D;
texture2d1->setInternalFormat(GL_RGBA);
rttCamera->attach(osg::Camera::COLOR_BUFFER, texture2d1); group1->addChild(createHUD(texture2d1));
viewerParam->setSceneData(group1);
//viewerParam->setUpViewInWindow(200, 200, 800, 600, 0);
} int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;
osg::ref_ptr<osg::Group> group1 = new osg::Group; osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile(""); //group1->addChild(node1.get());
group1->addChild(createCamera()); createRTT(viewer1);
//viewer1->setSceneData(group1.get());
//viewer1->setUpViewInWindow(200, 200, 800, 600, 0); return viewer1->run();
}

最新文章

  1. 走进vue.js(一)
  2. K近邻分类法
  3. Android Library Project 使用问题总结
  4. 通过MD5排除重复文件
  5. SQL递归
  6. 学习WEb前端开发的需要哪些条件
  7. CAS原理全面分析
  8. Question2Answer初体验
  9. 手动删除文件夹exe病毒并恢复原来文件夹
  10. Encapsulation.
  11. CheckBox控件
  12. JavaScript基础5——关于ECMAscript的函数
  13. [TFRecord格式数据]利用TFRecords存储与读取带标签的图片
  14. canvas---HTML5新特性
  15. 吴恩达机器学习笔记19-过拟合的问题(The Problem of Overfitting)
  16. Entity Framework 6.0 常见异常及解决办法
  17. hexo添加404公益界面
  18. Mysql双主 keepalived+lvs实现mysql高可用性
  19. [UE4]头文件循环依赖C++
  20. 面试7 GC机制中如何判断一个对象是否任在使用

热门文章

  1. LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation
  2. zookeeper学习(2)----zookeeper和kafka的关系
  3. python常用内置方法
  4. 服务器上 MySql 8.0.16创建远程连接账号、获取初始密码、修改密码、重启命令等
  5. 9 loader - 分析webpack调用第三方loader的过程
  6. C#格式化信息,格式化数字、格式化日期
  7. MyBatsi学习
  8. go常量的定义和枚举类型
  9. ajax向服务器发出get和post请求
  10. Mybatis-Plus select不列出全部字段