Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In my current FPS game, I have the mouse setup in a way, that it always forces the position of the mouse to be centered at the screen. This gets the job done, but also gets very annoying, since the mouse is "fixed" at the center of the screen.

Here is what I am doing:

  • get mouse current position
  • find offset from center of the screen
  • set mouse current position to center of the screen
  • apply difference to m_pTransformation (transformation matrix of the player)


Is there a better way to deal with this ?

share|improve this question
1  
Can you expand on why it's "annoying"? That's a pretty standard solution. –  wkerslake Feb 5 '11 at 1:28
    
For one: I've always been doing first-person view like this. I wanted to learn if there is a better way out there. Also, When I alt-tab out of the game, it still tries to center the mouse. I'll somehow need to flag it when the game goes out of scope. –  brainydexter Feb 5 '11 at 2:50
    
Also see gamedev.stackexchange.com/questions/7812/… –  Ricket Feb 8 '11 at 16:32
add comment

2 Answers 2

up vote 2 down vote accepted

That's a pretty standard solution. Try hiding the mouse cursor and superimposing a fixed targeting reticule (if your game needs one) if it's a distraction

share|improve this answer
1  
I already have a cross-hair in place hiding the mouse. –  brainydexter Feb 4 '11 at 23:50
add comment

Also make sure to unlock the mouse if the user alt-tabs out of the game and your game somehow still controls the cursor. Don't forget to test for that!

Otherwise I agree that yours is the standard solution. The alternative is to capture raw mouse input; MSDN documentation is here. This Stack Overflow question might help you starting to implement it in Mac and Linux.

I can't help but recommend against raw input though. I think you would need to test for anomalies and somehow handle all the different types of mice (different DPI, USB vs PS/2, etc.) and have a robust in-game system for sensitivity since raw input bypasses the operating system's mouse settings (acceleration, sensitivity, etc.).

It seems to me your method is just fine. It's simple (at least, much more simple than raw input) and you haven't indicated that it is broken in any way, so why are you trying to fix it? This almost seems a case of premature optimization. :)

share|improve this answer
1  
I just have been doing things like this for a long time and always wondered if there's a different/better way to deal with this. I gather from all the answers/comments, what I'm doing is good. Thanks for the reply. –  brainydexter Feb 8 '11 at 20:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.