Exemplo n.º 1
0
void OsgViewerBase::setMainCamera(CameraBase* camera)
{
	_mainCamera = camera;
	_mainCamera->setGraphicsContext( getGraphicsWindow() );
	this->setCamera(_mainCamera);

	/* scene data必须在设置完相机后设置 */
	this->setSceneData(_sceneData);
}
Exemplo n.º 2
0
ViewerQT::ViewerQT(const QGLFormat & format, QWidget * parent, const char * name, 
				   const QGLWidget * shareWidget, WindowFlags f)
: AdapterWidget(format, parent, shareWidget, f)
, _ucsDL(-1)
{
    getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
    getCamera()->setGraphicsContext(getGraphicsWindow());

    setThreadingModel(SingleThreaded);

    connect(&_timer, SIGNAL(timeout()), this, SLOT(updateGL()));
    _timer.start(10);
}
Exemplo n.º 3
0
ViewerQT::ViewerQT(QWidget * parent, const char * name, const QGLWidget * shareWidget, WindowFlags f):
    AdapterWidget( parent, name, shareWidget, f)
{
    setCamera(this->getCamera());
    // Camera
     getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
     getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(width())/static_cast<double>(height()), 1.0f, 10000.0f);
     getCamera()->setGraphicsContext(getGraphicsWindow());
    getCamera()->setClearColor(osg::Vec4d(51/255.0, 51/255.0, 102/255.0, 0));
    getCamera()->setViewMatrix(osg::Matrix::identity());
//   // getCamera()->setProjectionMatrixAsOrtho2D(0,1280,0,1024);
//   // getCamera()->setClearColor(osg::Vec4d(1, 1, 1, 0));
//    getCamera()->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
//    getCamera()->setClearMask(GL_DEPTH_BUFFER_BIT);
//    getCamera()->setRenderOrder(osg::Camera::POST_RENDER);
//    getCamera()->setUpdateCallback(new AxisCameraUpdateCallback());
//    QString axespath = QCoreApplication::applicationDirPath() + "/axes.osg";
//    osg::Node* axes = osgDB::readNodeFile(axespath.toLatin1().data());
//    qDebug()<<axes->asGroup()->getNumChildren();
//    qDebug()<<axespath;
//    getCamera()->addChild(axes);
    // Trackball
    m_rpTrackball = new osgGA::TrackballManipulator;
  //  setCameraManipulator(m_rpTrackball.get());
    addEventHandler(new osgGA::StateSetManipulator(getCamera()->getOrCreateStateSet()));
   // addEventHandler(new osgViewer::WindowSizeHandler);
    addEventHandler(new osgViewer::StatsHandler);
    // Scene root
    m_rpSceneGroupRoot = new osg::Group;
    setSceneData(m_rpSceneGroupRoot.get());
    osg::Camera* camera = createHUD();
    addSlave(camera, false);
    m_rpSceneGroupRoot->addChild(camera);
    osgText::Text* text = new osgText::Text;
    m_rpSceneGroupRoot->addChild( createHUD_viewPoint( text));//加入HUD文字
