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

Fixed transform control example #221

Closed
wants to merge 2 commits into from

Conversation

ahcorde
Copy link
Contributor

@ahcorde ahcorde commented Jan 29, 2021

I found an issue in the rendering examples, in particular in the transform_control example. When I try to click in the arrows or in one of the other Gizmo visuals is not getting the visual. I need to click in other part of the screen. See the gif below.

transform_bad

With this fix I'm able to get the right visual:

transform_ok

This is also happening in ign-gazebo.

Signed-off-by: ahcorde [email protected]

@ahcorde ahcorde added bug Something isn't working 🔮 dome Ignition Dome labels Jan 29, 2021
@ahcorde ahcorde requested a review from iche033 January 29, 2021 14:39
@ahcorde ahcorde self-assigned this Jan 29, 2021
@ahcorde ahcorde added the 🏢 edifice Ignition Edifice label Jan 29, 2021
@codecov
Copy link

codecov bot commented Jan 29, 2021

Codecov Report

Merging #221 (c10a6bb) into ign-rendering3 (5164539) will decrease coverage by 0.04%.
The diff coverage is 37.50%.

Impacted file tree graph

@@                Coverage Diff                 @@
##           ign-rendering3     #221      +/-   ##
==================================================
- Coverage           53.23%   53.18%   -0.05%     
==================================================
  Files                 131      131              
  Lines               12007    12027      +20     
==================================================
+ Hits                 6392     6397       +5     
- Misses               5615     5630      +15     
Impacted Files Coverage Δ
ogre/src/OgreCamera.cc 0.00% <0.00%> (ø)
src/Utils.cc 29.72% <34.61%> (-5.57%) ⬇️
ogre2/src/Ogre2Camera.cc 87.06% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5164539...c10a6bb. Read the comment docs.

@iche033
Copy link
Contributor

iche033 commented Jan 29, 2021

could be related to gazebosim/gz-sim#147

@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 3, 2021

@iche033 I completely changed the PR, do you mind to have another look ?

@chapulina chapulina removed the 🏢 edifice Ignition Edifice label Feb 3, 2021
@iche033
Copy link
Contributor

iche033 commented Feb 3, 2021

interesting, so you have different xScale and yScale values?

@iche033
Copy link
Contributor

iche033 commented Feb 3, 2021

The changes look good to me. I'm not able to reproduce this issue on my laptop though.

@jennuine do you still have this issue? If so, do you mind testing to see if this fixes the problem?

@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 3, 2021

interesting, so you have different xScale and yScale values?

Yes, I have xScale = 80 and yScale 81,5.

But I think the main issue was that if the scale is lower than the DPI then no scale is needed

@jennuine
Copy link
Contributor

jennuine commented Feb 4, 2021

I still have this issue and unfortunately the changes did not fix the problem for me

@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 4, 2021

Thank you for testing it @jennuine, can you remove this comment ?

https://github.com/ignitionrobotics/ign-rendering/blob/53e850f0f71e9521fcdc59bec492baa437710c9f/src/Utils.cc#L151-L153

And post the output here.

@jennuine
Copy link
Contributor

jennuine commented Feb 4, 2021

DPI Desktop: 96.000000, DPI XY: [162.019928, 160.891495], Scale XY: [1.687708, 1.675953]

@peci1
Copy link
Contributor

peci1 commented Feb 7, 2021

I think the code you're searching for Windows is:

#include <windows.h>
#include <GL/gl.h>
// windows.h defines these macros which break other parts of the library
#undef max
#undef min

 float xDpiDesktop = GetDeviceCaps(wglGetCurrentDC(), LOGPIXELSX);
 float xPixels = GetDeviceCaps(wglGetCurrentDC(), HORZRES);
 float xMM = GetDeviceCaps(wglGetCurrentDC(), HORZSIZE);
 float yDpiDesktop = GetDeviceCaps(wglGetCurrentDC(), LOGPIXELSY);
 float yPixels = GetDeviceCaps(wglGetCurrentDC(), VERTRES);
 float yMM = GetDeviceCaps(wglGetCurrentDC(), VERTSIZE);

I did a test on my computer with screen scaling set to 125%, with a FullHD 21,5" display:

xDpiDesktop = 120
xPixels = 1920
xMM = 477

