Reconstruct base camera object matrix with priority on up vector
authorMikko Rasa <tdb@tdb.fi>
Mon, 3 Oct 2016 13:54:30 +0000 (16:54 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 3 Oct 2016 13:54:30 +0000 (16:54 +0300)
In VR it's imperative that the camera object matches reality and some
applications may have a non-horizontal look vector.  The up vector on
the other hand should always point up in the user's immediate frame of
reference.

source/headtrackingcamera.cpp

index 42eedd5d90caa21543776a47d95049069b99e587..a296639315634c0f2f4feb689dd988e81746bd49 100644 (file)
@@ -15,7 +15,14 @@ void HeadTrackingCamera::set_elevation_offset(float o)
 
 void HeadTrackingCamera::update_from_matrix(const GL::Matrix &hmd_matrix)
 {
-       GL::Matrix matrix = base_camera.get_object_matrix()*hmd_matrix;
+       const GL::Vector3 &up_dir = base_camera.get_up_direction();
+       GL::Vector3 right_dir = normalize(cross(base_camera.get_look_direction(), up_dir));
+       GL::Vector4 columns[4];
+       columns[0] = compose(right_dir, 0.0f);
+       columns[1] = compose(up_dir, 0.0f);
+       columns[2] = compose(cross(right_dir, up_dir), 0.0f);
+       columns[3] = compose(base_camera.get_position(), 1.0f);
+       GL::Matrix matrix = GL::Matrix::from_columns(columns)*hmd_matrix;
 
        set_position(matrix*GL::Vector3()+base_camera.get_up_direction()*elevation_offset);
        set_look_direction((matrix*GL::Vector4(0, 0, -1, 0)).slice<3>(0));