Sign in to follow this  

3D mouse movement

Recommended Posts

Hello I've created a little 3D environnement. I can move properly with mij keyboard. But I also want to move with my mouse like in a first person shooter game. When the mouse moves from left to right, the environnement has to turn from right to left. i tried this POINT mousePos; int mid_x = width >> 1; int mid_y = height >> 1; GetCursorPos(&mousePos); if(mousePos.x > mid_x){ yrot-=0.03f } if(mousePos.x < mid_x){ yrot+=0.03f; } if(mousePos.x==mid_x){ yrot=0.00f; } It works but not as I want to. It is to sensitive (you have to point at the middle of the screen so it won't turn). I also want it to turn more quickly when you get closer to the border of the screen. (so0.03f has to change. I tried (mousePos.x-mid_x)*speed in stead of 0.03f) Is this correct? How can i make this because i didn't found any good tutorials about this topic. thanx Lirben

Share this post

Link to post
Share on other sites
To combat the problem of having to point at the middle of the screen, you should reset the cursor to a known position every frame and take your measurements from there. For instance:

Begin MouseLook
GetCursorPos (center)

while looping
GetCursorPos (newpos)
MouseMovement = center - newpos
SetCursorPos (center)

You should figure out the mouse velocity by dividing the mouse movement by the time that has passed since the last loop. This will give you more physical information to base your ramping and such.

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