Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added getPosition and getTarget for the visualizer camera. #811

Merged
merged 1 commit into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/visualization/include/iDynTree/Visualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ class ICamera
*/
virtual void setTarget(const iDynTree::Position & cameraPos) = 0;

/**
* Get the linear position of the camera w.r.t to the world.
*/
virtual iDynTree::Position getPosition() = 0;

/**
* Get the target of the camera (i.e. the point the camera is looking into) w.r.t. the world.
*/
virtual iDynTree::Position getTarget() = 0;

/**
* Set the up vector of the camera w.r.t to the world.
*/
Expand Down
26 changes: 26 additions & 0 deletions src/visualization/src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,32 @@ void Camera::setUpVector(const Direction& cameraUpVector)
}
}

Position Camera::getPosition()
{
if(m_irrCamera)
{
return irr2idyntree_pos(m_irrCamera->getPosition());
}
else
{
reportError("Camera","getPosition","Impossible to get the position of a null camera");
return iDynTree::Position();
}
}

Position Camera::getTarget()
{
if(m_irrCamera)
{
return irr2idyntree_pos(m_irrCamera->getTarget());
}
else
{
reportError("Camera","getTarget","Impossible to get the target of a null camera");
return iDynTree::Position();
}
}

ICameraAnimator *Camera::animator()
{
if (!m_animator)
Expand Down
2 changes: 2 additions & 0 deletions src/visualization/src/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Camera: public ICamera
virtual void setPosition(const Position& cameraPos);
virtual void setTarget(const Position& targetPos);
virtual void setUpVector(const Direction& upVector);
virtual iDynTree::Position getPosition();
virtual iDynTree::Position getTarget();
virtual ICameraAnimator* animator();
};

Expand Down
2 changes: 2 additions & 0 deletions src/visualization/src/DummyImplementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class DummyCamera : public ICamera
virtual void setPosition(const iDynTree::Position &) {};
virtual void setTarget(const iDynTree::Position &) {};
virtual void setUpVector(const Direction&) {};
virtual iDynTree::Position getPosition() {return iDynTree::Position();};
virtual iDynTree::Position getTarget() {return iDynTree::Position();};
virtual ICameraAnimator* animator() {return nullptr;};
};

Expand Down
3 changes: 3 additions & 0 deletions src/visualization/tests/VisualizerUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ void checkFrameVisualization() {
viz.init();

viz.camera().setPosition(iDynTree::Position(2.0, 0.0, 2.0));
ASSERT_EQUAL_VECTOR(viz.camera().getPosition(), iDynTree::Position(2.0, 0.0, 2.0));
viz.camera().setTarget(iDynTree::Position(0.0, 0.0, 0.0));
ASSERT_EQUAL_VECTOR(viz.camera().getTarget(), iDynTree::Position(0.0, 0.0, 0.0));

iDynTree::IFrameVisualization& frames = viz.frames();

Expand Down