• Advertisement
Sign in to follow this  

help to manage mouse

This topic is 4291 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

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
Advertisement
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
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
are there "simple" tutorials on it because it's very difficult to imagine all this

Share this post


Link to post
Share on other sites
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
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
Sign in to follow this  

  • Advertisement