Exemplo n.º 1
0
/*!
Applies the view transform to the modelview matrix depending on the eye:
eye=-1 for left, eye=1 for right
*/
void SLCamera::setView(const SLEye eye)
{  
   SLSceneView* sv = SLScene::current->activeSV();
   
   if (eye == centerEye)
   {  stateGL->modelViewMatrix.identity();
      stateGL->modelViewMatrix.multiply(_vm); 
   } 
   else // stereo viewing
   {
      if (_projection == stereoSideBySideD)
      {  
         // half interpupilar distance
         _eyeSeparation = sv->oculus()->eyeSeparation();
         SLfloat halfIPD = (SLfloat)eye * _eyeSeparation * -0.5f;

         // get the oculus orientation
         SLMat4f rotation(sv->oculus()->orientation().toMat4());
         SLMat4f vmEye(SLMat4f(halfIPD, 0.0f, 0.f) * rotation * _vm);
         stateGL->modelViewMatrix = vmEye;
         stateGL->viewMatrix = vmEye;
      }
      else
      {
         // Get central camera vectors eye, lookAt, lookUp out of the view matrix vm
         SLVec3f EYE, LA, LU, LR;
         _vm.lookAt(&EYE, &LA, &LU, &LR);
   
         // Shorten LR to half of the eye dist (eye=-1 for left, eye=1 for right)
         LR *= _eyeSeparation * 0.5f * (SLfloat)eye;
      
         // Set the OpenGL view matrix for the left eye
         SLMat4f vmEye;
         vmEye.lookAt(EYE+LR, EYE + _focalDist*LA+LR, LU);
         stateGL->modelViewMatrix = vmEye;
         stateGL->viewMatrix = vmEye;
      }
   } 
}
Exemplo n.º 2
0
/*!
Applies the view transform to the modelview matrix depending on the eye:
eye=-1 for left, eye=1 for right
*/
void SLCamera::setView(SLSceneView* sv, const SLEye eye)
{  
    SLScene* s = SLScene::current;
   
    SLMat4f vm = updateAndGetWMI();

    if (eye == centerEye)
    {   _stateGL->modelViewMatrix.identity();
        _stateGL->viewMatrix.setMatrix(vm);
    } 
    else // stereo viewing
    {
        if (_projection == stereoSideBySideD)
        {  
            // half interpupilar disqtance
            //_eyeSeparation = s->oculus()->interpupillaryDistance(); update old rift code
            SLfloat halfIPD = (SLfloat)eye * _eyeSeparation * -0.5f;
            
            SLMat4f trackingPos;
            if (_useDeviceRot)
            {
                // get the oculus or mobile device orientation
                SLQuat4f rotation;
                if (s->oculus()->isConnected())
                {
                    rotation = s->oculus()->orientation(eye);
                    trackingPos.translate(-s->oculus()->position(eye));
                }
                else rotation = sv->deviceRotation();

                SLfloat rotX, rotY, rotZ;
                rotation.toMat4().toEulerAnglesZYX(rotZ, rotY, rotX);
                //SL_LOG("rotx : %3.1f, roty: %3.1f, rotz: %3.1f\n", rotX*SL_RAD2DEG, rotY*SL_RAD2DEG, rotZ*SL_RAD2DEG);
                SLVec3f viewAdjust = s->oculus()->viewAdjust(eye) * _unitScaling;
                SLMat4f vmEye(SLMat4f(viewAdjust.x, viewAdjust.y, viewAdjust.z) * rotation.inverted().toMat4() * trackingPos * vm);
                _stateGL->modelViewMatrix = vmEye;
                _stateGL->viewMatrix = vmEye;
            } 
            else
            {      
                SLMat4f vmEye(SLMat4f(halfIPD, 0.0f, 0.f) * vm);
                _stateGL->modelViewMatrix = vmEye;
                _stateGL->viewMatrix = vmEye;
            }
        }
        else
        {
            // Get central camera vectors eye, lookAt, lookUp out of the view matrix vm
            SLVec3f EYE, LA, LU, LR;
            vm.lookAt(&EYE, &LA, &LU, &LR);
   
            // Shorten LR to half of the eye dist (eye=-1 for left, eye=1 for right)
            LR *= _eyeSeparation * 0.5f * (SLfloat)eye;
      
            // Set the OpenGL view matrix for the left eye
            SLMat4f vmEye;
            vmEye.lookAt(EYE+LR, EYE + _focalDist*LA+LR, LU);
            _stateGL->modelViewMatrix = vmEye;
            _stateGL->viewMatrix = vmEye;
        }
    } 
}