Original Post
I''m trying to add DirectInput to my current project, and I don''t understand the values I''m getting. Here''s my initialization:
Here''s CreateMouse():
And here''s my poll function:
Just for completeness, here''re the important declarations:
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
// 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;
}
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;
// 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);
}
LPDIRECTINPUTDEVICE8 m_Mouse; DIMOUSESTATE2 m_MouseData;