Original Post
Hello, I just started to use DirectInput with mouse.
My program work in full screen, with a backbuffer, and it write on the screen the position of the mouse.
But, the position is inaccurate, for exemple, if I move the mouse really fast, the position value will not increase as much as if I move the mouse slowly...
I followed the insctruction from the book "Programming RPG with DirectX" from Jim Adams.
I think my problem is because i'm using a BackBuffer, is it possible ?
Here is my code:
Init Mouse:
Read mouse and copy position in mouse global variable position:
Code for reading device(s)
Thanks
-------------------------
Account: Hedos - Level 1 Programmer
[edited by - Hedos on April 26, 2003 6:22:38 PM]
[edited by - Hedos on April 26, 2003 6:23:16 PM]
IDirectInputDevice8 *InitMouse(HWND hWnd, IDirectInput8 *pDI)
{
IDirectInputDevice8 *pDIDevice;
//Create the device object
if(FAILED(pDI->CreateDevice(GUID_SysMouse, &pDIDevice, NULL)))
return NULL;
//Set the data format
if(FAILED(pDIDevice->SetDataFormat(&c_dfDIMouse))){
pDIDevice->Release();
return NULL;
}
//Set the cooperative mode
if(FAILED(pDIDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE))){
pDIDevice->Release();
return NULL;
}
//Acquire the device for use
if(FAILED(pDIDevice->Acquire())){
pDIDevice->Release();
return NULL;
}
//Everything was a success, return the pointer
return pDIDevice;
}
ReadDevice(g_pDIDeviceMouse, (void*)&MouseState, sizeof(DIMOUSESTATE)); g_MouseXPos += MouseState.lX; g_MouseYPos -= MouseState.lY;
BOOL ReadDevice(IDirectInputDevice8 *pDIDevice,
void *DataBuffer, long BufferSize)
{
HRESULT hr;
while(1) {
// Poll device
pDIDevice->Poll();
// Read in state
if(SUCCEEDED(hr = pDIDevice->GetDeviceState(BufferSize,(LPVOID)DataBuffer)))
break;
// Return on an unknown error
if(hr != DIERR_INPUTLOST && hr != DIERR_NOTACQUIRED)
return FALSE;
// Reacquire and try again
if(FAILED(pDIDevice->Acquire()))
return FALSE;
}
// Return a success
return TRUE;
}