Oculus Rift with One Eye Open [Solved]

I’m attempting to document (via screen capture) a project that I made earlier this year using a Rift, but I’m struggling to finding a straight forward approach for drawing the perspective of a single eye to the screen. Have any OF users done this already?

The DK2 addon stores a separate matrix and viewport for each eye and the function ofxOculusDK2::setupEyeParams() is the place where all the magic happens:

ofViewport(toOf(eyeRenderViewport[0]));

ofSetMatrixMode(OF_MATRIX_PROJECTION);
ofLoadIdentityMatrix();
ofLoadMatrix( getProjectionMatrix(0) );

ofSetMatrixMode(OF_MATRIX_MODELVIEW);
ofLoadIdentityMatrix();
ofLoadMatrix( getViewMatrix(0) );

I’ve tried adding a custom function to generate a new projection matrix and viewport based on the dimensions of my window, but I can’t wrap my head around the DK2 library’s FOV structure (ovrFovPort) that’s used to calculate the projection matrix for each eye. According to the source code, the FOV is structured “in tangent of the angle units.” This FOV appears to different from the glFrustum calculation from times of past.

/// Field Of View (FOV) in tangent of the angle units.
/// As an example, for a standard 90 degree vertical FOV, we would
/// have: { UpTan = tan(90 degrees / 2), DownTan = tan(90 degrees / 2) }.
typedef struct ovrFovPort_
{
    /// The tangent of the angle between the viewing vector and the top edge of the field of view.
    float UpTan;
    /// The tangent of the angle between the viewing vector and the bottom edge of the field of view.
    float DownTan;
    /// The tangent of the angle between the viewing vector and the left edge of the field of view.
    float LeftTan;
    /// The tangent of the angle between the viewing vector and the right edge of the field of view.
    float RightTan;
} ovrFovPort;

Maybe there’s a better approach than this? Any advice would be greatly appreciated!

1 Like

Figured it out … it turned out I wasn’t building my perspective matrix properly.

void ofxOculusDK2::setupEyeParamsMono(){
	
	ovrRecti monoViewPort;
	monoViewPort.Pos  = Vector2i(0,0);
    monoViewPort.Size = Sizei(ofGetWidth(), ofGetHeight());
	
	if(bUseBackground){
		glPushAttrib(GL_ALL_ATTRIB_BITS);
		glDisable(GL_LIGHTING);
		ofDisableDepthTest();
		backgroundTarget.getTextureReference().draw(toOf(monoViewPort));
		glPopAttrib();
	}
    
    // xxx mattebb
    ovrHmd_GetEyePoses(hmd, frameIndex, hmdToEyeViewOffsets, headPose, NULL);

    ofViewport(toOf(monoViewPort));
    
    ofMatrix4x4 pm;
    pm.makePerspectiveMatrix(45.0, float(ofGetWidth())/ofGetHeight(), 0.1, 10000.0f);
    pm.scale(-1, 1.0, 1.0);

	ofSetMatrixMode(OF_MATRIX_PROJECTION);
	ofLoadIdentityMatrix();
	ofLoadMatrix( pm );
    
	ofSetMatrixMode(OF_MATRIX_MODELVIEW);
	ofLoadIdentityMatrix();
    ofLoadMatrix( getViewMatrix(ovrEye_Left) );
    
    orientationMatrix = getOrientationMat();
}