DirectInput8 Action Mapping Using Mouse Input

This is a discussion on DirectInput8 Action Mapping Using Mouse Input within the Game Programming forums, part of the General Programming Boards category; Alright, bear with me. I am for the first time (surprisingly) venturing out into DirectX programming. I've created a 2D ...

DirectInput8 Action Mapping Using Mouse Input

Alright, bear with me. I am for the first time (surprisingly) venturing out into DirectX programming. I've created a 2D game engine that uses the, new since DirectInput8, action maps to generically define controls for any devices attached to the system. My problem is that I am attempting to paint a cursor on the game screen at the point where the mouse cursor lies. I need mouse input, so I have mapped DIMOUSE_BUTTON0, but doing that automatically forces the acquiring of the mouse and thus calls to GetCursorPos() are screwed. In trying to fix the problem, I mapped DIMOUSE_XAXIS and DIMOUSE_YAXIS. When polled the dwData they send is something I could use some help understanding because it is always a short distance (under 5) and sometimes negative.

Might you know of any other way to determine the cursor position while it is acquired by DirectInput?

Help.

[edit]
I guess I could just create a mouse input device to deal with that specific guy independently... But still, if you have any other solutions, please let me know.
[/edit]

That's because you are receiving the data in relative mode. That is all coordinates are relative to the last mouse coordinates. So -5, -5 means that the mouse has been moved up and left by 5 pixels since the last time you polled it. There is a way to get the mouse to read in absolute coordinates and it is explained (albeit quite confusingly) in the DirectX SDK.

To put the mouse in absolute mode you must first unacquire it. Shakti and I tried to put the mouse into absolute mode with little success. We are not sure at this time exactly why it is not working.

Also since you are using DirectInput do not call the API to get the position of the mouse. The two should not be mixed. Either use all API or all DirectX, but don't combine them.

Thank you for the reply. I went through the lengthy process of adding a device specifically for mouse input and while making it work figured out that the values passed are relative coords, so I can now go back and remove everything I just added because the same values are received using the action map.

What I'm doing is just calling GetCursorPos() during initialization then adding the passed DIMOUSE_XAXIS/DIMOUSE_YAXIS to the coords. This seems to work well.

One problem though is that you will still recieve new coords for the mouse even if your cursor is at one end of the screen, so you can very soon and very fast get bad coordinates, if you dont account for that ofcourse.

Yes that is one way to do it but you have to remember that if you take the cursor all the way to, say, right of the screen and then still drag the mouse right you will have bad coordinates. You just have to account for that correctly.

I'd like to put my two cents in about DirectX action mapping....It's not worth it. The only thing that it offers to me is the fact that they will make it nice to change keys based on what the user chooses, everything else I can do easier and cleaner on my lonesome. I don't even like that aspect, because as far as I know, you can't change the appearence of the screen the user uses to change his mapping.

You can accumulate coordinates but its not as easy as it sounds and Shakti has tried it so far with very little success.

I know that we are not far from figuring out how to get the mouse into absolute mode but geez couldn't MS have made it easier??

After all the mouse driver by default reports coords in absolute, not relative. I think it is much easier to gain relative coords from absolute than absolute from relative. But if you miss one poll on relative then your coords are all way off. That's the problem...it cause very jerky mouse movements. You really need a handler that 'knows' when the mouse has moved so you never miss a movement.

And yeah action mapping looked stupid when I read about it in the SDK. Just not worth my time.

But if you miss one poll on relative then your coords are all way off. That's the problem...it cause very jerky mouse movements. You really need a handler that 'knows' when the mouse has moved so you never miss a movement.

There shouldn't be a case where you miss the relative mouse data, should there? I mean given the fact that the data is buffered and sent along in the order it occurred there should never be any problems. I have been doing a lot of testing with what I have so far and I haven't had any jerky motions or anything else indicating "skipped" data. Did you try doing the same without buffering the input? I can see how that can lead to a real headache.

Originally Posted by skorman00

I don't even like that aspect, because as far as I know, you can't change the appearence of the screen the user uses to change his mapping.

Quite true. The only thing you can change is the colors of the screen (using the DICOLORSET structure).

I'm surprised that so many people seem to dislike action mapping. It seems like a rather splendid idea to me, but my opinion may quite possibly be skewed given my lack of extended experience with DirectX programming. And, of course, if you must use a config screen of your own, you don't have to use the one provided by DirectInput. I like the fact that it will display an image of the user's joystick (if provided by the manufacturer) to make the config even more comprehensible.

I love action mapping, just not DirectX action mapping. They have it set up in such a way that it's much more complicated than necessary. All you need is an array of the DIK codes. For joystick support, you could use the same, and just store the device which they are using. However, it does get a bit more tricky depending on how you use joysticks and analog input (say for instance you wanted to map punching to a joystick movement like some boxing games). If you needed that functionality, then their action mapping may be beneficial, but I would still prefer to set it up myself...call me old fashioned.

Another thing I have discovered is that the units the DirectInput uses when processing mouse is not pixels. I think I know what it is but it is kind of hard to explain but I will give it a go.

Lets say your desktop is of the size 1024x768 and the window with your game in has the size 800x600. Now lets say you want to run the game as windowed and you have set up so you use DirectInput for mouse movement and you translate the relative coordinates to absolute. Now when you put the cursor all the way to the right of the screen (even if you dont have the actual game window there) your absolute coordinates will show you 799 so it seems like DirectX assumes you are running at full screen! Now isnt that just lovely?

Yeah, basically in windowed mode you can move the cursor anywhere within the confines of the actual window. It is up to the programmer to determine if it is actually within his game screen. That is sort of as expected isn't it? Or do you mean that you think it should stop the mouse cursor at the edge of your game screen instead of letting it go everywhere?