Advertisement

How to get the mousemovement with the win32api?

Started by June 12, 2000 07:26 AM
6 comments, last by XBTC 24 years, 6 months ago
Yes,I want to retrieve the absolute movement of the mouse.I only want to know if it is moved left or if it is moved right,I DON`T want to know,at which pixel the mouse is.´Cause I have a 3d-app where you look arround with the mouse like in quake,but if my mouse hits the left end of the window or the right....,I cannot look further left,´cause I´m only able to get the x\y pos of the mouse(which doesn´t change anymore if it is already on the end of the screen). Thanx in advance,XBTC!
just set the mouse coords back to 0,0 when the mouse gets to its boundary, and make sure you are changing the x/y pos into cartesian coord system this will help you in you visualization of this problem.

phope@mcmail.com
Advertisement
I''m not sure if this is exactly what you want, but if you use the SetCapture and ReleaseCapture Win32 functions you can assign all the mouse input to your window, regardless of where the mouse actually is. You can then work out how far the mouse has moved by storing it''s previous position and calculating the difference.

Thanx!
But isn´t there a "non-hack" way of getting the mickeys(is this spelled correctly????) directly?

STG:Don´t know what set and release-capture do but i´ll have a look at the help,perhaps it is what I want,thanx!

Greets,XBTC!
Well, the anonymous poster''s got the right idea. You don''t really need to convert the coordinate systems though because that would be a somewhat big performance hit for input.

Just to restate what the anonymous poster said:

1. Get the coordinates here
2. Move camera with along the X and Y axis.
3. Reset the coordinates to center

------------------------
Captured Reality.
Actually assuming your not using the Win32 API for mouse input *Which is a bad idea) All of you have got it wrong so far. I''m surprised. In DirectInput (Part of DirectX) When you initialize the mouse as a device, it defaults to retrieving up to an x, y, and z with four buttons. When you move the mouse let''s say 10 pixels to the right it return a positive 10 value in X, when you move it to the left 10 pixels, it will return a negative 10 in X same for y and z is usually those scroller wheels.

So as you can see it''s easy to do. If you put the mouse cursor in Exclusive mode the windows GDI cursor disappears so that you can paint your own cursor (Which could look MUCH better). So in game you simply wouldn''t paint the cursor and use the plus and minus values of x and y and add them to the camera angles with a bit of math.

Now in a menu you simply set up to variables called something like AbsoluteMouseX and AbsoluteMouseY and add the returned value to those variables (So to move right you add the positive 10 value returned and when you move left you add the negative 10 value returned, easy :-). Then checking to see that those variables never become less than 0 or greater than your screen res. And then paint your cursor''s "hotspot" (Usually the upper left corner, which is the actual pixel that is used to click with) at that position.

So now you''ve got the mouse cursor working now let''s how do you know when the mouse button''s are down? Well it''s simply DirectInput return''s the state of up to four mouse buttons. Now Button 0 is always the very left button and button 1 is always the very right button for compatability. Then any extra buttons are listed after that starting left to right so it''d be "Button0, Button2, Button3, Button1" or "Button0,Button1" or "Button0,Button2,Button1".

Did that make any sense? Well it''s all in the DX SDK which is available at microsoft''s site.
Hope that helped!
See ya,
Ben
__________________________Mencken's Law:"For every human problem, there is a neat, simple solution; and it's always wrong."
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
Advertisement
Ok, retardo me, you WANT the win32api. Didn't read carefully enough.Ok so I'd use GetCursorPos and SetCursorPos to first get the mouse position then add the difference of that and the last returned values to my variables. Then I'd set the cursor pos to 0,0 for the next read. You can also use "ShowCursor" API to make the mouse cursor invisible and then back to visible.

See ya,
Ben

P.S. Personally I wouldn't use win32API for mouse input in a 3D app of anysort! You could also use Windows messages which will also work well but still not as good as DirectInput!

oops spelling mistake, quick edit....

Edited by - cyberben on June 12, 2000 5:20:49 PM
__________________________Mencken's Law:"For every human problem, there is a neat, simple solution; and it's always wrong."
"Computers in the future may weigh no more than 1.5 tons."- Popular Mechanics, forecasting the relentless march of science in 1949
Thanx alot guys!
Especially for the very detailed info given by cyberben!

P.s.: Perhaps I should look into the direct-input-thing,but I want to stay away from M$ as far as possible.Question to self:Is the win32-api not from M$????

Thanx again,XBTC!



Edited by - XBTC on June 13, 2000 8:32:59 AM

This topic is closed to new replies.

Advertisement