04-19-2014 03:25 AM
void GeokoneController::setupCamera(OVR::Util::Render::StereoEye eye) {
OVR::Util::Render::StereoConfig *stereoConfig = _oculus->getStereoConfig();
OVR::Util::Render::StereoEyeParams params = stereoConfig->GetEyeRenderParams(eye);
// Set viewport to eye
glViewport(params.VP.x, params.VP.y, params.VP.w, params.VP.h);
// Get the projection center offset,
float projCenterOffset = stereoConfig->GetProjectionCenterOffset();
float ipd = stereoConfig->GetIPD();
float yfov = stereoConfig->GetYFOVRadians();
// The matrixes for offsetting the projection and view
// for each eye, to achieve stereo effect
glm::vec3 projectionOffset(-projCenterOffset / 2.0f, 0, 0);
glm::vec3 viewOffset = glm::vec3(-ipd / 2.0f, 0, 0);
// Negate the left eye versions
if (eye == OVR::Util::Render::StereoEye_Left) {
viewOffset *= -1.0f;
projectionOffset *= -1.0f;
}
// Adjust the view and projection matrixes
// View matrix is translated based on the eye offset
_view.top() = _view.top() * glm::translate(glm::mat4(), viewOffset);
// Projection matrix is calculated based on the fov and viewportAspectRatio
_projection.top() = glm::perspective(yfov, _viewportAspectRatio, PSIOculus::ZNEAR, PSIOculus::ZFAR);
// If we are distorting the views, need to adjust projection with the offset also
if (_renderMode == RENDER_MODE_STEREO_DISTORT) {
_projection.top() = _projection.top() * glm::translate(glm::mat4(), projectionOffset);
}
}
void GeokoneController::drawScene() {
PolyForm *poly;
glm::mat4 view_translation;
glm::vec3 translation = glm::vec3(0.0f);
translation.z = -1.0f;
// Translate
view_translation = glm::translate(glm::mat4(1.0f), translation);
// Then around Z axis to compose the view matrix
_view.top() = _view.top() * view_translation;
// Draw the horizon grid
drawGrid();
// Draw all the polyforms
// Render to the framebuffer texture
// This should render to the first attachment .. that is the
// texture or the color buffer
glUseProgram(_poly_prog);
for (int i=0; i<_container->getNumPolyForms(); i++) {
poly = _container->getPoly(i);
glBindVertexArray(poly->getVao());
drawPolyRecursion(poly);
glBindVertexArray(0);
}
}
// Render to our framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer_id);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Draw left viewpoint
_projection.push(_projection.top());
_view.push(_view.top());
setupCamera(OVR::Util::Render::StereoEye_Left);
drawScene();
_view.pop();
_projection.pop();
// Draw right viewpoint
_projection.push(_projection.top());
_view.push(_view.top());
setupCamera(OVR::Util::Render::StereoEye_Right);
drawScene();
_view.pop();
_projection.pop();
// Render to the screen
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, window_width, window_height); // Render on the whole framebuffer, complete from the lower left corner to the upper right
// Clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Render the buffer texture
glUseProgram(_fs_quad_prog);
// Draw the fullscreen quad containing the texture
glBindVertexArray(_fs_quad_vao);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
_video->flip();
04-22-2014 02:29 PM
04-22-2014 04:49 PM
void GeokoneController::setupCamera(OVR::Util::Render::StereoEye eye) {
OVR::HMDInfo *hmd = _oculus->getHMDInfo();
OVR::Util::Render::StereoConfig *stereoConfig = _oculus->getStereoConfig();
OVR::Util::Render::StereoEyeParams params = stereoConfig->GetEyeRenderParams(eye);
float aspectRatio = float(hmd->HResolution * 0.5f) / float(hmd->VResolution);
float halfScreenDistance = (hmd->VScreenSize / 2.0f);
float yfov = 2.0f * atan(halfScreenDistance / hmd->EyeToScreenDistance);
float viewCenter = hmd->HScreenSize * 0.25f;
float eyeProjectionShift = viewCenter - hmd->LensSeparationDistance * 0.5f;
float projectionCenterOffset = 4.0f * eyeProjectionShift / hmd->HScreenSize;
float halfIPD = hmd->InterpupillaryDistance / 2.0f;
glm::mat4 viewTranslation;
glm::mat4 projTranslation;
// Set viewport to eye
glViewport(params.VP.x, params.VP.y, params.VP.w, params.VP.h);
// The matrixes for offsetting the projection and view
// for each eye, to achieve stereo effect
glm::vec3 projectionOffset = glm::vec3(-projectionCenterOffset, 0.0f, 0.0f);
glm::vec3 viewOffset = glm::vec3(-halfIPD, 0.0f, 0.0f);
// Negate the left eye versions
if (eye == OVR::Util::Render::StereoEye_Left) {
projectionOffset *= -1.0f;
viewOffset *= -1.0f;
}
// Adjust the view and projection matrixes
// View matrix is translated based on the eye offset
glm::mat4 projCenter = glm::perspective(yfov, aspectRatio, PSIOculus::ZNEAR, PSIOculus::ZFAR);
projTranslation = glm::translate(glm::mat4(1.0f), projectionOffset);
_projection.top() = projTranslation * projCenter;
viewTranslation = glm::translate(glm::mat4(1.0f), viewOffset);
_view.top() = viewTranslation * _view.top();
}
04-22-2014 04:51 PM
"inDigiNeous" wrote:
So I am missing this offsetting the left and right sides towards the centre still, although the view matrix IPD and thus the scene rendering for both eyes are correct, they are just placed in the wrong position on the screen.
float lensOffset = 1.0f - (2.0f * ovrHmdInfo.LensSeparationDistance / ovrHmdInfo.HScreenSize);
for_each_eye([&](StereoEye eye){
float eyeLensOffset = (eye == LEFT ? -lensOffset : lensOffset);
projections[eye] = glm::ortho(
-1.0f + eyeLensOffset, 1.0f + eyeLensOffset,
-1.0f / eyeAspect, 1.0f / eyeAspect);
});
04-22-2014 04:55 PM
"inDigiNeous" wrote:
Yay! Got it working.
"inDigiNeous" wrote:
float projectionCenterOffset = 4.0f * eyeProjectionShift / hmd->HScreenSize;
04-27-2014 04:27 AM
"jherico" wrote:"inDigiNeous" wrote:
Yay! Got it working.
congrats!"inDigiNeous" wrote:
float projectionCenterOffset = 4.0f * eyeProjectionShift / hmd->HScreenSize;
You should find that the final value of projectionCenterOffset is ~0.15, and is the same as the value that you get from the OVR function that returns the projection center offset.
Did this answer your question? If it didn’t, use our search to find other topics or create your own and other members of the community will help out.
If you need an agent to help with your Meta device, please contact our store support team here.
Having trouble with a Facebook or Instagram account? The best place to go for help with those accounts is the Facebook Help Center or the Instagram Help Center. This community can't help with those accounts.
Check out some popular posts here:
Getting Help from the Meta Quest Community
Tips and Tricks: Charging your Meta Quest Headset