How to do frame rate independent mouse?

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.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

How to do frame rate independent mouse?

Post by MasterGod »

For example I want the mouse movement speed to be the same in 640x480 resolution and in 1600x1200.
I guess a solution would be to check with percentages but I don't have a clue on how to do that?
Or do you have a better solution?

Thanks.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

Do you mean that it takes the same physical mouse movement to get the mouse to move from one side of the screen to the other, or for camera rotation like an FPS camera? For the latter, getRelativePosition, but I suspect you mean the former.

The simplest way I can think of doing it is to use trig to find the direction of movement, then recalculate how far it would have gone using a timer and a relative position.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Ion Dune wrote:The simplest way I can think of doing it is to use trig to find the direction of movement, then recalculate how far it would have gone using a timer and a relative position.
Sorry but I still don't get how :wink:
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
danieLs0xFF
Posts: 14
Joined: Wed Aug 16, 2006 6:58 pm

Post by danieLs0xFF »

i think separate thread for mouse handling would do the trick
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

danieLs0xFF wrote:i think separate thread for mouse handling would do the trick
Don't you think that's too complicated for such a simple task??
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

MasterGod wrote:
danieLs0xFF wrote:i think separate thread for mouse handling would do the trick
Don't you think [...]
I doubt it.

Aaaanyway, to repeat the question: do you mean the movement of the cursor across the screen, or the effect of that movement on (e.g.) a FPS camera? Can you please be specific about your requirements.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

rogerborg wrote:Aaaanyway, to repeat the question: do you mean the movement of the cursor across the screen, or the effect of that movement on (e.g.) a FPS camera? Can you please be specific about your requirements.
Ok, I'll try to describe it better.
Let's say I have a sphere mesh.
When I raise the mouse up it rotates on -X and down on +X.
The mouse cursor is locked to the center of the screen.
Now, if I move the mouse up fast it moves lets say 10 unites. if I move the mouse slow, the same distance on my desk, it moves 75 unites. (10 and 75 for example).

P.S
I'm starting to think now the problem might not be with making the mouse "time-based" but with something else..
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
robertgarand
Posts: 69
Joined: Fri Feb 22, 2008 6:47 pm
Location: montreal
Contact:

Post by robertgarand »

Hi,
I m using the mouse to direct a cannon on the screen,
I use factor to multiply actual mousemov. it is currently
hard coded ( the 70's), but one culd just implement different
factors base on current screen resolution.
hope it helps.

Code: Select all

//.5 is center of screen in absolute mouse pos
const f32 anglecanon = 0.5;


	video::IVideoDriver* driver = Device->getVideoDriver();
	core::vector3df canonrot;
	f32 offsetx, offsety;
	if (!Device->isWindowActive()) {return;}
	gui::ICursorControl* cursorcontrol = Device->getCursorControl();
	core::position2d<f32> cursorpos = cursorcontrol->getRelativePosition();
	offsetx = (cursorpos.X-anglecanon)*70;
	offsety = (cursorpos.Y-anglecanon)*70;
	core::vector3df canon_rot= (canon->getRotation());
//X & Y is inverted on screen resolution versus gui mousePOS
	canonrot.Y =offsetx;
	canonrot.X =offsety;
	canonrot.Z=0;
	canon->setRotation(canonrot);
Hope it helps.
Robert
If it can't be writen, it can't exist
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

Oh, I see. So the same distance on the desk produces different results based on speed? I didn't even know it worked that way.
If you moved the mouse one centimeter physically, and that equaled 10 pixels on the screen, are you saying that if you move the mouse another centimeter but faster it will move less than or more than 10 pixels. If so, I don't think its something that can be changed in Irrlicht. It sounds like a problem in the operating system or the mouse.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Ion Dune wrote:Oh, I see. So the same distance on the desk produces different results based on speed? I didn't even know it worked that way.
If you moved the mouse one centimeter physically, and that equaled 10 pixels on the screen, are you saying that if you move the mouse another centimeter but faster it will move less than or more than 10 pixels. If so, I don't think its something that can be changed in Irrlicht. It sounds like a problem in the operating system or the mouse.
No, it doesn't happen outside Irrlicht, or at least my app (didn't tested it on the examples yet).
On windows/GTA SA 10 cm equals the same distance no matter what speed I move the mouse.

I'll check the behavior on the examples tomorrow and report back.

@robertgarand: I'll check it tomorrow, thanks.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

Ahh! I see now. I believe that I had a similar problem once, and that I was able to fix it by going from cursorcontrol->getPosition to getRelativePosition.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Ion Dune wrote:Ahh! I see now. I believe that I had a similar problem once, and that I was able to fix it by going from cursorcontrol->getPosition to getRelativePosition.
It didn't do the trick.

Maybe the following video will describe good enough my problem:
http://www.youtube.com/watch?v=WX2moCiCuEg
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

Huh. Well, I am stumped. Perhaps you should compare your code to that of the FPS camera scene node. It should be the same sort of mechanism.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

I tried but I can't figure which code inside the FPS camera take care of such behavior. :(
Does anyone else knows what causes it?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

(Sorry, I missed your earlier reply)

Answer: dunno. How are you retrieving and interpreting the mouse position/movement?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply