From: Mikko Rasa Date: Wed, 5 Oct 2016 23:32:53 +0000 (+0300) Subject: Store the base matrix of HeadTrackingCamera and provice access to it X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c3de3d030e663319289ce39aef1e8b21c3b47084;p=libs%2Fvr.git Store the base matrix of HeadTrackingCamera and provice access to it It will be useful for positioning other tracked devices. --- diff --git a/source/headtrackingcamera.cpp b/source/headtrackingcamera.cpp index 86d6e24..9f4dd5c 100644 --- a/source/headtrackingcamera.cpp +++ b/source/headtrackingcamera.cpp @@ -21,10 +21,12 @@ void HeadTrackingCamera::update_from_matrix(const GL::Matrix &hmd_matrix) columns[0] = compose(right, 0.0f); columns[1] = compose(up, 0.0f); columns[2] = compose(cross(right, up), 0.0f); - columns[3] = compose(base_camera.get_position(), 1.0f); - GL::Matrix matrix = GL::Matrix::from_columns(columns)*hmd_matrix; + columns[3] = compose(base_camera.get_position()+base_camera.get_up_direction()*elevation_offset, 1.0f); + base_matrix = GL::Matrix::from_columns(columns); - set_position(matrix*GL::Vector3()+base_camera.get_up_direction()*elevation_offset); + GL::Matrix matrix = base_matrix*hmd_matrix; + + set_position(matrix*GL::Vector3()); set_look_direction((matrix*GL::Vector4(0, 0, -1, 0)).slice<3>(0)); set_up_direction((matrix*GL::Vector4(0, 1, 0, 0)).slice<3>(0)); diff --git a/source/headtrackingcamera.h b/source/headtrackingcamera.h index c200136..a10c1e1 100644 --- a/source/headtrackingcamera.h +++ b/source/headtrackingcamera.h @@ -10,12 +10,15 @@ class HeadTrackingCamera: public Msp::GL::Camera { protected: const GL::Camera &base_camera; + GL::Matrix base_matrix; float elevation_offset; HeadTrackingCamera(const GL::Camera &); public: virtual ~HeadTrackingCamera() { } + const GL::Matrix &get_base_matrix() const { return base_matrix; } + void set_elevation_offset(float); virtual void reset_tracking() { } virtual void update() = 0;