Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Death Hamster

Setting the mouse's position

This topic is 5475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!