码迷,mamicode.com
首页 > 其他好文 > 详细

osg::Camera 参数修改

时间:2019-06-28 22:43:55      阅读:344      评论:0      收藏:0      [点我收藏+]

标签:xtu   env   getc   ble   gen   win32   group   inter   dia   

 

#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 <osgGA/TrackballManipulator>
#include <osgGA/GUIEventHandler>
#include <osgGA/CameraManipulator>
#include <osgGA/StandardManipulator>
#include <osgGA/OrbitManipulator>
#include <osgGA/TrackballManipulator>

#include <osgUtil/IntersectionVisitor>
#include <osgUtil/LineSegmentIntersector>

osg::ref_ptr<osg::Group> createCameras(osg::ref_ptr<osg::Node> node1)
{
    
    osg::ref_ptr<osg::Group> group1 = new osg::Group;
    unsigned int width, height;
    

    osg::ref_ptr<osg::Camera> camera1 = new osg::Camera;
    //osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\\参考手册\\BIM\\osg\\build20190628.osgb");

    //camera1->setGraphicsContext(graphics1);
    camera1->addChild(node1);
    camera1->setViewport(0, 0, 400, 300);
    camera1->setClearColor(osg::Vec4(1.0, 1.0, 1.0, 0.0));
    camera1->setName("camera1");

    osg::ref_ptr<osg::Camera> cameraRight = new osg::Camera;
    osg::Vec3d eyeRight, centerRight, upRight;

    //修改相机参数
    eyeRight = osg::Vec3d(0.0, 0.0, 0.0);
    centerRight = osg::Vec3d(0.0, 1.0, 0.0);
    upRight = osg::Vec3d(0.0, 0.0, 0.0);
    
    cameraRight->addChild(node1);
    cameraRight->setViewport(402, 0, 400, 300);
    cameraRight->setClearColor(osg::Vec4(1.0, 1.0, 1.0, 0.0));
    cameraRight->setName("camera2");

    //viewer->getCamera()->setViewMatrixAsLookAt(eye, center, up);
    //cameraRight->setViewMatrixAsLookAt(eyeRight, centerRight, upRight);
    cameraRight->setViewMatrix(osg::Matrix::rotate(osg::DegreesToRadians(-90.0),0.0,0.0,1.0));

    //viewer1->addSlave(camera1.get());
    group1->addChild(camera1.get());
    group1->addChild(cameraRight.get());

    return group1;
}


int main()
{
    osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;
    osg::ref_ptr<osg::Group> group1 = new osg::Group;
    //osg::ref_ptr<osg::Camera> camera1 = new osg::Camera;

    osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\\参考手册\\BIM\\osg\\build20190628.osgb");
    //osg::ref_ptr<osg::Node> node2 = osgDB::readNodeFile("D:\\参考手册\\BIM\\osg\\build20190628.osgb");

    //camera1->addChild(node1);
    //camera1->setViewport(0, 0, 300, 220);
    //camera1->setClearColor(osg::Vec4(0.0,0.0,0.0,0.0));

    group1->addChild(node1.get());
    //group1->addChild(camera1.get());
    group1->addChild(createCameras(node1));
    
    //createCameras1(node1, viewer1);

    viewer1->setSceneData(group1.get());
    //createCamera(viewer1);

    viewer1->setUpViewInWindow(200, 200, 800, 500, 0);

    viewer1->run();
}

 

技术图片

技术图片

 

osg::Camera 参数修改

标签:xtu   env   getc   ble   gen   win32   group   inter   dia   

原文地址:https://www.cnblogs.com/herd/p/11104964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!