Get Window Position

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Get Window Position

Post by LunaRebirth »

Hello!

I'm trying to make my game window resizable, but resizing the screen seems to screw up my controls and the screen will rotate non-stop.
I found the problem was that the mouse position relative for checking if you moved your mouse (And the distance moved) wasn't updating to the new window .5,.5 (In the middle of the screen)
So the middle would appear to be where the middle was BEFORE resizing the screen.

So I'm taking on the encounter of doing

Code: Select all

core::rect<int> windowSize = core::rect<int>(0,0,screen.width,screen.height);
device->getCursorControl()->setReferenceRect(&windowSize);
This works, but now if I set mouse position to .5,.5 -- Mouse position warps to literally half the screen's X and Y. Literally as in if the window was located at 0,0 (pixels), the mouse warps to half the screen X and Y even if the window is in the bottom-right of the screen.

So my problem is trying to do this:

Code: Select all

core::rect<int> windowSize = core::rect<int>(screen.x,screen.y,screen.x+screen.width,screen.y+screen.height);
But I can't seem to figure out how to get screen.x and screen.y to work...

What I Tried:

Code: Select all

HWND hVWnd = FindWindow((char*)screen.caption.c_str(), (char*)screen.caption.c_str());
RECT rRect;
GetWindowRect(hVWnd,&rRect);
screen.x = rRect.left; screen.y = rRect.top;
This doesn't find the window X and Y, it will always say the window is at something like 0,71283821 or something.

So how can I get the window's x/y coordinates?

Thanks in advance!
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Get Window Position

Post by hendu »

This is a bug in the (Windows?) cursorcontrol code of irr, if it doesn't update to new window size. Nothing to do with your code, and you shouldn't try to do workarounds.
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Get Window Position

Post by CuteAlien »

Ok, I probably don't get the exact problem. I know there was a similar report in the past: http://irrlicht.sourceforge.net/forum/v ... 32#p255132

I just adapted my mouse-test a little bit to check what happens on resizing, but so far it still seems to work: https://code.google.com/p/irr-playgroun ... e_test.cpp
So either this is fixed in trunk already or something my test doesn't catch yet. In which case it would be nice if you could propose something I can add to my test to see the problem.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Get Window Position

Post by LunaRebirth »

hendu wrote:This is a bug in the (Windows?) cursorcontrol code of irr, if it doesn't update to new window size. Nothing to do with your code, and you shouldn't try to do workarounds.
If I don't find a work-around, then it's quite annoying when you resize the window: setting mouse position to 0.5,0.5 sends it to the wrong area. Typically off screen if moved.
CuteAlien wrote: Ok, I probably don't get the exact problem. I know there was a similar report in the past: viewtopic.php?f=4&t=44507&p=255132#p255132

I just adapted my mouse-test a little bit to check what happens on resizing, but so far it still seems to work: https://code.google.com/p/irr-playgroun ... e_test.cpp
So either this is fixed in trunk already or something my test doesn't catch yet. In which case it would be nice if you could propose something I can add to my test to see the problem.
I made an image showing the problem. The bottom-right panel is what I need to get this working. I need to find the window x and y, But for some odd reason; I can't do this through WindowRect, as it returns strange values.
http://imgur.com/UsYKf55
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Get Window Position

Post by LunaRebirth »

I looked at the two links you've provided, The first seems to be much alike my problem possibly. Not sure if they got theirs working or not though.

I'm not sure what information I can provide about this problem, other than I'm finding window width and height by doing:

Code: Select all

screen.width = driver->getScreenSize().Width;
screen.height = driver->getScreenSize().Height;
and then doing

Code: Select all

core::rect<int> windowSize = core::rect<int>(0,0,screen.width,screen.height);
device->getCursorControl()->setReferenceRect(&windowSize);
core::position2d<f32> cursorPos = device->getCursorControl()->getRelativePosition();
If needed: I'm also not checking for "If the window has resized," I'm doing the above code on the main loop.
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Get Window Position

Post by CuteAlien »

Maybe it's the setReferenceRect, I don't have that in my test. Thought getRelativePosition does update in my example on resize without me calling that - so I'm not quite sure why it helps in your situation partly. Are you working with trunk or with Irrlicht 1.8 currently? I'm testing trunk at the moment.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Get Window Position

Post by LunaRebirth »

CuteAlien wrote:Maybe it's the setReferenceRect, I don't have that in my test. Thought getRelativePosition does update in my example on resize without me calling that - so I'm not quite sure why it helps in your situation partly. Are you working with trunk or with Irrlicht 1.8 currently? I'm testing trunk at the moment.
Without the setReferenceRect, the mouse boundaries (or whatever) do not change, and it moves my screen around as if I'm moving my mouse (Even when I'm not), so the setReferenceRect is a need-to-have in this case.
Not sure what trunk is, but I'm using Irrlicht 1.8.1
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Get Window Position

Post by CuteAlien »

I still can't reproduced it. I just used the official 1.8.1 release with my test from above. You can resize the window in my test and it prints out the relative positions. And they automatically change when resizing the window. So I'm sorry - but I need a test-case here to reproduce the exact problem.

Trunk is by the way the most current developer version which you can get from here: http://sourceforge.net/p/irrlicht/code/HEAD/tree/
Many people work with that as we generally try to keep it stable and it contains already some more features than the last release.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Get Window Position

Post by hendu »

LunaRebirth wrote:If I don't find a work-around, then it's quite annoying when you resize the window: setting mouse position to 0.5,0.5 sends it to the wrong area. Typically off screen if moved.
Well yeah, it obviously sucks, but it should be fixed in the right place, not papered over.

I don't see a mention of what OS is this anywhere. Windows 8.1 With Bing Starter Crippled Edition Where Metro Is Forced And Wallpaper May Not Be Changed?
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Get Window Position

Post by LunaRebirth »

Strange.

Anywho, I'm running Windows 8, and no I do not use Bing LOL
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Get Window Position

Post by CuteAlien »

Can you try if my test here works on your system? https://code.google.com/p/irr-playgroun ... e_test.cpp
Just copy it over some example and try what happens to the mouse-coordinates when resizing the Window there.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Get Window Position

Post by LunaRebirth »

That's really strange, that works fine. There must be something wrong with mine :/

Without using the new rect for the mouse; If I do a window resize, the screen will rotate even while not moving the mouse.
The bigger the window is resized to, the faster the screen moves around.

Edit:
If maybe this has anything to do with the problem or eliminates what may not be the problem, if I resize the window along the X axis but not Y, the 3D models get distorted a bit. Or if dragging the X axis closer together, the models look skinny. And vice-versa
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Get Window Position

Post by hendu »

The camera aspect is not automatically recalculated. It's not related to this.
LunaRebirth
Posts: 385
Joined: Sun May 11, 2014 12:13 am

Re: Get Window Position

Post by LunaRebirth »

Okay, I guess I'll let the problem continue.
It isn't THAT big of a deal with the mouse rect info stuff.
Just positions the mouse wrong. Can't notice if the window is full-screen -- Just something I'd like to get fixed
Post Reply