More DX Mouse problems...

Started by
5 comments, last by DrunkenBrit 16 years, 10 months ago
Hey! I'm messing about with DX input using the mouse...I'm moving a QUAD via the mouse position on the screen for testing purposes...the problem is the QUAD overtakes the mouse position the more I move it i.e. It seems that it is accumalting more than it should with adding the dx and dy mouse position per frame to the mouse x and y position, here is my mouse update function:


bool DxMouse::Update()
{
	assert( m_Initialised && "DxMouse not initialised!" );

	HRESULT hResult = m_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2),
												(LPVOID)&m_MouseState );

	if( FAILED( hResult ) )
	{
		hResult = m_pMouse->Acquire();

		while( hResult == DIERR_INPUTLOST )
			hResult = m_pMouse->Acquire();
		
		return false;
	}

	m_Dx = m_MouseState.lX;
	m_Dy = m_MouseState.lY;

	m_X += m_Dx + m_WindowRECT.left;
	
	if( m_YDown )
		m_Y -= m_Dy - m_WindowRECT.top;
	else
		m_Y += m_Dy + m_WindowRECT.top;

	if( m_X < 0.0f )
		m_X = 0.0f;

	if( m_Y < 0.0f )
		m_Y = 0.0f;

	return true;
}


Can anybody see something obvious that I'm doing wrong? I did try storing the dx and dy of the mouse position from the previous frame and then subtract that from the new mouse dx and dy, that ended up with flickering of the QUAD and drawing two of them :S Thanks!
Show A Man A Program, Frustrate Him For A Day...Teach A Man To Program, Frustrate Him For The Rest Of His Life...
Advertisement
The m_WindowRECT.left and m_WindowRECT.top are not needed, they just increase your deltas which result in exactly the effect you describe.

Since the mouse movement is given relative the windows position has no relation to it.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Thanks for your reply, but that didn't seem to solve the problem... :( Anything else?
Show A Man A Program, Frustrate Him For A Day...Teach A Man To Program, Frustrate Him For The Rest Of His Life...
Hi DrukenBrit,

The general concensus for handling keyboard/mouse input seems to favour standard Windows messages now, rather than DX Input.

I do use DX Input occasionally now, but generally only for joystick input.

Either way, I guess the problem may be a difference between mouse coordinates and your viewport coodinates.

I guess the problem may be of your mapping of mouse coordinates to viewport coordinates.

Sorry, I can't be more specific, but I would look for something along those lines.

Could you show your code where you map the mouse coordinates to your quads position (in the viewport)?

HTH,
Cambo_frog
For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.
Hi Cambo_frog,

Thank for your reply. My viewport is:

	glMatrixMode(GL_PROJECTION);						glLoadIdentity();								gluOrtho2D( 0.0, (double)g_ScreenWidth, 0.0, (double)g_ScreenHeight );	glMatrixMode(GL_MODELVIEW);						glViewport( 0, 0, g_ScreenWidth, g_ScreenHeight );		// Below is my main render loop:void Display(){	glClear( GL_COLOR_BUFFER_BIT );	glClearColor( 0, 0, 0, 0 );	DxMouse::Get().Update();		f32 x = DxMouse::Get().GetMouseX();	f32 y = DxMouse::Get().GetMouseY();	glPushMatrix();	glTranslatef( x, y, 0.0f );	test.Render();	glPopMatrix();	glutSwapBuffers();	}


I have also tried to use GetMousePos() and I get the same results with that...

Thanks mate!
Show A Man A Program, Frustrate Him For A Day...Teach A Man To Program, Frustrate Him For The Rest Of His Life...
Hi DrukenBrit,
That looks like OGL code rather than DX code!

Or is it a mix of both?

Sorry, but I am not familiar with OGL coordinate systems.

TIA,
Cambo_frog
For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.
Yup, It's OpenGL and DX for input.

Well the OpenGL is trivial, I'm using screen coordinates which are the same in DX afaik.

The screen is 800 * 600 dimensions. If I render a QUAD drawn at the origin to 100, 100, then the QUAD will be at 100, 100 in screen coordinates.

Thanks.
Show A Man A Program, Frustrate Him For A Day...Teach A Man To Program, Frustrate Him For The Rest Of His Life...

This topic is closed to new replies.

Advertisement