bjornblissing / osgoculusviewer

An OsgViewer with support for the Oculus Rift
Other
106 stars 67 forks source link

Wrong order of matrix multiplication ? #26

Closed west036 closed 9 years ago

west036 commented 9 years ago

Hi bjornblissing, Observing objects at close range (less than 1 meters), and rotating head (ear to shoulder), can cause the eyes to misfocus.I found in the code of the matrix multiplication sequence of head rotation and eye offset may be wrong, according to the following code modifications, the problem disappears. This problem also exists in OculusCompositeViewer and OculusViewConfig. Sorry about my English.

void OculusViewer::traverse(osg::NodeVisitor& nv) { if (!m_configured) { configure(); }

if (m_configured) {
    m_device.get()->updatePose(m_swapCallback->frameIndex());
    osg::Vec3 position = m_device.get()->position();
    osg::Quat orientation = m_device.get()->orientation();
    osg::Matrix hmdMatrix;
    hmdMatrix.makeRotate(orientation);
    hmdMatrix.preMultTranslate(position);
    osg::Matrix viewOffsetLeft = hmdMatrix*m_device.get()->viewMatrixLeft();
    osg::Matrix viewOffsetRight = hmdMatrix*m_device.get()->viewMatrixRight();
    //osg::Matrix viewOffsetLeft = m_device.get()->viewMatrixLeft();
    //osg::Matrix viewOffsetRight = m_device.get()->viewMatrixRight();
    //viewOffsetLeft.preMultTranslate(position);
    //viewOffsetRight.preMultTranslate(position);
    //viewOffsetLeft.postMultRotate(orientation);
    //viewOffsetRight.postMultRotate(orientation);
    // Nasty hack to update the view offset for each of the slave cameras
    // There doesn't seem to be an accessor for this, fortunately the offsets are public
    m_view->findSlaveForCamera(m_cameraRTTLeft.get())->_viewOffset = viewOffsetLeft;
    m_view->findSlaveForCamera(m_cameraRTTRight.get())->_viewOffset = viewOffsetRight;
}
osg::Group::traverse(nv);

}

bjornblissing commented 9 years ago

You are right. Nice catch!

The effect was really visible using the dumptruck model. The only thing needed was to zoom in on one of the rear view mirrors and tilt your head and the effect was clearly visible.

I will fix this right away.