1

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?

  • No idea what you're actually using here, but [openvr's `WaitGetPoses()`](https://github.com/ValveSoftware/openvr/wiki/IVRCompositor::WaitGetPoses) does not return a matrix. It is also unclear what your matrix and vector types are, and which conventions they follow. – derhass Feb 13 '20 at 15:46
  • ok sorry, so `vr::VRCompositor()->WaitGetPoses(m_rTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, NULL, 0 );` gives you the `TrackedDevicePose_t` which is a struct that holds the `HmdMatrix34_t mDeviceToAbsoluteTracking`. (see https://github.com/ValveSoftware/openvr/wiki/IVRCompositor::WaitGetPoses for reference). yeah sorry I should have been more clear about that but I am just using pseudo code to communicate my idea to solve the problem. So if you have any idea how to gererally tackle this problem I would be very grateful :) – Steven Schürstedt Feb 14 '20 at 10:17

1 Answers1

1

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);