//    pickHandler = new PickHandler;
//    addEventHandler(pickHandler);

    addEventHandler(new PickDragHandler(text));
    osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator =
            new osgGA::KeySwitchMatrixManipulator;
    keyswitchManipulator->addMatrixManipulator(1,"Trackball",new osgGA::TrackballManipulator());
    keyswitchManipulator->addMatrixManipulator(2,"Flight",new osgGA::FlightManipulator());
    keyswitchManipulator->addMatrixManipulator(3,"Drive",new osgGA::DriveManipulator());
    keyswitchManipulator->addMatrixManipulator(4,"Terrain",new osgGA::TerrainManipulator());
    setCameraManipulator(keyswitchManipulator.get());
    setThreadingModel(osgViewer::Viewer::SingleThreaded);

    connect(&_timer, SIGNAL(timeout()), this, SLOT(updateGL()));
    _timer.start(10);
}
Exemplo n.º 4
0
QOSG::ProjectiveARViewer::ProjectiveARViewer( QWidget* parent , const char* name , const QGLWidget* shareWidget , WindowFlags f , osgViewer::Viewer* viewerPerspective ):
    AdapterWidget( parent, name, shareWidget, f )
{
    this->viewerPerspective = viewerPerspective;

    appConf = Util::ApplicationConfig::get();

    renderCamera = new osg::Camera;
    useGraph = true;

    // setup Graph (radius 0.5m)
    graphPos = osg::Vec3d(-0.75, -0.25, 0.25);
    graphRadius = 0.5;

    // setup Viewer
    viewerPos = osg::Vec3d(-1.88, -0.95, 1.72);
    viewerDir = osg::Vec3d( -0.75, 0, 0.238 ) - viewerPos;
    viewerFOV = 90;

    this->setSceneData(createProjectorScene());

    // setup Projector
    projectorPos = osg::Vec3d( -0.665, -1.345, 0.825);
    projectorDir = osg::Vec3d( -0.75, 0, 0.238 ) - projectorPos;
    projectorFOV = 30;

    getCamera()->setViewport( new osg::Viewport( 0,0,width(),height() ) );
    getCamera()->setProjectionMatrixAsPerspective( projectorFOV, static_cast<double>( width() )/static_cast<double>( height() ), 0.01, appConf->getValue( "Viewer.Display.ViewDistance" ).toFloat() );
    getCamera()->setGraphicsContext( getGraphicsWindow() );
    getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );

    getCamera()->setClearColor( osg::Vec4( 0, 0, 0, 1 ) );
    getCamera()->setViewMatrixAsLookAt( projectorPos, projectorDir + projectorPos, osg::Vec3d( 0, 0, 1 ) );


    addEventHandler( new osgViewer::StatsHandler );

    setThreadingModel( osgViewer::ViewerBase::SingleThreaded );

    connect( &_timer, SIGNAL( timeout() ), this, SLOT( updateGL() ) );

    _timer.start( 10 );
}
Exemplo n.º 5
0
QOSG::ViewerQT::ViewerQT( QWidget* parent , const char* name , const QGLWidget* shareWidget , WindowFlags f , Vwr::CoreGraph* cg ):
	AdapterWidget( parent, name, shareWidget, f )
{
	this->cg = cg;
	cg->setCamera( this->getCamera() );

	this->mIsClicAruco=false;

	appConf = Util::ApplicationConfig::get();

	osg::DisplaySettings::instance()->setStereo( appConf->getValue( "Viewer.Display.Stereoscopic" ).toInt() );
	osg::DisplaySettings::instance()->setStereoMode( osg::DisplaySettings::ANAGLYPHIC );

	getCamera()->setViewport( new osg::Viewport( 0,0,width(),height() ) );
	getCamera()->setProjectionMatrixAsPerspective( 60, static_cast<double>( width() )/static_cast<double>( height() ), 0.01, appConf->getValue( "Viewer.Display.ViewDistance" ).toFloat() );
	getCamera()->setGraphicsContext( getGraphicsWindow() );
	getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );

	manipulator = new Vwr::CameraManipulator( cg );
	QObject::connect( manipulator, SIGNAL( sendMouseRotation( osg::Quat ) ),
					  cg, SLOT( updateGraphRotByMouse( osg::Quat ) ) );
	QObject::connect( manipulator, SIGNAL( sendFaceDetRotation( osg::Quat ) ),
					  cg, SLOT( updateGraphRotByFaceDet( osg::Quat ) ) );

	pickHandler = new Vwr::PickHandler( manipulator, cg );

	addEventHandler( new osgViewer::StatsHandler );
	addEventHandler( pickHandler );
	setCameraManipulator( manipulator );

	// Gloger: background to white color after disabling skybox
	getCamera()->setClearColor( osg::Vec4( 0, 0, 0, 1 ) );
	getCamera()->setViewMatrixAsLookAt( osg::Vec3d( -10, 0, 0 ), osg::Vec3d( 0, 0, 0 ), osg::Vec3d( 0, 1, 0 ) );

	setThreadingModel( osgViewer::ViewerBase::SingleThreaded );

	connect( &_timer, SIGNAL( timeout() ), this, SLOT( updateGL() ) );

	_timer.start( 10 );
}
Exemplo n.º 6
0
ViewerQOSG::ViewerQOSG(QWidget *parent, const char *name, WindowFlags f):
    QOSGWidget (parent, name, f) {

    getCamera()->setViewport(new osg::Viewport(0,0,width(),height()));
    getCamera()->setProjectionMatrixAsPerspective(
        30.0f,
        static_cast<double>(width())/static_cast<double>(height()),
        1.0f,
        10000.0f);
#if 0
#endif

    getCamera()->setGraphicsContext(getGraphicsWindow());

#if 0
    setThreadingModel(osgViewer::Viewer::SingleThreaded);

    connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));

    _timer.start(10);
#endif
}