Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Pages: [1] 2

Author Topic: Hardware OS Cursor  (Read 4399 times)

Falagard

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 18
    • View Profile
Hardware OS Cursor
« on: April 06, 2006, 04:08:00 PM »

I was reading in a proposals thread about hardware cursor support. Has anything been done on this side of things?

I just integrated OIS with my GOOF editor and was mistakingly looking forward to hardware cursor support :-D
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Hardware OS Cursor
« Reply #1 on: April 06, 2006, 04:11:53 PM »

Under what OS? You can use the default OS cursor. There may be (some point) in the future, support for changing the OS cursor. But, I am too busy to implement that sort of thing atm.

To just show the cursor, under OIS windows, just intialise OIS with the nonexclusive and foreground DI flags. Under Linux, initialise with the grab false and hide false (view wiki for details). Of course, then the cursor will drift outside the area of your window.
Logged

Falagard

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 18
    • View Profile
Hardware OS Cursor
« Reply #2 on: April 06, 2006, 04:17:51 PM »

Perfect, thanks :-)
Logged

Falagard

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 18
    • View Profile
Hardware OS Cursor
« Reply #3 on: April 06, 2006, 09:20:55 PM »

Okay, so the absolute position is accumulated by adding buffered relative moves so the hardware cursor and the absolute position reported by OIS don't match up.

I can't see an easy way to fix this. I wanted to be able to use a hardware cursor and call      CEGUI::System::getSingleton().injectMousePosition(arg.state.abX, arg.state.abY);
to inject the absolute position.

The reason why I want to use a hardware cursor is that one of the problems is that relative movement, even buffered, seems to be dependent on framerate. So the cursor moves slower at a slower framerate. With a hardware cursor, even if the the framerate is slow, the mouse continues to move at full speed. Even if the app is sluggish, it feels faster ;-)

Do you think it's feasible to have an option to set the DX input device in absolute mode and then do the opposite of what's happening now, by calculating the relative movement based on the previous absolute value?

Clay
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Hardware OS Cursor
« Reply #4 on: April 06, 2006, 09:27:58 PM »

