Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Badone

Absolute Position of Mouse w/ DirectInput 8

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

Hi, I'm using D3DXSprite and I've got the mosue working and running. I'm using C++, but on a VB site I saw some code on how to process the position of the mouse. Here is the small code that I have for this.
x=x+mouseState.lX*MOUSE_SPEED;
y=y+mouseState.lY*MOUSE_SPEED;

if(x<0)
{
	x=0;
}
if(x>800)
{
	x=800;
}
if(y<0)
{
	y=0;
}
if(y>600)
{
	y=600;
}
  
I am writing to a file the position of the mouse when I click a button. I ran the program 3 different times, putting the data into 3 different files, everytime the x and y positions were off. Here was the data that I received.
quote:
File 1: Button 1 was pressed where x=266 and y=140 File 2: Button 1 was pressed where x=222 and y=168 File 3: Button 1 was pressed where x=240 and y=182
These are so far off but I know I click the exact spot or maybe one pixel off. What is the bug in my code that is doing this? I can't have this, I need it to be the same everytime, otherwise buttons and such won't work. Any help would be greatly appreciated. Thanks! Edited by - Badone on December 29, 2001 9:34:07 PM

Share this post


Link to post
Share on other sites
Advertisement
I was thinking about it and I say that the MOUSE_SPEED=2. But how do I keep that constant? You can move the mouse fast or slow, so how do you know what the mouse speed really is? Can my values ever always be the same?

Share this post


Link to post
Share on other sites
Off to what? I mean you use these coordinates to draw your cursor, too, don''t you?
You can''t compare your coordinates to thos of the Windows system cursor, if that is what you''re doing.
Sorry, but I don''t fully understand what you are doing.

Share this post


Link to post
Share on other sites
Well I don''t really know myself. I''m using the code from Nexe''s site for mouse input. When I first got it I had about 30 errors and had to go through and debug it. It works now and all I know is I have declared mouseState as a DIMOUSESTATE2 and when I run the function InterogateTheMouse, it puts mouseState into GetDeviceState. I''m not really sure where I draw the mouse at. There are two functions that came with the class, DIMouse (Init everything), and InterogateTheMouse (get the input). Before all it did was check for buttons down but I put in the code to take mouseState.lX and mouseState.lY and try to turn them into my mouse coordinates. I also added a function to Release everything since that wasn''t in there. What is the function to draw the mouse? Any help would be greatly appreciated because I have not really worked with DirectInput at all and have just been playing around with D3DXSprite for a while. Thanks!

Share this post


Link to post
Share on other sites
Ok, I see what he was doing, the cooperative level was set for DISCL_NONEXCLUSIVE, so the cursor was already being drawn I guess by windows. Does anyone have an example on how to draw the mouse? Thanks.

Share this post


Link to post
Share on other sites
nm, I''m an idiot, lol. Ok, thanks for all the help Volker, I just have a few bugs to work out and it should be fine.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!