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-19-2014 07:18 PM
LiamDM@SHELL ~ $ sudo apt-get install GoodCodingPractice ERROR: This package is not compatible with your system
04-21-2014 01:12 AM
"LiamDM" wrote:
I believe it MAY (not 100% sure, as I haven't done much experimenting with code similar to yours) be something to do with glm::translate you are using, and how it parses matrices. I believe it may be a problem with vectors and vertexes and the differences between the two, and how you are trying to use vertices in your matrix instead of vectors, try and check this out:
http://stackoverflow.com/questions/18106287/glm-translate-matrix-does-not-translate-the-vector
04-21-2014 01:27 AM
_view.top() left
-----------------------------
1 0 0 0.032
0 1 0 0
0 0 1 0
0 0 0 1
_view.top() right
-----------------------------
1 0 0 -0.032
0 1 0 0
0 0 1 0
0 0 0 1
04-21-2014 02:36 AM
"inDigiNeous" wrote:
// The matrixes for offsetting the projection and view
// for each eye, to achieve stereo effect
glm::vec3 projectionOffset(-projCenterOffset / 2.0f, 0, 0);
04-22-2014 05:27 AM
"jherico" wrote:
The projectionCenterOffset should not be divided by 2. The IPD is the 'distance between the eyes' so each eye gets half of it to properly set up stereo separation. However, the projection center offset is the distance between the viewport center and the lens axis in noramlized device coordinates. There's no reason to divide it. It should have a value of ~0.15.
Sorry for misleading you. I guess I'll have to go and fix my blog post.
// The projection offset and lens offset are both in normalized
// device coordinates, i.e. [-1, 1] on both the X and Y axis
glm::vec3 projectionOffsetVector =
glm::vec3(ovrStereoConfig.GetProjectionCenterOffset() / 2.0f, 0, 0);
eyeArgs[LEFT].projectionOffset =
glm::translate(glm::mat4(), projectionOffsetVector);
eyeArgs[RIGHT].projectionOffset =
glm::translate(glm::mat4(), -projectionOffsetVector);
04-22-2014 10:20 AM
04-22-2014 11:02 AM
"inDigiNeous" wrote:"jherico" wrote:
The projectionCenterOffset should not be divided by 2. The IPD is the 'distance between the eyes' so each eye gets half of it to properly set up stereo separation. However, the projection center offset is the distance between the viewport center and the lens axis in noramlized device coordinates. There's no reason to divide it. It should have a value of ~0.15.
Sorry for misleading you. I guess I'll have to go and fix my blog post.
Thanks for answering Jericho, you have some great examples, they have helped me a lot!
But in your examples, it also has eg. in Example_2_4_HelloRift.cpp:
// The projection offset and lens offset are both in normalized
// device coordinates, i.e. [-1, 1] on both the X and Y axis
glm::vec3 projectionOffsetVector =
glm::vec3(ovrStereoConfig.GetProjectionCenterOffset() / 2.0f, 0, 0);
eyeArgs[LEFT].projectionOffset =
glm::translate(glm::mat4(), projectionOffsetVector);
eyeArgs[RIGHT].projectionOffset =
glm::translate(glm::mat4(), -projectionOffsetVector);
The GetProjectionCenterOffset() is divided by 2.0f, isn't this correct ?
04-22-2014 11:11 AM
"rupy" wrote:
Also are you supposed to move the center of the eyes if the IPD is different than 6,4 cm? It's silly, so many fundamental questions unanswered for almost a year?!
04-22-2014 02:16 PM
"rupy" wrote:
the snowflakes should align in the lenses, you can directly see that wont work looking at your image which is symmetrical
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