I think it corresponds to the values you're trying to get in X11.

However, the transform control example works for me even without this patch on Windows.

Docs here: https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdevicecaps . The GetDeviceCaps method returns some "generic" DPI common to all screens, but I think it might be better than nothing.

You can also use GetDpiForWindow(hwnd) which gets you DPI for a specific window, which might be better. But I haven't found a good way to access the window handle of the OGRE window. There is Ogre::RenderTarget::getCustomAttribute("WINDOW", &hwnd), but it would need some more logic for different render engines and OSes. However, it might be useful even in case of X11 because that would return you a handle to the actual window and its screen, and not always screen 0.

Also, the current implementation of the added screenScalingFactor(xScale, yScale) function should default to returning ones for unsupported operating systems, not "nothing" as it does now.

Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another reference point:

  • Ubuntu Bionic Docker container (host is Ubuntu Focal)
  • Display resolution: 2560x1600, scale: 100%
  • Output: DPI Desktop: 96.000000, DPI XY: [100.968941, 101.094528], Scale XY: [1.051760, 1.053068]

transform

/// \brief Get the screen scaling factor.
/// \param[out] _xScale The X screen scaling factor.
/// \param[out] _yScale The Y screen scaling factor.
/// \return The screen scaling factor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return is void 😉

src/Utils.cc Show resolved Hide resolved
ogre/src/OgreCamera.cc Outdated Show resolved Hide resolved
@chapulina
Copy link
Contributor

I believe this issue has been manifesting on CI, see #170. The VisualAt test has been "flaky", but actually it consistently passes / fails according to which machine it runs on.

@chapulina
Copy link
Contributor

I pushed some tweaks in 58a0857:

  • Remove duplicate code
  • Break down the math to make it easier to debug

I also tracked down the history of the scaling factor.

With that in mind, I tried setting the scaling to 1.0 and voilà, it worked like a charm.

I don't really understand why the resolution we get from the calculation is different from the one reported by Xrm and how this scaling changes for different hardware, so it's hard for me to make a recommendation here. The fact that Gazebo classic has been using 1.0 so far is a strong indication for me that reverting to 1.0 may be a good option.


So I see 3 different setups in this thread:

  • @ahcorde 's is fixed with the current PR
  • @jennuine 's doesn't work with or without the PR
  • @chapulina 's doesn't work with or without the PR, but works with 1.0

@jennuine , @ahcorde : can you try 1.0 / 1.0 scaling just for fun?

I'd also be interested in seeing if @nkoenig could test the laptop that gave origin to the scaling in the first place.


https://github.com/osrf/buildfarmer/issues/207

ahcorde and others added 2 commits June 29, 2021 10:40
@ahcorde ahcorde force-pushed the ahcorde/fix/transform_control_example branch from 58a0857 to c10a6bb Compare June 29, 2021 08:57
@ahcorde ahcorde changed the base branch from ign-rendering4 to ign-rendering3 June 29, 2021 08:57
@ahcorde
Copy link
Contributor Author

ahcorde commented Jun 29, 2021

it's working for me,

I retarget this to ign-rendering3, because ign-rendering4 it's no Citadel or Edifice.

@jennuine
Copy link
Contributor

jennuine commented Jun 29, 2021

It's working for me with or without the PR now... With the PR, I tested both as is and with scaling 1.0 and it works either way. Without the PR, I've tested this on Citadel, Dome, and Edifice and all work as expected now.

🤔 I don't know what could have changed between now and then? Maybe @mabelzhang can give it a try, I believe she had come across this issue awhile ago too.

@chapulina
Copy link
Contributor

it's working for me

@ahcorde , you mean with this PR or with 1.0 or both?

@ahcorde
Copy link
Contributor Author

ahcorde commented Jun 29, 2021

I only tried 1.0

@chapulina
Copy link
Contributor

I have a suggestion in #381 for a way to let each user calibrate their screens independently.

@chapulina
Copy link
Contributor

I'm closing this in favor of #446, which was merged into Fortress. We can backport that if needed.

@chapulina chapulina closed this Dec 10, 2021
@chapulina chapulina deleted the ahcorde/fix/transform_control_example branch August 31, 2022 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 🔮 dome Ignition Dome
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants