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 ...

  1. #1
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856

    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]
    Last edited by LuckY; 08-04-2004 at 01:48 PM.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    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.

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    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.

    Thanks again.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    1,198
    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.

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    maybe im missing something here but, if you know the initial mouse position, why dont you just accumulate the relative positions to get the absolute one?

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    1,198
    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.

  7. #7
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    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.

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    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.

  9. #9
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Quote Originally Posted by Bubba
    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.

    Quote 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.

  10. #10
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    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.

  11. #11
    Registered User
    Join Date
    Aug 2003
    Posts
    1,198
    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?

  12. #12
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    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?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help on Calculator program in C
    By deathscyth129 in forum C Programming
    Replies: 8
    Last Post: 01-08-2005, 06:50 PM
  2. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  3. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  4. Action Based On User Input
    By Stealth in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2001, 05:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21