Forum Discussion
Jossos2
12 years agoHonored Guest
Perspective/Matrices issues
Hello, I'm having some real trouble getting the perspective right.
First of all, looking straight ahead, I am looking like 45 degrees down in the scene. No idea why.
Secondly, the perspective is all fucked. as I look around the world distorts like crazy. It seems to be sorta treating each eye like 16x9, when they should be 8x9 if you get what i mean.
Third, Is there a way to get raw degrees of FOV for each eye? the value I get is 1.4 something, i dont understand what that is.
Fourth: How do I get rid of that stupid health and safety message?
And I can swap the value from this with this:
And I get the same result.
This is the function I use, and for some reason, I get this horrid skewing of the scene.
My render function:
This image is me looking STRAIGHT AHEAD, and for some reason I'm looking 45 degrees downward. If i take out all of the translations, this is still the case.

I don't even care about how the oculus vr mode fucks up my model, I just want the matrices to work, but I can't figure out what's wrong exactly.
Any help is appreciated
First of all, looking straight ahead, I am looking like 45 degrees down in the scene. No idea why.
Secondly, the perspective is all fucked. as I look around the world distorts like crazy. It seems to be sorta treating each eye like 16x9, when they should be 8x9 if you get what i mean.
Third, Is there a way to get raw degrees of FOV for each eye? the value I get is 1.4 something, i dont understand what that is.
Fourth: How do I get rid of that stupid health and safety message?
MATRIX4f VRDATA::GetEyeProjMatrix(const int& eyeIndex)
{
ovrEyeType eye = hmd->EyeRenderOrder[eyeIndex];
Matrix4f matr = ovrMatrix4f_Projection(hmd->DefaultEyeFov[eyeIndex], 0.01f, 10000.0f, 1);
return ConvertOVRMatrix(matr);
}
And I can swap the value from this with this:
m_pipeline.Perspective(100.0f, (float)(g_graphicsManager->GetWidth() / 2.0f) / (float)g_graphicsManager->GetHeight(), 0.01f, 1000.0f);
And I get the same result.
This is the function I use, and for some reason, I get this horrid skewing of the scene.
My render function:
ovrPosef eyeRenderPose[2];
for (int i = 0; i < 2; i++)
{
ovrEyeType eye = g_graphicsManager->m_vrData->hmd->EyeRenderOrder[i];
glViewport(eye == ovrEye_Left ? 0 : g_graphicsManager->GetFBWidth() / 2,
0,
g_graphicsManager->GetFBWidth() / 2,
g_graphicsManager->GetFBHeight());
m_pipeline.LoadIdentity();
m_pipeline.MatrixMode(PROJECTION_MATRIX);
//m_pipeline.Perspective(g_graphicsManager->m_vrData->GetEyeProjMatrix(i));
m_pipeline.Perspective(100.0f, (float)(g_graphicsManager->GetWidth() / 2.0f) / (float)g_graphicsManager->GetHeight(), 0.01f, 1000.0f);
eyeRenderPose[eye] = ovrHmd_GetEyePose(g_graphicsManager->m_vrData->hmd, eye);
m_pipeline.MatrixMode(VIEW_MATRIX);
m_pipeline.AddMatrix(g_graphicsManager->m_vrData->GetRotationMatrix(i));
m_pipeline.Translate(g_graphicsManager->m_vrData->eyeRenderDesc[eye].ViewAdjust.x,
g_graphicsManager->m_vrData->eyeRenderDesc[eye].ViewAdjust.y,
g_graphicsManager->m_vrData->eyeRenderDesc[eye].ViewAdjust.z);
m_pipeline.Translate(-eyeRenderPose[eye].Position.x,
-eyeRenderPose[eye].Position.y,
-eyeRenderPose[eye].Position.z);
m_pipeline.Translate(0, -ovrHmd_GetFloat(g_graphicsManager->m_vrData->hmd, OVR_KEY_EYE_HEIGHT, 1.65), 0);
RenderModels();
}
g_graphicsManager->UnbindFramebuffer();
//glViewport(0, 0, g_graphicsManager->GetWidth(), g_graphicsManager->GetHeight());
ovrHmd_EndFrame(g_graphicsManager->m_vrData->hmd, eyeRenderPose, &g_graphicsManager->m_vrData->eyeTexture[0].Texture);
assert(glGetError() == GL_NO_ERROR);
This image is me looking STRAIGHT AHEAD, and for some reason I'm looking 45 degrees downward. If i take out all of the translations, this is still the case.

I don't even care about how the oculus vr mode fucks up my model, I just want the matrices to work, but I can't figure out what's wrong exactly.
Any help is appreciated
5 Replies
- AnonymousHello,
Is your AddMatrix function do a multiply internally ? Also, you may have to transpose the matrix ovrMatrix4f_Projection gives to you if you want column-major matrices. - Jossos2Honored Guest
"ockiller" wrote:
Hello,
Is your AddMatrix function do a multiply internally ? Also, you may have to transpose the matrix ovrMatrix4f_Projection gives to you if you want column-major matrices.
Add matrix with the rotation does the same thing as glRotate, just multiplies.
Transpose turns the whole view into gibberish - tmason101Honored GuestI wish I could help you but I don't know what libraries/SDKs you are using besides the Rift's SDK.
Also, is that fixed function pipeline for OpenGL? - Jossos2Honored Guest
"tmason101" wrote:
I wish I could help you but I don't know what libraries/SDKs you are using besides the Rift's SDK.
Also, is that fixed function pipeline for OpenGL?
#include <GL/glew.h>
#include <SDL2/SDL.h>
I've made my own matrices functions that mimic the old glRotate/Translate functions. - machineelfHonored Guest
"Jossos2" wrote:
"tmason101" wrote:
I wish I could help you but I don't know what libraries/SDKs you are using besides the Rift's SDK.
Also, is that fixed function pipeline for OpenGL?
#include <GL/glew.h>
#include <SDL2/SDL.h>
I've made my own matrices functions that mimic the old glRotate/Translate functions.
Hmmm, I'll try and look at your code if I have time tomorrow but here are some pointers:- You need to get and use the perspective matrix from Oculus and then simply convert it from it's DirectX form to the OpenGL form. Take a look at my example I posted earlier on how to do this.
- For the view matrix, which is what I suspect your problem is in regards to looking "down" versus looking straight ahead, there is a similar process, somewhat. You need to:
- have a matrix that represents the camera's position
- get the matrix that represents the "orientation" of the HMD
- get a matrix that represents the eye corrected position from an identity matrix
- and then multiply the matrices in a certain order
- My example posted earlier also shows this. Note that my example doesn't cover moving around the world, just the movement of the headset.
I use GLM, if you are just starting out I recommend you use a math library to make things easier and then once you have something solid you can write your own math libraries.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 11 months ago
- 2 years ago
- 3 months ago
- 2 years ago
- 2 years ago