help to manage mouse

Started by
6 comments, last by Bob Janova 17 years, 11 months ago
i want to make a little world where i can move (rotation and translation) like a quake, but i didn't find simple tutorial to manage the mouse move. i know it's the fonction mousemotion which manage it but the tutorial are rare so if you can show me how to manage the camera with the mouse that would be cool. i work with the api win32 , not with glut. thx
Advertisement
try some of thre tutorial sites (at least 10 different ones on the net) eg
http://www.gametutorials.com/main.asp
but it's not free
What you want is to make your mouse work like a joystick. To do this, you have to position the mouse in the center of the screen, then hide the cursor. For every frame you have to calculate the difference of the new mouse position from the center. This gives you how far the user pulled the mouse. The result will be a vector. The x vector can be used as the amount of turn needed and the y for movement. (the negative y points forward) Then set the cursor back to the center, so the user can move it again.

Viktor

ps: For testing, you can leave the cursor visible, so you can see it jumping back to the center for each frame. This algorithm will give you a nice smooth movement because if your framerate is higher, the user will only be able to move the mouse to a shorter distance under one frame and the overall movement speed will be based on the mouse sensitivity setting.
are there "simple" tutorials on it because it's very difficult to imagine all this
nobody knows?
Just lock your mouse to the centre of the screen, and translate the X movement of the mouse into rotation on Z and Y movement into rotation on X (assuming your standard coordinate planes). It's not that hard; the hardest part is tuning it to work smoothly.

Someone can probably draw a picture or something.
Delphi code:
// Mouse lookmx := (100 * (Mouse.CursorPos.x - (GLWidth div 2))) div GLWidth;mx := Min(100, Max(-100, Mx));my := (100 * (Mouse.CursorPos.Y - (GLHeight div 2))) div GLHeight;my := Min(100, Max(-100, MY));Player^.Direction.X := Min(890,Max(-890,Player^.Direction.X + my));Player^.Direction.Y := (Player^.Direction.Y + mx) mod 3600;// Put the mouse back in the middleRecentreMouse;ShowCursor(False);


Player^.Direction is a set of rotation angles, not a direction vector. I know that's confusing, but hey, I wrote this code a long time ago!

This topic is closed to new replies.

Advertisement