Sign in to follow this  
pisslin

help to manage mouse

Recommended Posts

pisslin    122
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

Share this post


Link to post
Share on other sites
zedzeek    529
try some of thre tutorial sites (at least 10 different ones on the net) eg
http://www.gametutorials.com/main.asp

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Bob Janova    769
Delphi code:
// Mouse look
mx := (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 middle
RecentreMouse;
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this