Jump to content
  • Advertisement
Sign in to follow this  
Lirben

3D mouse movement

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

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
Advertisement
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)
loop

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!