Android Screen Rotation View

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

Android Screen Rotation View

Post by LunaRebirth »

When I rotate the screen from portrait to landcape, the view gets shifted like 3D objects get cut off to half the screen size, probably due to the screen width.
Likewise, if I rotate the screen from landscape to portrait, the view starts at about the middle of the screen, such as elements starting at pos (0, screenHeight/2) instead of (0, 0).

Here is what I've tried:

Code: Select all

void checkWindowSizeUpdate()
{
    Game::window.resized.resized = false;
 
    bool screenChanged = false;
    int newX = 0, newY = 0, newWidth = 0, newHeight = 0;
#ifdef _IRR_ANDROID_PLATFORM_
    newWidth = ANativeWindow_getWidth(Game::state->window);
    newHeight = ANativeWindow_getHeight(Game::state->window);
#elif _WIN32 || _WIN64
    newWidth = Game::driver->getScreenSize().Width;
    newHeight = Game::driver->getScreenSize().Height;
 
    HWND hWnd = GetActiveWindow();
    RECT rect;
    if(GetWindowRect(hWnd, &rect))
    {
        newX = rect.left;
        newY = rect.top;
    }
#endif
 
    screenChanged = Game::window.x != newX || Game::window.y != newY || newWidth != Game::window.width || newHeight != Game::window.height;
 
    if (screenChanged)
    {
        Game::window.width = newWidth;
        Game::window.height = newHeight;
        Game::window.x = newX;
        Game::window.y = newY;
        core::rect<s32> rct = core::rect<s32>(Game::window.x,Game::window.y,Game::window.x+Game::window.width,Game::window.y+Game::window.height);
#ifdef _WIN32 || _WIN64
        Game::device->getCursorControl()->setReferenceRect(&rct);
#endif // _WIN32
        Game::smgr->getActiveCamera()->setAspectRatio((float)Game::window.width/(float)Game::window.height);
        Game::log("NEW SCREEN SIZE: " + Operations::intToString(Game::window.x) + ", " + Operations::intToString(Game::window.y) + ", " +
                                        Operations::intToString(Game::window.width) + ", " + Operations::intToString(Game::window.height));
        Game::driver->setViewPort(recti(0, 0, Game::window.width, Game::window.height));
    }
}
(Note that I am aware there are events for screen resizes, this is just a test).

The "NEW SCREEN SIZE: " output is correctly outputting the Android rotated screen resolution.

Any help would be appreciated.
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Android Screen Rotation View

Post by CuteAlien »

Yeah, there is some mess going on. Got it on my todo since a few weeks, didn't get to it yet :-( My hope right now is that I maybe find some time between x-mas and new year (taking days off there, but also having visitors... tricky...)
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: 386
Joined: Sun May 11, 2014 12:13 am

Re: Android Screen Rotation View

Post by LunaRebirth »

CuteAlien wrote:Yeah, there is some mess going on. Got it on my todo since a few weeks, didn't get to it yet :-( My hope right now is that I maybe find some time between x-mas and new year (taking days off there, but also having visitors... tricky...)
Okay, great.
I will also look around the source, but I am nowhere near as familiar with the Irrlicht source as you are.
Thanks!
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

Re: Android Screen Rotation View

Post by LunaRebirth »

I was testing around with this issue again today, I have some clients who are pushing me to get the portrait view working, but other features that are dependent on landscape view.

Looks like if I am in landscape view and switch to portrait, the viewport's Y axis becomes the height of the screen from landscape view.
If I were able to set the viewport's Y axis to a negative value, I could reposition the viewport's Y axis to be that value (but negative), and it would correctly display the screen after being rotated.

Unfortunately, it looks like the viewport does not support negative values. I am able to push the screen down even further by setting the viewPort's Y axis to, for example, 10, and it would move the screen down 10 pixels. But if I set it to -10, nothing happens -- the screen does not move up.

I can't find where setViewPort is checking against negative values in the source code. Is this a Rect<s32> thing?
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

Re: Android Screen Rotation View

Post by LunaRebirth »

I removed line 2086-2087 from https://github.com/zaki/irrlicht/blob/o ... Driver.cpp, and this allowed me to set the viewPort to negative values.

After switching from landscape (2880x1440) to portrait (1440x2880), I set the viewPort to (0,-1440,1440,1440) and that makes the screen the correct size.

Unfortunately, this seems to squash my font, and cut off parts of my IGUIImages.
Along with that, my touch positions are off by a lot and getCursorControl()->setReferenceRect() does not work for touches.

See the image below:

Image

For reference, here's how it looks starting up as portrait view:

Image
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Android Screen Rotation View

Post by CuteAlien »

Thanks for the update. Got to admit - last time I looked at this I gave up :-/
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: 386
Joined: Sun May 11, 2014 12:13 am

Re: Android Screen Rotation View

Post by LunaRebirth »

CuteAlien wrote:Thanks for the update. Got to admit - last time I looked at this I gave up :-/
Here are some things I found:

(1) - Touch positions don't account for the viewPort. A simple change to CIrrDeviceAndroid's handleInput() method should do the trick, unless there is somewhere else this should be instead.
(2) - IGUIImage's texture scales with the viewPort, but the clip does not. This is why the images are being cut off.
Post Reply