I cannot move the mouse out of the OGRE Render Window

Problems building or running the engine, queries about how to use features etc.
cubic
Gnoblar
Posts: 3
Joined: Mon Jan 17, 2005 6:21 am

I cannot move the mouse out of the OGRE Render Window

Post by cubic »

When I run the OGRE GUI Sample,I cannot move my mouse out of the OGRE Render Window.Can anybody tell me why?Another question,I found my mouse move quite slowly in the OGRE GUI Sample's Render Window.Please help,thanks!
User avatar
Banania
Gremlin
Posts: 150
Joined: Wed Oct 20, 2004 2:35 pm
Location: Paris, France

Post by Banania »

When I run the OGRE GUI Sample,I cannot move my mouse out of the OGRE Render Window.Can anybody tell me why?
It is because the samples captures the mouse. I don't think there is a way to avoid that unless you write your own input system. That's because the input system provided by Ogre only exists because it was needed to quickly produce demos. It was never intended to be a perfect input system. But it works for most case.
Banania
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

In games you usually don't want the mouse to escape the window anyway... You can go to another window with alt-tab and have your mouse back I think.
Kai-Peter
Greenskin
Posts: 133
Joined: Tue Oct 15, 2002 10:14 am
Location: Helsinki, Finland
x 1

Post by Kai-Peter »

However, if you are creating something that you occasionally need to run in windowed standard cursor support is cool. I use the standard win32 cursor by replacing the main OGRE rendering loop with a custom one. The events from Windows are then fed into CEGUI (that has a disabled mouse as well).

Here is basically what I'm doing (the real code is slightly more complex):

Code: Select all

main()
{
  while(isRunning) {
    pumpMessages();
    if(Ogre::Root::getSingleton().renderOneFrame() == false)
        isRunning = false;
  }
}

pumpMessages()
{
    // Pump messages on Win32
    MSG  msg;
    while(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {
      TranslateMessage(&msg );
      if(main != NULL)
        main->injectMessageWin32(msg);
      DispatchMessage(&msg );
    }
}

// Message handler
void
Main::injectMessageWin32(MSG msg)
{
  CEGUI::System& cegui = CEGUI::System::getSingleton();

  char keyCode;

  switch(msg.message) {
  case WM_LBUTTONDOWN:
    cegui.injectMouseButtonDown(CEGUI::LeftButton);
    break;
  case WM_LBUTTONUP:
    cegui.injectMouseButtonUp(CEGUI::LeftButton);
    break;
  case WM_RBUTTONDOWN:
    cegui.injectMouseButtonDown(CEGUI::RightButton);
    break;
  case WM_RBUTTONUP:
    cegui.injectMouseButtonUp(CEGUI::RightButton);
    break;
  case WM_MBUTTONDOWN:
    cegui.injectMouseButtonDown(CEGUI::MiddleButton);
    break;
  case WM_MBUTTONUP:
    cegui.injectMouseButtonUp(CEGUI::MiddleButton);
    break;
  case WM_MOUSEMOVE: {
    POINTS currentPos = MAKEPOINTS(msg.lParam);
    int mouseX = currentPos.x;
    int mouseY = currentPos.y;
    if(!(mouseX < 0 || mouseY < 0 ||
         mouseX >= static_cast<int>(renderWindow->getWidth()) ||
         mouseY >= static_cast<int>(renderWindow->getHeight()))) {
      CEGUI::MouseCursor::getSingleton().setPosition(CEGUI::Point(static_cast<float>(mouseX), static_cast<float>(mouseY)));
      cegui.injectMouseMove(0.0f, 0.0f);
    }
    break;
  }
  case WM_KEYDOWN:
    keyCode = static_cast<char>(msg.wParam);
    CEGUI::System::getSingleton().injectKeyDown(InputEventConvert::convertKeyWin32ToCEGUI(keyCode));
    break;
  case WM_KEYUP:
    keyCode = static_cast<char>(msg.wParam);
    CEGUI::System::getSingleton().injectKeyUp(InputEventConvert::convertKeyWin32ToCEGUI(keyCode));
    break;
  }
}
This lets the application drop the FPS to 10-15 and still keep the user feeling everything is running smoothly. :)
Kai Backman, programmer (Blog)
ShortHike - Space Station Game
User avatar
Antiarc
Greenskin
Posts: 120
Joined: Thu Jan 23, 2003 8:40 am

Post by Antiarc »

At least for Axiom, I just hacked up the Win32 platform manager (specifically the input portion) so that the window doesn't own the mouse cursor - works beautifully.
cubic
Gnoblar
Posts: 3
Joined: Mon Jan 17, 2005 6:21 am

thanks a lot

Post by cubic »

Thanks a lot!But I am still puzzling why the mouse cursor moves so slowly?
Kai-Peter
Greenskin
Posts: 133
Joined: Tue Oct 15, 2002 10:14 am
Location: Helsinki, Finland
x 1

Re: thanks a lot

Post by Kai-Peter »

cubic wrote:Thanks a lot!But I am still puzzling why the mouse cursor moves so slowly?
It moves slowly because it is only rendered every time the ogre screen is rendered. If you set up the mouse using the above the mouse will move as quickly as your screen can update. :)
Kai Backman, programmer (Blog)
ShortHike - Space Station Game
cubic
Gnoblar
Posts: 3
Joined: Mon Jan 17, 2005 6:21 am

thanks

Post by cubic »

Thanks for your help! I will have a try.
RoundSparrow
Greenskin
Posts: 145
Joined: Wed Jan 19, 2005 4:36 am
Location: Arica, Chile

Post by RoundSparrow »

Kai-Peter wrote: I use the standard win32 cursor by replacing the main OGRE rendering loop with a custom one. The events from Windows are then fed into CEGUI (that has a disabled mouse as well).
We too want to use the standard hardware cursor on our windowed Ogre application. I'm trying to understand the specifics here...

Are you saying that you have to modify and recompile Ogre to make this work, or just that you change your own code?

I'd prefer a way we could do this against 'stock ogre' - if that isn't possible, maybe we need to suggest this as a feature?

Thanks.
qsilver
OGRE Community Helper
OGRE Community Helper
Posts: 198
Joined: Sat Oct 02, 2004 9:11 am
Location: San Francisco, California, USA

Post by qsilver »

RoundSparrow wrote: We too want to use the standard hardware cursor on our windowed Ogre application. I'm trying to understand the specifics here...

Are you saying that you have to modify and recompile Ogre to make this work, or just that you change your own code?
The changes are all in your own code. You will need to create your own main window using the Win32 API, or some other app toolkit like WTL or GTK.

Then you'll need to pass the external window handle to Ogre (see http://www.ogre3d.org/docs/api/html/cla ... rSystema14 w.r.t. externalWindowHandle in the NameValuePairList param) and handle all your own input according to the window toolkit you are using. You can then call the single-frame render function (renderOneFrame insead of startRendering) whenever you want to redraw the screen.

See the source code for the MeshViewer add-on (in CVS under ogreaddons) for inspiration.