From fb83af8d9d26b254d4debb202a2c5d1558ac7aa0 Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Mon, 1 Feb 2021 12:28:52 +0100 Subject: [PATCH] Add mouse camera control --- modules/HumanStateVisualizer/src/main.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/HumanStateVisualizer/src/main.cpp b/modules/HumanStateVisualizer/src/main.cpp index 4e031908f..9149724e2 100644 --- a/modules/HumanStateVisualizer/src/main.cpp +++ b/modules/HumanStateVisualizer/src/main.cpp @@ -168,6 +168,8 @@ int main(int argc, char* argv[]) viz.camera().setPosition(cameraDeltaPosition); viz.camera().setTarget(fixedCameraTarget); + + viz.camera().animator()->enableMouseControl(true); viz.addModel(modelLoader.model(), "human"); @@ -235,6 +237,9 @@ int main(int argc, char* argv[]) std::array baseOrientationInterface; std::vector jointPositionsInterface; std::vector jointNames; + iDynTree::Vector4 baseOrientationQuaternion; + iDynTree::Position basePosition; + iDynTree::Position basePositionOld = fixedCameraTarget; iDynTree::Transform wHb = iDynTree::Transform::Identity(); iDynTree::VectorDynSize joints(viz.modelViz("human").model().getNrOfDOFs()); @@ -261,13 +266,11 @@ int main(int argc, char* argv[]) jointPositionsInterface = iHumanState->getJointPositions(); jointNames = iHumanState->getJointNames(); - iDynTree::Vector4 baseOrientationQuaternion; baseOrientationQuaternion.setVal(0, baseOrientationInterface.at(0)); baseOrientationQuaternion.setVal(1, baseOrientationInterface.at(1)); baseOrientationQuaternion.setVal(2, baseOrientationInterface.at(2)); baseOrientationQuaternion.setVal(3, baseOrientationInterface.at(3)); - iDynTree::Position basePosition; basePosition.setVal(0, basePositionInterface.at(0)); basePosition.setVal(1, basePositionInterface.at(1)); basePosition.setVal(2, basePositionInterface.at(2)); @@ -290,8 +293,11 @@ int main(int argc, char* argv[]) // follow the desired link with the camera if ( !useFixedCamera ) { + cameraDeltaPosition = viz.camera().getPosition() - basePositionOld; viz.camera().setPosition(basePosition + cameraDeltaPosition); viz.camera().setTarget(basePosition); + + basePositionOld = basePosition; }