The problem (IIRC) with DX input mouse in absolute (which I used to have it in when the mode was non-buffered, but now it is all buffered internally), are that absolute Directinput mouse values are meaningless :(

They can (and often are) crazy numbers like, -1293000 or so. Because, the OS cursor just floats around never ending IIRC (until it wraps around i guess). Under GLX, it is more sane. The numbers you get from absolute values are exactly where in your window the mouse is. I think (but am not sure)  that maybe you can just listen to Mouse moved, and may the Win32 (for windows builds) GetMousePosition (or whatever it is called), might just work better. And, i doubt the extra call would hurt performance more then < .5% :D But, again, I'm not sure if you will get sane values from that, or the same kindof values Directinput gives you.
Logged

Falagard

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 18
    • View Profile
Hardware OS Cursor
« Reply #5 on: April 06, 2006, 09:32:18 PM »

Ya, I'm reading similar stuff when I search google for DIPROPAXISMODE_ABS ;-)

I think GetMousePos gives you absolute coords for the entire screen and I'd have to translate them into the client rect of the window and then into pixels or something. I'll look into it further. I don't mind a special solution for windows and an alternate path for linux since I'm guessing the ratio of windows to linux users of this tool will be 10:1 or so, so the linux guys might have to deal with the software cursor.
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Hardware OS Cursor
« Reply #6 on: April 06, 2006, 09:44:44 PM »

I think you missunderstood. What I was saying was that the GLX Absolutle (when not grabbing) is always right on :wink: If you window is 250x200. And the mouse is 10 pixels from the top, and 10 pixels from the left, it will report 10x10 - all the way until the bottom border of 200, and right edge 250, the abs will match exactly. And, you will only get messages when the mouse is in the window - just the way X11 works.

Windows is similiar if OIS could use the WinProc - however, that would be kinda nasty to steal the WinProc from the user (then, the user would not get size/move/button click, etc events), it has been disscussed here. An elegent solution would be a complete cross platform MessageLoop wrapper - but, that is outside the scope of OIS.
Logged

Falagard

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 18
    • View Profile
Hardware OS Cursor
« Reply #7 on: April 06, 2006, 09:47:32 PM »

Holy crap it works.

I added an mHwnd member variable to Win32Mouse.cpp and then the following changes to capture:

Code: [Select]

        POINT point;

GetCursorPos(&point);
ScreenToClient(mHwnd, &point);

mState.abX = point.x;
mState.abY = point.y;

if( axesMoved )
{
/*
mState.abX +=  mState.relX;
mState.abY +=  mState.relY;
mState.abZ +=  mState.relZ;
*/

//Clip values to window width if mouse captured in windows (invisible)
//if( coopSetting & DISCL_EXCLUSIVE )
{
//X
if( mState.abX < 0 )
mState.abX = 0;
else if( mState.abX > mState.width )
mState.abX = mState.width;
//Y
if( mState.abY < 0 )
mState.abY = 0;
else if( mState.abY > mState.height )
mState.abY = mState.height;
}

_doMouseMove(diBuff[entries-1].dwTimeStamp);
}


As you can see I'm ignoring the accumulated relative, made it so it clips the absolute to the window, get the cursor position each frame. Seems to work great for both CEGUI as well as relative mouse moves for things like camera movement. The relative movement won't add up to the same movement as the absolute does, but that's not a problem for me (and most others?).

Clay
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Hardware OS Cursor
« Reply #8 on: April 06, 2006, 10:03:01 PM »

Hmm. I think, instead of doing that always,
I could add it to OIS if it looked like:
Code: [Select]

if( axesMoved )
{
  if( coopSetting & DISCL_NONEXCLUSIVE )
  {
    POINT point;
    GetCursorPos(&point);
    ScreenToClient(mHwnd, &point);
    mState.abX = point.x;
    mState.abY = point.y;
  }
  else
  {
    mState.abX +=  mState.relX;
    mState.abY +=  mState.relY;
    mState.abZ +=  mState.relZ;
  }

  //Clip values to window
  if( mState.abX < 0 )
     mState.abX = 0;
  else if( mState.abX > mState.width )
    mState.abX = mState.width;
  if( mState.abY < 0 )
    mState.abY = 0;
  else if( mState.abY > mState.height )
    mState.abY = mState.height;
   _doMouseMove(diBuff[entries-1].dwTimeStamp);
 }


Just a quick stab, i didn't test it. But, can you see what I mean?
Logged

Falagard

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 18
    • View Profile
Hardware OS Cursor
« Reply #9 on: April 06, 2006, 10:25:55 PM »

Yup totally. I figured something like that would be the final solution, and it seems to work fine and dandy with your more logical code.

It's so nice to finally have a windows mouse cursor - it makes the app feel way better. Thanks.

Clay
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Hardware OS Cursor
« Reply #10 on: April 06, 2006, 10:31:20 PM »

No problem, I'll look to commiting tomorrow, I'm still working on learning Squirrel right now :D

I am curious though, what do you do with the mouse escaping the window? Or does it not matter for the app you are working on - ie, leaving the window is fine?
Logged

Falagard

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 18
    • View Profile
Hardware OS Cursor
« Reply #11 on: April 06, 2006, 11:10:28 PM »

The app I'm working on is the GOOF editor, so it's basically a scene editing tool. It's fine to leave the window.
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Hardware OS Cursor
« Reply #12 on: April 07, 2006, 10:20:19 AM »

Ok, this has been committed to Cvs. Bascially, I changed acouple things, first. mHwnd is not a member, nor did I want it to be. So, I added a call to the manager (it is an inline function anyway IIRC). Second, the RelZ component was not being updated in the version above, this version fixes that. Now, the console demo shows sane absolute values when in non_exclusive mode. Thanks for your efforts Falagard :)
Code: [Select]

if( axesMoved )
{
if( coopSetting & DISCL_NONEXCLUSIVE )
{
//DirectInput provides us with meaningless values, so correct that
HWND hwin = ((Win32InputManager*)(InputManager::getSingletonPtr()))->getWindowHandle();
POINT point;
GetCursorPos(&point);
ScreenToClient(hwin, &point);
mState.abX = point.x;
mState.abY = point.y;
}
else
{
mState.abX +=  mState.relX;
mState.abY +=  mState.relY;
}
mState.abZ +=  mState.relZ;

//Clip values to window
if( mState.abX < 0 )
mState.abX = 0;
else if( mState.abX > mState.width )
mState.abX = mState.width;
if( mState.abY < 0 )
mState.abY = 0;
else if( mState.abY > mState.height )
mState.abY = mState.height;

_doMouseMove(diBuff[entries-1].dwTimeStamp);
}
Logged

Falagard

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 18
    • View Profile
Hardware OS Cursor
« Reply #13 on: April 07, 2006, 12:41:08 PM »

Cool, looks good.
Logged

Freak 99

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 4
    • View Profile
Hardware OS Cursor
« Reply #14 on: August 16, 2006, 06:33:21 AM »

Excuse me for posting in this old thread, but...

... could you please explain this to a OIS noob like me?  :roll:

I'm using OIS with Ogre and CEGUI. My app is based on ExampleApplication / ExampleFrameListener / GuiFrameListener from the OIS Ogre demo. I compiled OIS from source package 0.7.2, and everthing works ok.

Except mouse positions in nonexclusive mode. I keep getting weird numbers, and don't really know what to change.

Thx in advance :wink:


Edit: I tried the latest SVN version too, but it doesn't work for me. My app keeps crashing with some OIS exception on startup.
Logged
Pages: [1] 2