Restrict mouse to center + Player movement with 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.
Post Reply
vrg84
Posts: 3
Joined: Wed Dec 10, 2008 12:16 pm

Restrict mouse to center + Player movement with mouse

Post by vrg84 »

Good afternoon all,

Maybe my topic title is a big vague, so i'll try to explain what i am trying to achieve.

In my game, i want to let the Player move with the mouse (not a regular one, its a trackball).

- Drag mouse up/down = Move in Z-axis
- Drag mouse left/right = Move in X-axis

In addition, i would like to let the player move with the strength of the mouse movement, so if he drags the mouse really fast to the left, the object should move left fast as well.

I was able to get this right by saving the mouse position on the "EMIE_MOUSE_MOVED" event, and in future triggers of this event, comparing it with current mouse position and use the difference as the "force".

But obviously, if i set the cursor in the middle of the screen (to avoid mouse leaving window):

Code: Select all

device->getCursorControl()->setPosition(0.5f,0.5f);
The MOUSE_MOVED event fires and it saves the position of the mouse (which is center screen).

To make a long story short :P How can i let the player move like this, without the mouse leaving the window?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Calculate the amount of movement by always diffing each mouse position from the screen centre, not the last mouse position.

I'll leave the "why" as an exercise for the reader.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
vrg84
Posts: 3
Joined: Wed Dec 10, 2008 12:16 pm

Post by vrg84 »

rogerborg wrote:Calculate the amount of movement by always diffing each mouse position from the screen centre, not the last mouse position.

I'll leave the "why" as an exercise for the reader.
Ah! Fixed it, thanks :)

Kind of logical when i read it now :oops:
Post Reply