Commit ebb127e3 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

BUG: Fix camera rotation and translational offset

Separates camera rotation and translational offset with that of the device
parent 50aec694
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
namespace imstk namespace imstk
{ {
void void
CameraController::setOffsetUsingCurrentCameraPose() CameraController::setOffsetUsingCurrentCameraPose()
{ {
auto pos = m_camera.getPosition(); auto pos = m_camera.getPosition();
...@@ -59,10 +59,38 @@ CameraController::runModule() ...@@ -59,10 +59,38 @@ CameraController::runModule()
return; return;
} }
// Apply Offsets
p = p + m_cameraTranslationOffset;
r *= m_cameraRotationOffset;
// Set camera info // Set camera info
m_camera.setPosition(p); m_camera.setPosition(p);
m_camera.setFocalPoint((r*FORWARD_VECTOR) + p); m_camera.setFocalPoint((r*FORWARD_VECTOR) + p);
m_camera.setViewUp(r*UP_VECTOR); m_camera.setViewUp(r*UP_VECTOR);
} }
void
CameraController::setCameraRotationOffset(const Quatd& r)
{
m_cameraRotationOffset = r;
}
void
CameraController::setCameraTranslationOffset(const Vec3d& t)
{
m_cameraTranslationOffset = t;
}
const imstk::Vec3d&
CameraController::getCameraTranslationOffset() const
{
return m_cameraTranslationOffset;
}
const imstk::Quatd&
CameraController::getCameraRotationOffset() const
{
return m_cameraRotationOffset;
}
} // imstk } // imstk
...@@ -57,7 +57,27 @@ public: ...@@ -57,7 +57,27 @@ public:
/// ///
/// \brief /// \brief
/// ///
void setOffsetUsingCurrentCameraPose(); void setOffsetUsingCurrentCameraPose();
///
/// \brief
///
void setCameraRotationOffset(const Quatd& r);
///
/// \brief
///
void setCameraTranslationOffset(const Vec3d& t);
///
/// \brief
///
const Vec3d& getCameraTranslationOffset() const;
///
/// \brief
///
const Quatd& getCameraRotationOffset() const;
protected: protected:
/// ///
...@@ -77,6 +97,9 @@ protected: ...@@ -77,6 +97,9 @@ protected:
Camera& m_camera; ///< Camera controlled by the external device Camera& m_camera; ///< Camera controlled by the external device
Vec3d m_cameraTranslationOffset = WORLD_ORIGIN; ///< Translation offset for the camera over tracking data
Quatd m_cameraRotationOffset = Quatd::Identity(); ///< Rotation offset for the camera over tracking data
}; };
} // imstk } // imstk
......
...@@ -43,7 +43,7 @@ using namespace imstk; ...@@ -43,7 +43,7 @@ using namespace imstk;
const unsigned int scanarioNumber = 1; //possible values: 1, 2, 3, 4 const unsigned int scanarioNumber = 1; //possible values: 1, 2, 3, 4
// Camera settings // Camera settings
const double cameraAngulation = 0.0; //possible values: 0, 30, 45 deg const double cameraAngulation = PI_4; //possible values: 0, 30, 45 deg
const double cameraViewAngle = 80.0; //possible values: 80 deg const double cameraViewAngle = 80.0; //possible values: 80 deg
const double cameraZoomFactor = 1.0; //possible values: TBD const double cameraZoomFactor = 1.0; //possible values: TBD
...@@ -103,7 +103,7 @@ void createScenario1() ...@@ -103,7 +103,7 @@ void createScenario1()
// Set camera controller // Set camera controller
cam->setupController(client0, cameraControllerScaling); cam->setupController(client0, cameraControllerScaling);
cam->getController()->setRotationOffset(Quatd(Eigen::AngleAxisd(cameraAngulation, Vec3d::UnitY()))); cam->getController()->setCameraRotationOffset(Quatd(Eigen::AngleAxisd(cameraAngulation, Vec3d::UnitY())));
//cam->getController()->setInversionFlags(imstk::CameraController::InvertFlag::rotY | imstk::CameraController::InvertFlag::rotZ); //cam->getController()->setInversionFlags(imstk::CameraController::InvertFlag::rotY | imstk::CameraController::InvertFlag::rotZ);
sdk->addModule(server); sdk->addModule(server);
...@@ -159,7 +159,7 @@ void createScenario2() ...@@ -159,7 +159,7 @@ void createScenario2()
// Set camera controller // Set camera controller
cam->setupController(client0, cameraControllerScaling); cam->setupController(client0, cameraControllerScaling);
cam->getController()->setRotationOffset(Quatd(Eigen::AngleAxisd(cameraAngulation, Vec3d::UnitY()))); cam->getController()->setCameraRotationOffset(Quatd(Eigen::AngleAxisd(cameraAngulation, Vec3d::UnitY())));
//cam->getController()->setInversionFlags(imstk::CameraController::InvertFlag::rotY | imstk::CameraController::InvertFlag::rotZ); //cam->getController()->setInversionFlags(imstk::CameraController::InvertFlag::rotY | imstk::CameraController::InvertFlag::rotZ);
#ifdef ADD_TOOL_CONTROLLER #ifdef ADD_TOOL_CONTROLLER
...@@ -238,7 +238,7 @@ void createScenario3() ...@@ -238,7 +238,7 @@ void createScenario3()
// Set camera controller // Set camera controller
cam->setupController(client0, cameraControllerScaling); cam->setupController(client0, cameraControllerScaling);
cam->getController()->setRotationOffset(Quatd(Eigen::AngleAxisd(cameraAngulation, Vec3d::UnitY()))); cam->getController()->setCameraRotationOffset(Quatd(Eigen::AngleAxisd(cameraAngulation, Vec3d::UnitY())));
//cam->getController()->setInversionFlags(imstk::CameraController::InvertFlag::rotY | imstk::CameraController::InvertFlag::rotZ); //cam->getController()->setInversionFlags(imstk::CameraController::InvertFlag::rotY | imstk::CameraController::InvertFlag::rotZ);
#ifdef ADD_TOOL_CONTROLLER #ifdef ADD_TOOL_CONTROLLER
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment