Setting the mouse's position

Started by
6 comments, last by Death Hamster 20 years, 8 months ago
Hi folks I am trying to make my own little FPS (first person shooter) interface. I have got the point of view to rotate in response to the mouse. However when the mouse cursor hits the edge of the screen it refuses to rotate in that directoin any more. Does anyone know the command to either move the mouse cursor back to the center of the screen? Is there another way to get x and y values from the mouse with out dealing with the cursor? I am using the win32 messge loop''s WM_MOUSEMOVE for user input and OpenGL for 3D rendering.
Programming is like dancing through landmines:The programmer is the choreographer, the computer is the dancer and when an error occurs something blows up.
Advertisement
There is a Win32 command...

SetCursorPos(x,y);

which will do it.

Geocyte Has Committed Suicide.

edit: Yes there are other ways. You can use DirectInput's mouse, for example. DIMOUSESTATE objects have a member variables lX and lY which (if you have read the mouse state properly) give you the translation distance since the previous frame.

[edited by - geocyte on August 15, 2003 10:07:52 PM]
Geocyte Has Committed Suicide.
I''m definitely not an expert (I have no idea), but be careful that SetCursorPos(x,y); doesn''t send you a WM_MOUSEMOVE message. Maybe check to see if it does, and if so, just ignore the first one sent after you call Set.
I've only a vauge idea what I'm talking about, but hopefully this will do until someone better informed comes along.

I think the problem here is that you need "relative" instead of "absolute" mouse location info - ie, you want to know how far and in what direction the mouse has moved relative to its last position, not where it's at in terms of screen/client coords.

That way, if I'm swinging the mouse to the left, you know it's going in a left direction at such a speed, and can move the camera accordingly. It doesn't matter where the cursor would be, you just need to know the mouse is moving left relative to its last position.

TBH, I don't know enough to give you more than that, but do some searches for tuts and such with those keywords and you should find some info.

Edit: Yep, Geocyte's edit above is what I was on about. DInput can do it for you, I assume there's a func/msg in Win32 to get that info as well.

[edited by - NeverSayDie on August 16, 2003 3:18:36 PM]
Wading through the DirectInput docs is painful but if you wanted to use DirectX then the code is only a few lines long to set up and read the mouse. Do that if possible.

Mark
Cornutopia Games
http://www.cornutopia.net
The problem with using SetCursorPos is that it will issue a WM_MOUSEMOVE for the difference of where it is that and where you put it. Which if thats what you''re using to trap your movement, will give you really messed up results.
Instead of using WM_MOUSEMOVE, just stick a GetCursorPos in your main loop:

POINT mouse;
GetCursorPos(&mouse);

Now you can use SetCursorPos without worrying about the message generated.

[edited by - CodeMunkie on August 18, 2003 3:24:45 PM]
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
yeah, thats what we had to end up doing, but then we ran into problems that the coordinates were screen relative, not window relative, so we had to factor in the upper left corner coords with what getcursorpos gave... which in the end is nothing. I have that 80''s mentality when if you wanted a 10 second pause in yer program, you simply did a for loop from 1 - 10000... =) So I am always trying to minimize and optimize, when nowadays, it hardly matters with a few extra math calls...

This topic is closed to new replies.

Advertisement