Reputation: 21
I am programming an application with openvr and opengl and I want the camera to move in the direction it is looking at. So when you put on the hmd and look in a certain direction the virtual camera should fly in that direction so you can move around.
So the position of the hmd is provided by openvr with a call to VRCompositor()->WaitGetPoses
and this should be analogous to the inverse of the view matrix, so if I extract the third coulmn of the matrix I should get the view direction and then I can translate my model matrix along that direction to move the scene.
m_mat4HMDPose = VRCompositor()->WaitGetPoses;
m_mat4HMDPose = inverse(m_mat4HMDPose);
vec4 direction = m_mat4HMDPose * vec4(0.0, 0.0, -1.0, 0.0);
model = translate(model, vec3(direction.x, direction.y, direction.z));
This seems to be not completly wrong, but this does not work for all directions. Sometimes I look to the left but I am translated to the right, and vice versa. This also happens with up/down, and the translation will change when Im rotating the hmd around the z-axis.
I also tried to follow this tutorial https://www.youtube.com/watch?v=QREKO1sf8b8 for unity, and I got the movement working with unity, but I cannot convert the code back to run with my opengl application. I tried to implement the euler and quaternion conversion, but with no success.
I am feeling that I need to transform my direction vector with an additional matrix, so it will point in the right direction all the time, but I cannot figure out how o_o
Does anyone know what the mistake is, or knows a way how to implement this movement?
Upvotes: 1
Views: 582
Reputation: 21
okay I found the mistake I need to multiply the direction with the inverse of the hmd pose, so vec4 direction = inverse(m_mat4HMDPose) * vec4(0.0, 0.0, 1.0, 0.0);
Upvotes: 1