Skip to main content
gamedev.net
🔒 Locked

DirectInput - Mouse problem

Started by Hedos Apr 26, 2003 at 5:21 PM 0 replies 450+ views
Original Post
Hedos
Hedos
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:
  
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;

}
  
Read mouse and copy position in mouse global variable position:
  
ReadDevice(g_pDIDeviceMouse, (void*)&MouseState, sizeof(DIMOUSESTATE));
g_MouseXPos += MouseState.lX;
g_MouseYPos -= MouseState.lY;
  
Code for reading device(s)
  
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;
}
  
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]
Colin Jeanne
Colin Jeanne
What are you comparing the mouse movement to? The system cursor? The system cursor does not follow a simple mousex += dx, mousey += dy formula for calculating position. It includes other factors such as acceleration. That could be why your cursor doesn''t move with the system cursor.



Qui fut tout, et qui ne fut rien
Invader''s Realm

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.