Skip to main content
gamedev.net
🔒 Locked

DI mouse problem

Started by Kris2456 2 replies 750+ views
Original Post
Kris2456
Kris2456
Hi. In my engine i have decided to use direct input for all the user input. I have finished the keyboard and it works fine. But with the mouse i am having more problems. It seems that the point on my screen which should move with the mouse does indeed move with it, but at extremly high speeds. It also seems to move in strides of about 50 pixels. And i cant seem to slow it down nor make the gap smaller. I dont really know what to do, if anyone has had this prob before please say. Thanks!
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
neneboricua19
neneboricua19
The values returned for mouse movement by DirectInput don't necessarily correspond to the number of pixels that the mouse moved on the screen. Mouse movement will be returned as a relative change in position of the mouse; the actual movement values are determined by the device driver and aren't necessarily the same as the number of pixels on the screen.

To slow down your cursor, you can divide this change in position reported by DirectInput by some amount. This is typically what games do. In the options for most games where you can adjust the sensitivity of the mouse, the slider that they present you simply adjusts the value that is used to divide the delta values returned by DirectInput.

neneboricua
Kris2456
Kris2456
I tried that, but with no avail, it just made it move slower, but not without the uber spaces between each movement.

here is my code:
//CMouse.hclass CMouse{      public:      LPDIRECTINPUTDEVICE8   m_mouse;      DIMOUSESTATE mouse_state;            bool Init(HWND hwnd, LPDIRECTINPUT8 dxi);      void Update(int res[]);      void SetSensitivity(int sense) { Sensitivity = sense;}            float X, Y, ScrollWheel;      int Sensitivity;      BYTE Buttons[4];      };//CMouse.cppvoid CMouse::Update(int res[]){     m_mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouse_state);          X += mouse_state.lX/Sensitivity;     Y -= mouse_state.lY/Sensitivity;     ScrollWheel = mouse_state.lZ;          Buttons[0] = mouse_state.rgbButtons[0];     Buttons[1] = mouse_state.rgbButtons[1];     Buttons[2] = mouse_state.rgbButtons[2];     Buttons[3] = mouse_state.rgbButtons[3];     }


I hope this helps...
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
dave
dave
I have posted here my class i just wrote for this...

#ifndef _WIN_INPUT_H_#define _WIN_INPUT_H_#include "win_def.h"struct CURRENT_INPUT{	DIMOUSESTATE	mouseState;	_UINT			buttons;	POINT			cursorPosScreen;	POINT			cursorPosClient;	char			keys[256];};class win_input{public:	win_input(	MDEVICE		device,				HWND		window,				HINSTANCE	instance);	~win_input();	void			Frame();	MINPUT&			DI_Ref()		{	return m_DI;				};	MINPUTDEVICE&	DIKeyboard()	{	return m_DIKeyboard;		};	MINPUTDEVICE&	DIMouse()		{	return m_DIMouse;			};	CURRENT_INPUT&	GetInput()		{	return m_currInput;			};private:	MINPUT			m_DI;	MINPUTDEVICE	m_DIKeyboard;	MINPUTDEVICE	m_DIMouse;	CURRENT_INPUT			m_currInput;	MDEVICE					m_device;	HWND					m_window;	HINSTANCE				m_instance;	void CreateDI();	void CreateDIMouse();	void CreateDIKeyboard();	void UpdateMouse();	void UpdateKeyboard();};#endif

#include "win_input.h"win_input::win_input(	MDEVICE		device,						HWND		window,						HINSTANCE	instance){	m_device	= device;	m_window	= window;	m_instance	= instance;	CreateDI();	CreateDIKeyboard();	CreateDIMouse();}win_input::~win_input(){}void win_input::CreateDI(){		if ( FAILED(	DirectInput8Create(	m_instance, 										DIRECTINPUT_VERSION,										IID_IDirectInput8, 										(void**)m_DI.pp(), 										NULL)))	{		assert(0);	}	}void win_input::CreateDIKeyboard(){	m_DI->CreateDevice(GUID_SysKeyboard, m_DIKeyboard.pp(), NULL);	m_DIKeyboard->SetDataFormat(&c_dfDIKeyboard);	m_DIKeyboard->SetCooperativeLevel(	m_window, 										DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);}void win_input::CreateDIMouse(){	m_DI->CreateDevice(GUID_SysMouse, m_DIMouse.pp(), NULL);	m_DIMouse->SetDataFormat(&c_dfDIMouse);	m_DIMouse->SetCooperativeLevel(	m_window,									DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);}void win_input::Frame(){	UpdateKeyboard();	UpdateMouse();}void win_input::UpdateKeyboard(){	if ( FAILED(m_DIKeyboard->Acquire()) )	{		m_DIKeyboard->Acquire();	}	m_DIKeyboard->GetDeviceState(sizeof(m_currInput.keys),(LPVOID)&m_currInput.keys);}void win_input::UpdateMouse(){	if ( FAILED(m_DIMouse->Acquire()) )	{		m_DIMouse->Acquire();	}	m_DIMouse->GetDeviceState(sizeof(m_currInput.mouseState),(LPVOID)&m_currInput.mouseState);	GetCursorPos( &m_currInput.cursorPosClient );	m_currInput.cursorPosScreen = m_currInput.cursorPosClient;    ScreenToClient( m_window, &m_currInput.cursorPosClient );}


I have found that you can achieve better movement from the mouse if u get the cursor position and then convert that position from screen space to window space using the function ScreenToClient().

See the above code for that.

ace

Topic Locked

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

Sign in to reply to this topic.