--- /dev/null
+#include <stdexcept>
+#include "headtrackingcamera.h"
+#include "motioncontroller.h"
+#include "stereoview.h"
+
+using namespace std;
+
+namespace Msp {
+namespace VR {
+
+MotionController::MotionController():
+ view(0)
+{ }
+
+MotionController::~MotionController()
+{
+ detach_from_view();
+}
+
+void MotionController::attach_to_view(StereoView &v)
+{
+ detach_from_view();
+ view = &v;
+ view->add_controller(*this);
+}
+
+void MotionController::detach_from_view()
+{
+ if(view)
+ view->remove_controller(*this);
+ view = 0;
+}
+
+void MotionController::update_from_matrix(const GL::Matrix &m)
+{
+ matrix = m;
+ if(view)
+ if(const HeadTrackingCamera *head_camera = view->get_head_camera())
+ matrix = head_camera->get_base_matrix()*matrix;
+}
+
+} // namespace VR
+} // namespace Msp