Skip to content

Commit

Permalink
Generate a window manually with GLFW when using irrlicht (#1071)
Browse files Browse the repository at this point in the history
Co-authored-by: Silvio Traversaro <silvio.traversaro@iit.it>
  • Loading branch information
S-Dafarra and traversaro authored May 10, 2023
1 parent 7e4851c commit b5a0e49
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
if: contains(matrix.os, 'windows')
shell: bash -l {0}
run: |
bash_vc_install=${VCToolsInstallDir//\\//}
bash_vc_install=${VCToolsInstallDir//\\//}
compiler_path=${bash_vc_install}bin/Hostx64/x64/cl.exe
echo "CC=${compiler_path}" >> $GITHUB_ENV
echo "CXX=${compiler_path}" >> $GITHUB_ENV
Expand Down Expand Up @@ -182,7 +182,7 @@ jobs:
apt-get -y update
apt-get -y install \
git build-essential cmake libace-dev coinor-libipopt-dev libeigen3-dev swig \
libxml2-dev liboctave-dev python3-dev python3-numpy valgrind libassimp-dev libirrlicht-dev curl unzip
libxml2-dev liboctave-dev python3-dev python3-numpy valgrind libassimp-dev libirrlicht-dev curl unzip libglfw3-dev
- name: Install files to enable compilation of mex files [apt]
run: |
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/matlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on:
pull_request:
schedule:
# * is a special character in YAML so you have to quote this string
# Execute a "nightly" build at 2 AM UTC
# Execute a "nightly" build at 2 AM UTC
- cron: '0 2 * * *'

jobs:
build-matlab-tests:
build-matlab-tests:
name: '[matlab:${{ matrix.matlab_version }}:${{ matrix.os }}]'
runs-on: ${{ matrix.os }}
defaults:
Expand Down Expand Up @@ -56,22 +56,22 @@ jobs:
run: |
# Workaround for https://github.com/conda-incubator/setup-miniconda/issues/186
conda config --remove channels defaults
# Compilation related dependencies
# Compilation related dependencies
mamba install cmake compilers make ninja pkg-config
# Actual dependencies
mamba install eigen libxml2 assimp ipopt irrlicht osqp-eigen
mamba install eigen libxml2 assimp ipopt irrlicht osqp-eigen glfw
# Additional dependencies useful only on Linux
- name: Dependencies [Conda/Linux]
if: contains(matrix.os, 'ubuntu')
if: contains(matrix.os, 'ubuntu')
run: |
# Additional dependencies only useful on Linux
# See https://github.com/robotology/robotology-superbuild/issues/477
mamba install expat-cos6-x86_64 freeglut libselinux-cos6-x86_64 libxau-cos6-x86_64 libxcb-cos6-x86_64 libxdamage-cos6-x86_64 libxext-cos6-x86_64 libxfixes-cos6-x86_64 libxxf86vm-cos6-x86_64 mesa-libgl-cos6-x86_64 mesa-libgl-devel-cos6-x86_64
# Additional dependencies useful only on Windows
- name: Dependencies [Conda/Windows]
if: contains(matrix.os, 'windows')
if: contains(matrix.os, 'windows')
run: |
# Additional dependencies only useful on Windows
# See https://github.com/robotology/robotology-superbuild/issues/477
Expand Down Expand Up @@ -120,8 +120,8 @@ jobs:
run: |
cd build
# Only run matlab tests as the rest of tests are already run by other jobs
ctest --output-on-failure -C ${{ matrix.build_type }} -R "matlab" -VV .
ctest --output-on-failure -C ${{ matrix.build_type }} -R "matlab" -VV .
- name: Install [Conda]
run: |
cd build
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ jobs:
swig \
libxml2-dev \
libassimp-dev \
libirrlicht-dev
libirrlicht-dev \
libglfw3-dev
pip install build
- name: Build sdist
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [8.999.0] - 2023-03-05
## [8.999.0] - YYYY-MM-DD

### Fixed
- Fix export of `iDynTree::PrismaticJoint` in `iDynTree::getRandomModel` (https://github.com/robotology/idyntree/pull/1057).

### Changed

- Binary wheels available on PyPI now target `manylinux_2_28`, and the options `IDYNTREE_USES_ASSIMP`, `IDYNTREE_USES_IPOPT` and `IDYNTREE_USES_IRRLICHT` are disable in binary wheels on PyPI. If you need these options enabled, please use conda-forge binaries or build iDynTree from source (https://github.com/robotology/idyntree/pull/1068).
- Compilation with `IDYNTREE_USES_IRRLICHT` set to `ON` now requires `glfw` library. Furthermore, now `IDYNTREE_USES_IRRLICHT` on Windows requires irrlicht to be compiled with SDL support. This changes have been done to support resizable visualizer windows on Windows (https://github.com/robotology/idyntree/issues/1070, https://github.com/robotology/idyntree/pull/1071).
- Use iDynTree::InverseKinematicsRotationParametrizationRollPitchYaw as default parametrization in iDynTree::InverseKinematics (https://github.com/robotology/idyntree/pull/1058).

#### URDF XML parser change
Expand Down
1 change: 1 addition & 0 deletions ci_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies:
- assimp
- ipopt
- irrlicht
- glfw
- swig
- pybind11
- python
Expand Down
3 changes: 2 additions & 1 deletion src/visualization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ target_compile_options(${libraryname} PRIVATE ${IDYNTREE_WARNING_FLAGS})
if(IDYNTREE_USES_IRRLICHT)
find_package(OpenGL)
find_package(Irrlicht REQUIRED)
find_package(glfw3 REQUIRED)

target_link_libraries(${libraryname} PRIVATE Irrlicht::Irrlicht)
target_link_libraries(${libraryname} PRIVATE Irrlicht::Irrlicht glfw)
if(TARGET OpenGL::GL)
target_link_libraries(${libraryname} PRIVATE OpenGL::GL)
endif()
Expand Down
6 changes: 6 additions & 0 deletions src/visualization/src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ void Camera::setAspectRatio(double aspectRatio)
}
}

void Camera::setWindowDimensions(unsigned int width, unsigned int height)
{
setAspectRatio(width/ (float)height);
m_animator->setWindowDimensions(width, height);
}

void Camera::setIrrlichtCamera(irr::scene::ICameraSceneNode* cam)
{
m_irrCamera = cam;
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 @@ -36,6 +36,8 @@ class Camera: public ICamera

void setAspectRatio(double aspectRatio);

void setWindowDimensions(unsigned int width, unsigned int height);

virtual void setPosition(const Position& cameraPos);
virtual void setTarget(const Position& targetPos);
virtual void setUpVector(const Direction& upVector);
Expand Down
30 changes: 15 additions & 15 deletions src/visualization/src/CameraAnimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,17 @@ namespace iDynTree
{

//! constructor
CameraAnimator::CameraAnimator(irr::gui::ICursorControl* cursor, irr::scene::ISceneNode *cameraAxis,
CameraAnimator::CameraAnimator(irr::scene::ISceneNode *cameraAxis, unsigned int windowWidth, unsigned int windowHeight,
double rotateSpeed, double zoomSpeed, double translateSpeed)
: m_cursorControl(cursor), m_mousePos(0.5f, 0.5f), m_initialMousePosition(m_mousePos),
: m_mousePos(0.5f, 0.5f), m_initialMousePosition(m_mousePos),
m_zoomSpeed(zoomSpeed), m_rotateSpeed(rotateSpeed), m_translateSpeed(translateSpeed),
m_zooming(false), m_rotating(false), m_movingUp(false), m_translating(false), m_isEnabled(false)
m_zooming(false), m_rotating(false), m_movingUp(false), m_translating(false), m_isEnabled(false),
m_width(windowWidth), m_height(windowHeight)
{
#ifdef _DEBUG
setDebugName("iDynTreeCameraAnimator");
#endif

if (m_cursorControl)
{
m_cursorControl->grab();
m_mousePos = m_cursorControl->getRelativePosition();
}

allKeysUp();
m_cameraAxis = cameraAxis;

Expand All @@ -41,8 +36,13 @@ CameraAnimator::CameraAnimator(irr::gui::ICursorControl* cursor, irr::scene::ISc
//! destructor
CameraAnimator::~CameraAnimator()
{
if (m_cursorControl)
m_cursorControl->drop();

}

void CameraAnimator::setWindowDimensions(unsigned int width, unsigned int height)
{
m_width = width;
m_height = height;
}


Expand All @@ -60,11 +60,11 @@ bool CameraAnimator::OnEvent(const irr::SEvent& event)
{
case irr::EMIE_LMOUSE_PRESSED_DOWN:
m_mouseKeys[0] = true;
m_initialMousePosition = m_cursorControl->getRelativePosition();
m_initialMousePosition = m_mousePos;
break;
case irr::EMIE_RMOUSE_PRESSED_DOWN:
m_mouseKeys[2] = true;
m_initialMousePosition = m_cursorControl->getRelativePosition();
m_initialMousePosition = m_mousePos;
break;
case irr::EMIE_MMOUSE_PRESSED_DOWN:
m_mouseKeys[1] = true;
Expand All @@ -79,7 +79,7 @@ bool CameraAnimator::OnEvent(const irr::SEvent& event)
m_mouseKeys[1] = false;
break;
case irr::EMIE_MOUSE_MOVED:
m_mousePos = m_cursorControl->getRelativePosition();
m_mousePos.set(static_cast<float>(event.MouseInput.X) / m_width, static_cast<float>(event.MouseInput.Y) / m_height);
break;
case irr::EMIE_MOUSE_WHEEL:
m_wheelMoving = true;
Expand Down Expand Up @@ -328,7 +328,7 @@ double CameraAnimator::getZoomSpeed() const
irr::scene::ISceneNodeAnimator* CameraAnimator::createClone(irr::scene::ISceneNode* /*node*/, irr::scene::ISceneManager* /*newManager*/)
{
CameraAnimator * newAnimator =
new CameraAnimator(m_cursorControl, m_cameraAxis->clone(), m_rotateSpeed, m_zoomSpeed, m_translateSpeed);
new CameraAnimator(m_cameraAxis->clone(), m_width, m_height, m_rotateSpeed, m_zoomSpeed, m_translateSpeed);
return newAnimator;
}

Expand Down
7 changes: 5 additions & 2 deletions src/visualization/src/CameraAnimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ namespace iDynTree
{
public:
//! Constructor
CameraAnimator(irr::gui::ICursorControl* cursor, irr::scene::ISceneNode *cameraAxis, double rotateSpeed = 10.0f,
CameraAnimator(irr::scene::ISceneNode *cameraAxis, unsigned int windowWidth, unsigned int windowHeight, double rotateSpeed = 10.0f,
double zoomSpeed = 0.5f, double translationSpeed = 10.0f);

//! Destructor
virtual ~CameraAnimator();

void setWindowDimensions(unsigned int width, unsigned int height);

//! Animates the scene node, currently only works on cameras
virtual void animateNode(irr::scene::ISceneNode* node, irr::u32 timeMs) override;

Expand Down Expand Up @@ -78,7 +80,6 @@ namespace iDynTree
bool m_wheelMoving;
irr::f32 m_wheelDirection;

irr::gui::ICursorControl *m_cursorControl;
irr::scene::ISceneNode *m_cameraAxis;
irr::core::position2df m_mousePos;
irr::core::position2df m_initialMousePosition;
Expand All @@ -90,6 +91,8 @@ namespace iDynTree
bool m_movingUp;
bool m_translating;
bool m_isEnabled;
unsigned int m_width;
unsigned int m_height;
};

} // end namespace irr
Expand Down
Loading

0 comments on commit b5a0e49

Please sign in to comment.