Jump to content
  • Advertisement

Archived

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

Odd the Hermit

DirectInput Mouse Values

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

I''m trying to add DirectInput to my current project, and I don''t understand the values I''m getting. Here''s my initialization:
  
// Create Direct Input

if( DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION,
		IID_IDirectInput8, (void**)&m_DInput, NULL) != DI_OK ) {
	sprintf(err, "%s%s",
		"There was an error initializing Direct Input.  ",
		"Please make sure you have DirectX 8 or later installed.");
	MessageBox( m_Parent->GetHWND(), err, "Error Initializing DirectInput!", MB_OK|MB_ICONERROR);
	return false;
}

// Create the mouse device.

if( !CreateMouse() ) {
	sprintf(err, "%s%s",
		"There was an error initializing Direct Input.  ",
		"Unable to initialize the keyboard.");
	MessageBox( m_Parent->GetHWND(), err, "Error Initializing DirectInput!", MB_OK|MB_ICONERROR);
	return false;
}
  
Here''s CreateMouse():
  
char err[256] = "";
// Create the Direct Input mouse device.

if(FAILED(m_DInput->CreateDevice(GUID_SysMouse, &m_Mouse, NULL))) {
	sprintf(err, "%s",
		"There was an error creating the mouse device.");
	MessageBox(m_Parent->GetHWND(),err,"DirectInput Error!",MB_OK|MB_ICONERROR);
	return false;
}
// Set the data format for the mouse.

if(FAILED(m_Mouse->SetDataFormat(&c_dfDIMouse2))) {
	sprintf(err, "%s",
		"Unable to set the mouse data format.");
	MessageBox(m_Parent->GetHWND(),err,"DirectInput Error!",MB_OK|MB_ICONERROR);
	return false;
}
// Set the cooperative level.

if(FAILED(m_Mouse->SetCooperativeLevel(m_Parent->GetHWND(),DISCL_FOREGROUND|DISCL_EXCLUSIVE))) {
	sprintf(err, "%s",
		"Unable to set the mouse cooperative level.");
	MessageBox(m_Parent->GetHWND(),err,"DirectInput Error!",MB_OK|MB_ICONERROR);
	return false;
}
// Acquire the device.

m_Mouse->Acquire();

// We made it!  Yay!

return true;
  
And here''s my poll function:
  
// Read the mouse.

ZeroMemory( &m_MouseData, sizeof(m_MouseData) );
if(FAILED(m_Mouse->GetDeviceState(sizeof(m_MouseData),&m_MouseData))) {
	// Something went wrong; reacquire the mouse.

	m_Mouse->Acquire();
	m_Mouse->GetDeviceState(sizeof(m_MouseData),&m_MouseData);
}
char err[256] = "";
sprintf(err,"In DInputLayer: DX Mouse Data: (%g, %g)\n",
	m_MouseData.lX,m_MouseData.lY);
OutputDebugString(err);
}
  
Just for completeness, here''re the important declarations:
  
LPDIRECTINPUTDEVICE8 m_Mouse;
DIMOUSESTATE2 m_MouseData;
  
My problem is that, when I fire this up, the values I get from that last OutputDebugString are miniscule (2.77577e-306, for example), no matter how hard I throw the mouse around. Which seems, well, wrong. What am I missing? -Odd the Hermit

Share this post


Link to post
Share on other sites
Advertisement
ok well...directX automatically keeps the mouse centered...so if u move it to the side, the position value will change and will immediately be snapped back to the center...which would explain the miniscule value...

ur code looks fine and all just OutputDebugString may not be the best way of doing it...a better way to test it is to hook it up to text being rendered to the screen...that way u can see when it moves, or get a cursor in there and test it out

Share this post


Link to post
Share on other sites
I know the mouse returns relative values; the problem is that the values I''m getting are so close to zero that they''re unreadable. I''d noticed the problem when I''d tried hooking it up to a cursor, but because the values are so small, there''s no perceptable movement. I used the OutputDebugString call to track down where the problem seems to be--I''m getting bad data straight from DirectX. And I have no idea why. Seems like there''s got to be something I''m missing...

-Odd the Hermit

Share this post


Link to post
Share on other sites
I used buffered input with GetDeviceData and I got nice int values ranging between 1 and 30 or something. Buffered and Immediate Input are obviously very different for the mouse, since you receive relative values when using Buffered input, and absolute values when you use Immmediate input.

Share this post


Link to post
Share on other sites
sprintf(err,"In DInputLayer: DX Mouse Data: (%g, %g)\n", m_MouseData.lX,m_MouseData.lY);

try specifying a typecast to those variables...your polling function seems correct, so maybe sprintf is treating those long''s as float''s without converting them...that seems unlikely, but try

sprintf(err,"In DInputLayer: DX Mouse Data: (%g, %g)\n", (float)m_MouseData.lX,(float)m_MouseData.lY);

dunno if it''ll help or not



----------------------

“I have no country to fight for, my
country is the earth, and I am a citizen
of the world... I am not a capitalist soldier,
I am a proletarian revolutionist. I
do not belong to the army of the plutocracy
but to the irregular army of the
people. I refuse to obey any command
to fight from the ruling class, but I will
not wait to be commanded to fight for
the working class. I am opposed to every
war but one. I am for that war heart
and soul, and that is the world-wide war
of the social revolution. In that war I am
prepared to fight in any way the ruling
class may make it necessary even to
the barricades.”
Eugene V. Debs

----------------------

Share this post


Link to post
Share on other sites
the reason for that being that sprintf is expecting a float, and will read the argument as a float....the virtual arguments will not cast themselves, so it will read the bytes of the long as if they were the bytes of a float, and the two are stored in totally different ways in memory, so you will not get the correct value

chris




----------------------

“I have no country to fight for, my
country is the earth, and I am a citizen
of the world... I am not a capitalist soldier,
I am a proletarian revolutionist. I
do not belong to the army of the plutocracy
but to the irregular army of the
people. I refuse to obey any command
to fight from the ruling class, but I will
not wait to be commanded to fight for
the working class. I am opposed to every
war but one. I am for that war heart
and soul, and that is the world-wide war
of the social revolution. In that war I am
prepared to fight in any way the ruling
class may make it necessary even to
the barricades.”
Eugene V. Debs

----------------------

Share this post


Link to post
Share on other sites
btw, that won''t help the fact that you''re getting small values, but it will at least tell you the correct values that you are getting

chris



----------------------

“I have no country to fight for, my
country is the earth, and I am a citizen
of the world... I am not a capitalist soldier,
I am a proletarian revolutionist. I
do not belong to the army of the plutocracy
but to the irregular army of the
people. I refuse to obey any command
to fight from the ruling class, but I will
not wait to be commanded to fight for
the working class. I am opposed to every
war but one. I am for that war heart
and soul, and that is the world-wide war
of the social revolution. In that war I am
prepared to fight in any way the ruling
class may make it necessary even to
the barricades.”
Eugene V. Debs

----------------------

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!