[osg-users] Left handed scene

Antoine Rennuit antoinerennuit at hotmail.com
Tue Aug 2 05:36:06 PDT 2016


Hi all,


I have a QtWidget app which I am converting to QtQuick. My app works well with QtWidget but after transitioning to QtQuick I have observed that the whole scene is now left handed: not only the geometry is left handed (the z axis is down when it should be up - check joined file) but also the TrackballManipulator behavior (e.g. when I pan up with the mouse the scene goes down, and it's the same opposite reaction for rotate).


I do not understand where this is coming from. I was able to easily put the geometry back right handed using a scale -1 on Z but I should not have to do that and this does not solve the TrackballManipulator behavior.


I have used https://bitbucket.org/leon_manukyan/qtquick2osgitem as a starting point and my code does the following:


I have a RendererImpl class, created by an OsgItem and which is responsible for maintaining the osgViewer::Viewer and the osgViewer::GraphicsWindow, here is its init method:


void RendererImpl::init()
{
    m_sceneRoot = new osg::Group();

    m_viewer = new osgViewer::Viewer;
    m_viewer->setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
    m_viewer->setSceneData(m_sceneRoot);
    m_viewer->setCameraManipulator(new osgGA::TrackballManipulator);
    m_viewer->getCameraManipulator()->setHomePosition(osg::Vec3d(4.0, -4.0, 2.0), osg::Vec3d(0.0, 0.0, 1.0), osg::Vec3d(0.0, 0.0, 1.0));
    m_viewer->home();

    m_sceneRoot->addChild(setupLight());
    m_sceneRoot->addChild(setupGrid(6.0f, 2.0f));

    m_window = new FrameBufferWindow(this);
    updateSize();

    osg::Camera* camera = m_viewer->getCamera();
    camera->setGraphicsContext( m_window.get() );

    camera->setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
}


And its update method on window size change:


void RendererImpl::updateSize()
{
    m_window->getEventQueue()->windowResize(0, 0, osgItem().width(), osgItem().height() );
    m_window->resized(0, 0, osgItem().width(), osgItem().height());

    osg::Camera& camera = *m_viewer->getCamera();
    const osg::GraphicsContext::Traits& t = *m_window->getTraits();
    camera.setViewport( 0, 0, t.width, t.height );
    double aspectRatio = t.height ? (double)t.width / (double)t.height : 1.0;
    camera.setProjectionMatrixAsPerspective(30.0f, aspectRatio, 1.0f, 10000.0f );
}


And I have an item which streams the events to the window, e.g.:


void OsgItem::mouseMoveEvent(QMouseEvent *event)
{
    m_renderer->m_window->getEventQueue()->mouseMotion(event->x(), event->y());

    update();
}


Does anyone have an idea of what is wrong in my code? I have looked for days and I am stuck!


Thanks,


Antoine.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160802/b6196c1b/attachment-0003.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot from 2016-08-02 14:25:53.png
Type: image/png
Size: 7972 bytes
Desc: Screenshot from 2016-08-02 14:25:53.png
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160802/b6196c1b/attachment-0003.png>


More information about the osg-users mailing list