I have been using ofxOpenVR for a while with some pretty hacky solutions. I think I understand what I am doing wrong but want to clarify somethings about OF’s matrix modes. I have the following code that was developed by Hugues Bruyère @smallfly (https://github.com/smallfly).
ofPushView(); ofSetMatrixMode(OF_MATRIX_PROJECTION); ofLoadMatrix(openVR.getCurrentProjectionMatrix(nEye)); ofSetMatrixMode(OF_MATRIX_MODELVIEW); ofMatrix4x4 currentViewMatrixInvertY = openVR.getCurrentViewMatrix(nEye); currentViewMatrixInvertY.scale(1.0f, -1.0f, 1.0f); ofLoadMatrix(currentViewMatrixInvertY); //I draw stuff here ofPopView();
I don’t quite understand what is going on and what the predefined OF_MATRIX_PROJECTION and OF_MATRIX_MODELVIEW mean. I have been reading up on openGL and assume that
OF_MATRIX_PROJECTION is the equivalent of GL_PROJECTION
OF_MATRIX_MODELVIEW is the equivalent of GL_MODELVIEW
The end of this code leaves me in OF_MATRIX_MODELVIEW mode with the line
That inverts the matrix to match OF’s orientation. I think I should be able to draw a mesh after this using something like this:
ofPushMatrix(); ofMatrix4x4 myMatrixToUseForTransformations; ofMultMatrix( myMatrixToUseForTransformations ); myMesh.draw(); ofPopMatrix();
When I do this however it seems like the transform that I do is fixed to the model view matrix of the eye, not independent.
I am trying to develop this away from a vive at the moment, which is dumb, but I also want to understand the logic. What I think I should do is the following:
ofPushMatrix(); ofMatrix4x4 myMatrixToUseForTransformations; ofMultMatrix( myMatrixToUseForTransformations * currentViewMatrixInvertY ); myMesh.draw(); ofPopMatrix();
I know it is a bit of an abstract question and I will be back with the HMD on Monday, with more questions for sure, but I want to be a little prepared.
I guess the thing that confuses me the most is as each eye is essentially a view, why is the model view matrix loaded for the eye, I would have thought that it should be a projection matrix instead.