FPS-like mouse-look camera WinAPI problem

Started by
17 comments, last by bmarci 4 years, 6 months ago
2 minutes ago, b2soft said:

in such case I need to manage focus states of the window

Well, checking if your application window is active is just another function call. I think this solution is much more convenient than fighting an event-based system which doesn't have games in mind. I don't really see any advantage in writing twenty lines of code to retrieve the cursor position. Especially not in a full-screen FPS where the only thing you need is just a mouse delta.

 

1 minute ago, JoeJ said:

Sounds interesting. But i guess you still have to use SetCursorPos, and a useless message is generated?

Yes, you'd still need SetCursorPos, but useless messages can be silently ignored. In fact, you are ignoring tons of messages anyway so this doesn't matter at all. Spy++ is a handy tool for monitoring such things BTW..

Advertisement
8 minutes ago, Prototype said:

you are ignoring tons of messages anyway so this doesn't matter at all.

So OS is like Facebook, get it :D

2 minutes ago, JoeJ said:

So OS is like Facebook, get it :D

More like Twitter, but you can't block anybody and you are obliged to retweet :)

3 minutes ago, Prototype said:

More like Twitter, but you can't block anybody and you are obliged to retweet :)

actually, you can... :D own custom eventz for all!

just kidding.

 

Seems that checking for center-positioned mouse is OK for me

 

Thanks, mates

Have you considered using raw input instead of win32 and using a virtual cursor instead? My engine works with both events and raw input and an input manager deals with things including providing an offset vector of how the cursor moved since the last frame.  So you could calculate your yaw and pitch from that and keep a little dot in the HUD in the center and hide the actual cursor?

Just now, Jman2 said:

Have you considered using raw input instead of win32 and using a virtual cursor instead? My engine works with both events and raw input and an input manager deals with things including providing an offset vector of how the cursor moved since the last frame.  So you could calculate your yaw and pitch from that and keep a little dot in the HUD in the center and hide the actual cursor?

Yep, it's an option (DirectInput, XInput, something else), but I want to keep things simple for my sample, at least, for now,

Here is a good resource on RawInput for when you get to that point:

http://keithditch.powweb.com/Games/html/raw_input.html

As mentioned earlier the Get/SetCursorPos can easily do the trick. Also don't forget to handle the WM_ACTIVATEAPP so when you hit alt-tab, or a system popup appears you can release the mouse. I don't remember if I had to deal with cursor visibility on focus change, though :( 

Also the SetCursorPos resets some internal counters, so call it only when you have some delta, otherwise it'll truncate the very small movements and your camera will be... hmm... what to say... :) 

This topic is closed to new replies.

Advertisement